Skip to content

Commit

Permalink
add wrapper to libbeat instrumentation to propagate missing tracer
Browse files Browse the repository at this point in the history
config via env
  • Loading branch information
1pkg committed Jul 9, 2024
1 parent ab4b728 commit f2ae5e9
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 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,49 @@ 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) {
var apmCfg struct {
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 {
return nil, err
}
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

0 comments on commit f2ae5e9

Please sign in to comment.