Skip to content

Commit

Permalink
beater: separate recording static/dynamic config (#4609)
Browse files Browse the repository at this point in the history
* beater: separate recording static/dynamic config

Record the static/root config separately from
apm-server config, the latter of which may be
dynamic in the future (i.e. due to Fleet policy
updates).
  • Loading branch information
axw authored Jan 13, 2021
1 parent fb90d3a commit ad5d272
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ func (bt *beater) Run(b *beat.Beat) error {
}

// send configs to telemetry
if err := recordConfigs(b.Info, bt.config, bt.rawConfig); err != nil {
if err := recordRootConfig(b.Info, bt.rawConfig); err != nil {
bt.logger.Errorf("Error recording telemetry data", err)
}
recordAPMServerConfig(bt.config)

tracer, tracerServer, err := bt.initTracing(b)
if err != nil {
Expand Down
37 changes: 23 additions & 14 deletions beater/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,14 @@ var configMonitors = &configTelemetry{
tailSamplingPolicies: monitoring.NewInt(apmRegistry, "sampling.tail.policies"),
}

func recordConfigs(info beat.Info, apmCfg *config.Config, rootCfg *common.Config) error {
// recordRootConfig records static properties of the given root config for telemetry.
// This should be called once at startup, with the root config.
func recordRootConfig(info beat.Info, rootCfg *common.Config) error {
indexManagementCfg, err := idxmgmt.NewIndexManagementConfig(info, rootCfg)
if err != nil {
return err
}
configMonitors.dataStreamsEnabled.Set(apmCfg.DataStreams.Enabled)
configMonitors.rumEnabled.Set(apmCfg.RumConfig.IsEnabled())
configMonitors.apiKeysEnabled.Set(apmCfg.APIKeyConfig.IsEnabled())
configMonitors.kibanaEnabled.Set(apmCfg.Kibana.Enabled)
configMonitors.jaegerHTTPEnabled.Set(apmCfg.JaegerConfig.HTTP.Enabled)
configMonitors.jaegerGRPCEnabled.Set(apmCfg.JaegerConfig.GRPC.Enabled)
configMonitors.sslEnabled.Set(apmCfg.TLS.IsEnabled())
configMonitors.pipelinesEnabled.Set(apmCfg.Register.Ingest.Pipeline.IsEnabled())
configMonitors.pipelinesOverwrite.Set(apmCfg.Register.Ingest.Pipeline.ShouldOverwrite())
configMonitors.dataStreamsEnabled.Set(indexManagementCfg.DataStreams)
configMonitors.setupTemplateEnabled.Set(indexManagementCfg.Template.Enabled)
configMonitors.setupTemplateOverwrite.Set(indexManagementCfg.Template.Overwrite)
configMonitors.setupTemplateAppendFields.Set(len(indexManagementCfg.Template.AppendFields.GetKeys()) > 0)
Expand All @@ -92,11 +86,26 @@ func recordConfigs(info beat.Info, apmCfg *config.Config, rootCfg *common.Config
configMonitors.ilmSetupRequirePolicy.Set(indexManagementCfg.ILM.Setup.RequirePolicy)
mode := indexManagementCfg.ILM.Mode
configMonitors.ilmEnabled.Set(mode == ilm.ModeAuto || mode == ilm.ModeEnabled)
return nil
}

tailSamplingEnabled := apmCfg.Sampling.Tail != nil && apmCfg.Sampling.Tail.Enabled
configMonitors.tailSamplingEnabled.Set(tailSamplingEnabled)
// recordAPMServerConfig records dynamic APM Server config properties for telemetry.
// This should be called once each time runServer is called.
func recordAPMServerConfig(cfg *config.Config) {
configMonitors.rumEnabled.Set(cfg.RumConfig.IsEnabled())
configMonitors.apiKeysEnabled.Set(cfg.APIKeyConfig.IsEnabled())
configMonitors.kibanaEnabled.Set(cfg.Kibana.Enabled)
configMonitors.jaegerHTTPEnabled.Set(cfg.JaegerConfig.HTTP.Enabled)
configMonitors.jaegerGRPCEnabled.Set(cfg.JaegerConfig.GRPC.Enabled)
configMonitors.sslEnabled.Set(cfg.TLS.IsEnabled())
configMonitors.pipelinesEnabled.Set(cfg.Register.Ingest.Pipeline.IsEnabled())
configMonitors.pipelinesOverwrite.Set(cfg.Register.Ingest.Pipeline.ShouldOverwrite())

tailSamplingEnabled := cfg.Sampling.Tail != nil && cfg.Sampling.Tail.Enabled
tailSamplingPolicies := 0
if tailSamplingEnabled {
configMonitors.tailSamplingPolicies.Set(int64(len(apmCfg.Sampling.Tail.Policies)))
tailSamplingPolicies = len(cfg.Sampling.Tail.Policies)
}
return nil
configMonitors.tailSamplingEnabled.Set(tailSamplingEnabled)
configMonitors.tailSamplingPolicies.Set(int64(tailSamplingPolicies))
}
3 changes: 2 additions & 1 deletion beater/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func TestRecordConfigs(t *testing.T) {
},
},
})
require.NoError(t, recordConfigs(info, apmCfg, rootCfg))
require.NoError(t, recordRootConfig(info, rootCfg))
recordAPMServerConfig(apmCfg)

assert.Equal(t, configMonitors.ilmSetupEnabled.Get(), true)
assert.Equal(t, configMonitors.rumEnabled.Get(), false)
Expand Down

0 comments on commit ad5d272

Please sign in to comment.