Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add wrapper around libbeat instrumentation to propagate missing tracer config #13653

Merged
merged 8 commits into from
Jul 11, 2024
46 changes: 45 additions & 1 deletion internal/beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (s *Runner) Run(ctx context.Context) error {
}
}

instrumentation, err := instrumentation.New(s.rawConfig, "apm-server", version.Version)
instrumentation, err := newInstrumentation(s.rawConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -537,6 +537,50 @@ func (s *Runner) Run(ctx context.Context) error {
return errors.Join(result, closeErr)
}

// newInstrumentation is a thin wrapper around libbeat instrumentation that
// sets missing tracer configuration from elastic-agent.
func newInstrumentation(rawConfig *agentconfig.C) (instrumentation.Instrumentation, error) {
1pkg marked this conversation as resolved.
Show resolved Hide resolved
var apmCfg struct {
1pkg marked this conversation as resolved.
Show resolved Hide resolved
GlobalLabels string `config:"globallabels"`
TLS struct {
SkipVerify bool `config:"skipverify"`
ServerCertificate string `config:"servercert"`
ServerCA string `config:"serverca"`
} `config:"tls"`
}
cfg, err := rawConfig.Child("instrumentation", -1)
if err != nil {
// Fallback to instrumentation.New if the configs are not present.
return instrumentation.New(rawConfig, "apm-server", version.Version)
}
if err := cfg.Unpack(&apmCfg); err != nil {
return nil, err
}
const (
envVerifyServerCert = "ELASTIC_APM_VERIFY_SERVER_CERT"
envServerCert = "ELASTIC_APM_SERVER_CERT"
envCACert = "ELASTIC_APM_SERVER_CA_CERT_FILE"
envGlobalLabels = "ELASTIC_APM_GLOBAL_LABELS"
)
if apmCfg.TLS.SkipVerify {
os.Setenv(envVerifyServerCert, "false")
defer os.Unsetenv(envVerifyServerCert)
}
if apmCfg.TLS.ServerCertificate != "" {
os.Setenv(envServerCert, apmCfg.TLS.ServerCertificate)
defer os.Unsetenv(envServerCert)
}
if apmCfg.TLS.ServerCA != "" {
os.Setenv(envCACert, apmCfg.TLS.ServerCA)
defer os.Unsetenv(envCACert)
}
if len(apmCfg.GlobalLabels) > 0 {
os.Setenv(envGlobalLabels, apmCfg.GlobalLabels)
defer os.Unsetenv(envGlobalLabels)
}
return instrumentation.New(rawConfig, "apm-server", version.Version)
}

func maxConcurrentDecoders(memLimitGB float64) uint {
// Allow 128 concurrent decoders for each 1GB memory, limited to at most 2048.
const max = 2048
Expand Down