Skip to content

Commit

Permalink
Merge branch 'master' into java-attacher-config
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartnelson3 authored Jun 24, 2021
2 parents 788a332 + 9cf78f5 commit c7a85c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions kibana/send_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import (
"github.com/elastic/go-ucfg"
)

// TODO: Get this value from Oliver
// https://github.com/elastic/kibana/issues/100657
const kibanaConfigUploadPath = "/apm/fleet/apm_server_settings"
const kibanaConfigUploadPath = "/api/apm/fleet/apm_server_schema"

// SendConfig marshals and uploads the provided config to kibana using the
// provided ConnectingClient. It retries until its context has been canceled or
Expand All @@ -45,7 +43,8 @@ func SendConfig(ctx context.Context, client Client, conf *ucfg.Config) error {
if err != nil {
return err
}
b, err := json.Marshal(flat)

b, err := json.Marshal(format(flat))
if err != nil {
return err
}
Expand Down Expand Up @@ -75,6 +74,10 @@ func SendConfig(ctx context.Context, client Client, conf *ucfg.Config) error {
}
}

func format(m map[string]interface{}) map[string]interface{} {
return map[string]interface{}{"schemaJson": m}
}

func flattenAndClean(conf *ucfg.Config) (map[string]interface{}, error) {
m := common.MapStr{}
if err := conf.Unpack(m); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion kibana/send_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/elastic/go-ucfg"
)

func TestFlatten(t *testing.T) {
func TestFlattenAndFormat(t *testing.T) {
tlsFieldsCount := 0
cc, err := common.NewConfigWithYAML([]byte(serverYAML), "apm-server.yml")
c := ucfg.Config(*cc)
Expand All @@ -38,6 +38,10 @@ func TestFlatten(t *testing.T) {
flat, err := flattenAndClean(&c)
assert.NoError(t, err)

flat = format(flat)
assert.Contains(t, flat, "schemaJson")

flat = flat["schemaJson"].(map[string]interface{})
for k := range flat {
assert.NotContains(t, k, "elasticsearch")
assert.NotContains(t, k, "kibana")
Expand Down

0 comments on commit c7a85c1

Please sign in to comment.