Skip to content

Commit

Permalink
beater: telemetry for tail-based sampling config (elastic#4360)
Browse files Browse the repository at this point in the history
* beater: telemetry for tail-based sampling config
  • Loading branch information
axw authored and simitt committed Oct 29, 2020
1 parent 6332320 commit e28ed59
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
4 changes: 3 additions & 1 deletion beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func (bt *beater) Run(b *beat.Beat) error {
}

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

tracer, tracerServer, err := bt.initTracing(b)
if err != nil {
Expand Down
17 changes: 13 additions & 4 deletions beater/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/idxmgmt/ilm"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/monitoring"
)

Expand All @@ -45,6 +44,8 @@ type configTelemetry struct {
jaegerGRPCEnabled *monitoring.Bool
jaegerHTTPEnabled *monitoring.Bool
sslEnabled *monitoring.Bool
tailSamplingEnabled *monitoring.Bool
tailSamplingPolicies *monitoring.Int
}

var configMonitors = &configTelemetry{
Expand All @@ -63,13 +64,14 @@ var configMonitors = &configTelemetry{
jaegerGRPCEnabled: monitoring.NewBool(apmRegistry, "jaeger.grpc.enabled"),
jaegerHTTPEnabled: monitoring.NewBool(apmRegistry, "jaeger.http.enabled"),
sslEnabled: monitoring.NewBool(apmRegistry, "ssl.enabled"),
tailSamplingEnabled: monitoring.NewBool(apmRegistry, "sampling.tail.enabled"),
tailSamplingPolicies: monitoring.NewInt(apmRegistry, "sampling.tail.policies"),
}

func recordConfigs(info beat.Info, apmCfg *config.Config, rootCfg *common.Config, logger *logp.Logger) {
func recordConfigs(info beat.Info, apmCfg *config.Config, rootCfg *common.Config) error {
indexManagementCfg, err := idxmgmt.NewIndexManagementConfig(info, rootCfg)
if err != nil {
logger.Errorf("Error recording telemetry data", err)
return
return err
}
configMonitors.rumEnabled.Set(apmCfg.RumConfig.IsEnabled())
configMonitors.apiKeysEnabled.Set(apmCfg.APIKeyConfig.IsEnabled())
Expand All @@ -87,4 +89,11 @@ 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)

tailSamplingEnabled := apmCfg.Sampling.Tail != nil && apmCfg.Sampling.Tail.Enabled
configMonitors.tailSamplingEnabled.Set(tailSamplingEnabled)
if tailSamplingEnabled {
configMonitors.tailSamplingPolicies.Set(int64(len(apmCfg.Sampling.Tail.Policies)))
}
return nil
}
5 changes: 2 additions & 3 deletions beater/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ package beater
import (
"testing"

"github.com/elastic/beats/v7/libbeat/logp"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/apm-server/beater/config"
"github.com/elastic/beats/v7/libbeat/beat"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestRecordConfigs(t *testing.T) {
},
},
})
recordConfigs(info, apmCfg, rootCfg, logp.NewLogger("beater"))
require.NoError(t, recordConfigs(info, apmCfg, rootCfg))

assert.Equal(t, configMonitors.ilmSetupEnabled.Get(), true)
assert.Equal(t, configMonitors.rumEnabled.Get(), false)
Expand Down
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ https://github.com/elastic/apm-server/compare/7.10\...master[View commits]
* Monitoring for aggregation of transaction metrics {pull}4287[4287]
* Log warnings in aggregation of transaction metrics when grouping limit is reached {pull}4313[4313]
* Configurable tail-based sampling policies {pull}4320[4320]
* Monitoring and telemetry for tail-based sampling {pull}4346[4346] {pull}4360[4360]
15 changes: 15 additions & 0 deletions systemtest/sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ func TestTailSampling(t *testing.T) {
// Make sure apm-server.sampling.tail metrics are published. Metric values are unit tested.
doc := getBeatsMonitoringStats(t, srv1, nil)
assert.True(t, gjson.GetBytes(doc.RawSource, "beats_stats.metrics.apm-server.sampling.tail").Exists())

// Check tail-sampling config is reported in telemetry.
var state struct {
APMServer struct {
Sampling struct {
Tail struct {
Enabled bool
Policies int
}
}
} `mapstructure:"apm-server"`
}
getBeatsMonitoringState(t, srv1, &state)
assert.True(t, state.APMServer.Sampling.Tail.Enabled)
assert.Equal(t, 1, state.APMServer.Sampling.Tail.Policies)
}

func TestTailSamplingUnlicensed(t *testing.T) {
Expand Down

0 comments on commit e28ed59

Please sign in to comment.