Skip to content

Commit

Permalink
feat: add fleet agent cfg deprecation notice (#15260)
Browse files Browse the repository at this point in the history
* feat: add fleet agent cfg deprecation notice

* Update internal/beater/server.go

Co-authored-by: simitt <[email protected]>

---------

Co-authored-by: simitt <[email protected]>
  • Loading branch information
kruskall and simitt authored Jan 16, 2025
1 parent 7f89b7e commit 911887c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ func (s *Runner) Run(ctx context.Context) error {
kibanaClient,
newElasticsearchClient,
tracer,
s.logger,
)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions internal/beater/beater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/beater/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 911887c

Please sign in to comment.