Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically Enable/disable depenencies tab #311

Merged
merged 7 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions pkg/strategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func normalize(jaeger *v1.Jaeger) {
jaeger.Spec.Ingress.Security = v1.IngressSecurityNoneExplicit
}

// note that the order normalization matters - UI norm expects all normalized properties
normalizeSparkDependencies(&jaeger.Spec.Storage.SparkDependencies, jaeger.Spec.Storage.Type)
normalizeIndexCleaner(&jaeger.Spec.Storage.EsIndexCleaner, jaeger.Spec.Storage.Type)
normalizeElasticsearch(&jaeger.Spec.Storage.Elasticsearch)
Expand Down Expand Up @@ -135,23 +136,48 @@ func normalizeRollover(spec *v1.JaegerEsRolloverSpec) {
}

func normalizeUI(spec *v1.JaegerSpec) {
sOpts := spec.Storage.Options.Map()
uiOpts := map[string]interface{}{}
if !spec.UI.Options.IsEmpty() {
if m, err := spec.UI.Options.GetMap(); err == nil {
uiOpts = m
}
}
// we respect explicit UI config
if _, ok := uiOpts["archiveEnabled"]; ok {
enableArchiveButton(uiOpts, spec.Storage.Options.Map())
disableDependenciesTab(uiOpts, spec.Storage.Type, spec.Storage.SparkDependencies.Enabled)
if len(uiOpts) > 0 {
spec.UI.Options = v1.NewFreeForm(uiOpts)
}
}

func enableArchiveButton(uiOpts map[string]interface{}, sOpts map[string]string) {
// respect explicit settings
if _, ok := uiOpts["archiveEnabled"]; !ok {
// archive tab is by default disabled
if strings.EqualFold(sOpts["es-archive.enabled"], "true") ||
strings.EqualFold(sOpts["cassandra-archive.enabled"], "true") {
uiOpts["archiveEnabled"] = true
}
}
}

func disableDependenciesTab(uiOpts map[string]interface{}, storage string, depsEnabled *bool) {
// dependency tab is by default enabled and memory storage support it
if strings.EqualFold(storage, "memory") || (depsEnabled != nil && *depsEnabled == true) {
Copy link
Contributor

@objectiser objectiser Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs to be ... || depsEnabled == nil || *depsEnabled == true - as if the depsEnabled is nil, then it means dependencies are enabled by default, doesn't it? So UI config shouldn't be changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization of deps spec runs before - so we assuming correct settings here

return
}
if strings.EqualFold(sOpts["es-archive.enabled"], "true") ||
strings.EqualFold(sOpts["cassandra-archive.enabled"], "true") {
uiOpts["archiveEnabled"] = true
deps := map[string]interface{}{}
if val, ok := uiOpts["dependencies"]; ok {
if val, ok := val.(map[string]interface{}); ok {
deps = val
} else {
// we return as the type does not match
return
}
}
if len(uiOpts) > 0 {
spec.UI.Options = v1.NewFreeForm(uiOpts)
// respect explicit settings
if _, ok := deps["menuEnabled"]; !ok {
deps["menuEnabled"] = false
uiOpts["dependencies"] = deps
}
}

Expand Down
103 changes: 86 additions & 17 deletions pkg/strategy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,38 +246,107 @@ func TestNormalizeUI(t *testing.T) {
}{
{
j: &v1.JaegerSpec{},
expected: &v1.JaegerSpec{},
expected: &v1.JaegerSpec{UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"dependencies": map[string]interface{}{"menuEnabled": false}})}},
},
{
j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es.archive.enabled": "false"})}},
expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es.archive.enabled": "false"})}},
j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Type: "memory"}},
expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Type: "memory"}},
},
{
j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})}},
expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": true})}},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": true, "dependencies": map[string]interface{}{"menuEnabled": false}})}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this wrong - if the storage type is not defined, it should default to memory, which should show the dependencies tab. The expected results is showing it disabled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general yes, but this tests only normalizeUI which works on any storage

},
}
for _, test := range tests {
normalizeUI(test.j)
assert.Equal(t, test.expected, test.j)
}
}

func TestNormalizeUIArchiveButton(t *testing.T) {
tests := []struct {
uiOpts map[string]interface{}
sOpts map[string]string
expected map[string]interface{}
}{
{},
{
j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"cassandra-archive.enabled": "true"})}},
expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"cassandra-archive.enabled": "true"})},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": true})}},
uiOpts: map[string]interface{}{},
sOpts: map[string]string{"es-archive.enabled": "false"},
expected: map[string]interface{}{},
},
{
j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"other": "foo"})}},
expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"other": "foo", "archiveEnabled": true})}},
uiOpts: map[string]interface{}{},
sOpts: map[string]string{"es-archive.enabled": "true"},
expected: map[string]interface{}{"archiveEnabled": true},
},
{
j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": "respectThis"})}},
expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})},
UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": "respectThis"})}},
uiOpts: map[string]interface{}{},
sOpts: map[string]string{"cassandra-archive.enabled": "true"},
expected: map[string]interface{}{"archiveEnabled": true},
},
{
uiOpts: map[string]interface{}{"archiveEnabled": "respectThis"},
sOpts: map[string]string{"es-archive.enabled": "true"},
expected: map[string]interface{}{"archiveEnabled": "respectThis"},
},
}
for _, test := range tests {
normalizeUI(test.j)
assert.Equal(t, test.expected, test.j)
enableArchiveButton(test.uiOpts, test.sOpts)
assert.Equal(t, test.expected, test.uiOpts)
}
}

func TestNormalizeUIDependenciesTab(t *testing.T) {
falseVar := false
tests := []struct {
uiOpts map[string]interface{}
storage string
enabled *bool
expected map[string]interface{}
}{
{
uiOpts: map[string]interface{}{},
storage: "memory",
expected: map[string]interface{}{},
},
{
uiOpts: map[string]interface{}{},
storage: "memory",
enabled: &falseVar,
expected: map[string]interface{}{},
},
{
uiOpts: map[string]interface{}{},
storage: "whateverStorage",
expected: map[string]interface{}{"dependencies": map[string]interface{}{"menuEnabled": false}},
},
{
uiOpts: map[string]interface{}{},
storage: "whateverStorage",
enabled: &falseVar,
expected: map[string]interface{}{"dependencies": map[string]interface{}{"menuEnabled": false}},
},
{
uiOpts: map[string]interface{}{"dependencies": "respectThis"},
storage: "whateverStorage",
expected: map[string]interface{}{"dependencies": "respectThis"},
},
{
uiOpts: map[string]interface{}{"dependencies": map[string]interface{}{"menuEnabled": "respectThis"}},
storage: "whateverStorage",
expected: map[string]interface{}{"dependencies": map[string]interface{}{"menuEnabled": "respectThis"}},
},
{
uiOpts: map[string]interface{}{"dependencies": map[string]interface{}{"foo": "bar"}},
storage: "whateverStorage",
expected: map[string]interface{}{"dependencies": map[string]interface{}{"foo": "bar", "menuEnabled": false}},
},
pavolloffay marked this conversation as resolved.
Show resolved Hide resolved
}
for _, test := range tests {
disableDependenciesTab(test.uiOpts, test.storage, test.enabled)
assert.Equal(t, test.expected, test.uiOpts)
}
}

Expand Down