diff --git a/internal/beater/beater.go b/internal/beater/beater.go index 7cb5c0310f..c6c2184347 100644 --- a/internal/beater/beater.go +++ b/internal/beater/beater.go @@ -410,6 +410,7 @@ func (s *Runner) Run(ctx context.Context) error { kibanaClient, newElasticsearchClient, tracer, + s.logger, ) if err != nil { return err diff --git a/internal/beater/beater_test.go b/internal/beater/beater_test.go index 5a52994a6b..15cd3d5f32 100644 --- a/internal/beater/beater_test.go +++ b/internal/beater/beater_test.go @@ -37,6 +37,8 @@ import ( "github.com/stretchr/testify/require" "go.elastic.co/apm/v2/apmtest" "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" "github.com/elastic/apm-server/internal/beater/config" "github.com/elastic/apm-server/internal/elasticsearch" @@ -243,6 +245,28 @@ func TestRunnerNewDocappenderConfig(t *testing.T) { } } +func TestAgentConfigFetcherDeprecation(t *testing.T) { + core, observed := observer.New(zapcore.DebugLevel) + logger := logp.NewLogger("bo", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + return zapcore.NewTee(in, core) + })) + + _, _, err := newAgentConfigFetcher(context.Background(), &config.Config{ + FleetAgentConfigs: []config.FleetAgentConfig{ + { + AgentName: "foo", + }, + }, + }, nil, func(c *elasticsearch.Config) (*elasticsearch.Client, error) { return nil, nil }, nil, logger) + require.NoError(t, err) + + all := observed.All() + assert.Len(t, all, 1) + record := all[0] + assert.Equal(t, zapcore.WarnLevel, record.Level, record.Message) + assert.Equal(t, agentcfgDeprecationNotice, record.Message) +} + func TestNewInstrumentation(t *testing.T) { var auth string labels := make(chan map[string]string, 1) diff --git a/internal/beater/server.go b/internal/beater/server.go index 973269cc8c..ac4593adee 100644 --- a/internal/beater/server.go +++ b/internal/beater/server.go @@ -49,6 +49,8 @@ import ( var ( agentcfgMonitoringRegistry = monitoring.Default.NewRegistry("apm-server.agentcfg") + + agentcfgDeprecationNotice = "deprecation notice: support for passing fleet agent configs will be removed in an upcoming version" ) // WrapServerFunc is a function for injecting behaviour into ServerParams @@ -240,6 +242,7 @@ func newAgentConfigFetcher( kibanaClient *kibana.Client, newElasticsearchClient func(*elasticsearch.Config) (*elasticsearch.Client, error), tracer *apm.Tracer, + logger *logp.Logger, ) (agentcfg.Fetcher, func(context.Context) error, error) { // Always use ElasticsearchFetcher, and as a fallback, use: // 1. no fallback if Elasticsearch is explicitly configured @@ -252,6 +255,7 @@ func newAgentConfigFetcher( case cfg.AgentConfig.ESOverrideConfigured: // Disable fallback because agent config Elasticsearch is explicitly configured. case cfg.FleetAgentConfigs != nil: + logger.Warn(agentcfgDeprecationNotice) agentConfigurations := agentcfg.ConvertAgentConfigs(cfg.FleetAgentConfigs) fallbackFetcher = agentcfg.NewDirectFetcher(agentConfigurations) case kibanaClient != nil: