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

Addressing multiple dashboard issues: deps loading once, field conversion, etc. #27669

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
minor fixes
kvch committed Aug 31, 2021
commit bc5503f25675f36d14be0a7179a4562d0f2a22f6
2 changes: 1 addition & 1 deletion libbeat/dashboards/kibana_loader.go
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ func (loader KibanaLoader) ImportDashboard(file string) error {
}

content = ReplaceIndexInDashboardObject(loader.config.Index, content)
content = ConvertToStr(content)
content = EncodeJSONObjects(content)
content = ReplaceStringInDashboard("CHANGEME_HOSTNAME", loader.hostname, content)

err = loader.importReferences(file, content)
8 changes: 3 additions & 5 deletions libbeat/dashboards/modify_json.go
Original file line number Diff line number Diff line change
@@ -192,13 +192,11 @@ func ReplaceIndexInDashboardObject(index string, content []byte) []byte {
}

if kibanaSavedObject, ok := attributes["kibanaSavedObjectMeta"].(map[string]interface{}); ok {
ba := ReplaceIndexInSavedObject(logger, index, kibanaSavedObject)
attributes["kibanaSavedObjectMeta"] = ba
attributes["kibanaSavedObjectMeta"] = ReplaceIndexInSavedObject(logger, index, kibanaSavedObject)
}

if visState, ok := attributes["visState"].(string); ok {
nya := ReplaceIndexInVisState(logger, index, visState)
attributes["visState"] = nya
attributes["visState"] = ReplaceIndexInVisState(logger, index, visState)
}

b, err := json.Marshal(objectMap)
@@ -210,7 +208,7 @@ func ReplaceIndexInDashboardObject(index string, content []byte) []byte {
return b
}

func ConvertToStr(content []byte) []byte {
func EncodeJSONObjects(content []byte) []byte {
logger := logp.NewLogger("dashboards")

if len(bytes.TrimSpace(content)) == 0 {
12 changes: 4 additions & 8 deletions libbeat/dashboards/modify_json_test.go
Original file line number Diff line number Diff line change
@@ -72,18 +72,14 @@ func TestReplaceIndexInDashboardObject(t *testing.T) {
expected []byte
}{
{
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"metricbeat-*\"}"}}}
`),
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"metricbeat-*\"}"}}}`),
"otherindex-*",
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"otherindex-*\"}"}}}
`),
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"otherindex-*\"}"}}}`),
},
{
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"metricbeat-*\"}}"}}}
`),
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"metricbeat-*\"}}"}}}`),
"otherindex-*",
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"otherindex-*\"}}"}}}
`),
[]byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"otherindex-*\"}}"}}}`),
},
}