From 5bf2ff8e1227b790da7ab80342ea69e0c3169098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Fri, 29 May 2020 18:22:27 +0200 Subject: [PATCH 01/13] Add basic configuration for the APM tracer --- .../_meta/config/default.reference.yml.tmpl | 1 + libbeat/_meta/config/default.short.yml.tmpl | 1 + .../config/instrumentation.reference.yml.tmpl | 35 +++ libbeat/_meta/config/instrumentation.yml.tmpl | 22 ++ libbeat/beat/beat.go | 2 + libbeat/beat/instrumentation.go | 202 ++++++++++++++++++ libbeat/cmd/instance/beat.go | 36 ++-- libbeat/pipe/listener.go | 103 +++++++++ 8 files changed, 384 insertions(+), 18 deletions(-) create mode 100644 libbeat/_meta/config/instrumentation.reference.yml.tmpl create mode 100644 libbeat/_meta/config/instrumentation.yml.tmpl create mode 100644 libbeat/beat/instrumentation.go create mode 100644 libbeat/pipe/listener.go diff --git a/libbeat/_meta/config/default.reference.yml.tmpl b/libbeat/_meta/config/default.reference.yml.tmpl index c7c75d51cf4..7919bd0d4f7 100644 --- a/libbeat/_meta/config/default.reference.yml.tmpl +++ b/libbeat/_meta/config/default.reference.yml.tmpl @@ -19,4 +19,5 @@ {{template "monitoring.reference.yml.tmpl" .}} {{template "http.reference.yml.tmpl" .}} {{template "seccomp.reference.yml.tmpl" .}} +{{template "instrumentation.reference.yml.tmpl" .}} {{template "migration.yml.tmpl" .}} diff --git a/libbeat/_meta/config/default.short.yml.tmpl b/libbeat/_meta/config/default.short.yml.tmpl index c18d2abd8a5..103f570f7de 100644 --- a/libbeat/_meta/config/default.short.yml.tmpl +++ b/libbeat/_meta/config/default.short.yml.tmpl @@ -9,4 +9,5 @@ {{template "processors.yml.tmpl" .}} {{template "logging.yml.tmpl" .}} {{template "monitoring.yml.tmpl" .}} +{{template "instrumentation.yml.tmpl" .}} {{template "migration.yml.tmpl" .}} diff --git a/libbeat/_meta/config/instrumentation.reference.yml.tmpl b/libbeat/_meta/config/instrumentation.reference.yml.tmpl new file mode 100644 index 00000000000..0db13c5bf55 --- /dev/null +++ b/libbeat/_meta/config/instrumentation.reference.yml.tmpl @@ -0,0 +1,35 @@ +{{header "Instrumentation"}} + +# Instrumentation support for the {{.BeatName}}. +#instrumentation: + # Set to true to enable instrumentation of {{.BeatName}}. + #enabled: false + + # Environment in which {{.BeatName}} is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s diff --git a/libbeat/_meta/config/instrumentation.yml.tmpl b/libbeat/_meta/config/instrumentation.yml.tmpl new file mode 100644 index 00000000000..8b9cbc4dd0a --- /dev/null +++ b/libbeat/_meta/config/instrumentation.yml.tmpl @@ -0,0 +1,22 @@ +{{header "Instrumentation"}} + +# Instrumentation support for the {{.BeatName}}. +#instrumentation: + # Set to true to enable instrumentation of {{.BeatName}}. + #enabled: false + + # Environment in which {{.BeatName}} is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + diff --git a/libbeat/beat/beat.go b/libbeat/beat/beat.go index 75585ba8992..164b03376b0 100644 --- a/libbeat/beat/beat.go +++ b/libbeat/beat/beat.go @@ -69,6 +69,8 @@ type Beat struct { ConfigManager management.ConfigManager // config manager Keystore keystore.Keystore + + Instrumentation *Instrumentation // Instrumentation holds an APM agent for capturing and reporting traces } // BeatConfig struct contains the basic configuration of every beat diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go new file mode 100644 index 00000000000..a4de448ab8c --- /dev/null +++ b/libbeat/beat/instrumentation.go @@ -0,0 +1,202 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package beat + +import ( + "fmt" + "net" + "net/http" + "net/url" + "os" + "time" + + "go.elastic.co/apm" + "go.elastic.co/apm/transport" + + "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/beats/v7/libbeat/pipe" +) + +// Instrumentation holds an APM tracer a net.Listener +type Instrumentation struct { + tracer *apm.Tracer + // the Listener is only relevant for APM Server sending tracing data to itself + // APM Server needs this Listener to create an ad-hoc tracing server + Listener net.Listener +} + +// GetTracer returns the configured tracer +// If there is not configured tracer, it returns the DefaultTracer, which is always disabled +func (t *Instrumentation) GetTracer() *apm.Tracer { + if t == nil || t.tracer == nil { + return apm.DefaultTracer + } + return t.tracer +} + +// InstrumentationConfig holds config information about self instrumenting the APM Server +type InstrumentationConfig struct { + Enabled *bool `config:"enabled"` + Environment *string `config:"environment"` + Hosts []*url.URL `config:"hosts"` + Profiling ProfilingConfig `config:"profiling"` + APIKey string `config:"api_key"` + SecretToken string `config:"secret_token"` +} + +// ProfilingConfig holds config information about self profiling the APM Server +type ProfilingConfig struct { + CPU *CPUProfiling `config:"cpu"` + Heap *HeapProfiling `config:"heap"` +} + +// CPUProfiling holds config information about CPU profiling of the APM Server +type CPUProfiling struct { + Enabled bool `config:"enabled"` + Interval time.Duration `config:"interval" validate:"positive"` + Duration time.Duration `config:"duration" validate:"positive"` +} + +// IsEnabled indicates whether instrumentation is enabled +func (c *InstrumentationConfig) IsEnabled() bool { + return c != nil && c.Enabled != nil && *c.Enabled +} + +// IsEnabled indicates whether CPU profiling is enabled +func (p *CPUProfiling) IsEnabled() bool { + return p != nil && p.Enabled +} + +// IsEnabled indicates whether heap profiling is enabled +func (p *HeapProfiling) IsEnabled() bool { + return p != nil && p.Enabled +} + +// HeapProfiling holds config information about heap profiling of the APM Server +type HeapProfiling struct { + Enabled bool `config:"enabled"` + Interval time.Duration `config:"interval" validate:"positive"` +} + +// CreateTracer configures and returns an instrumentation object for tracing +func CreateTracer(cfg *common.Config, info Info) (*Instrumentation, error) { + if !cfg.HasField("instrumentation") { + return nil, nil + } + + instrumentation, err := cfg.Child("instrumentation", -1) + if err != nil { + return nil, nil + } + + config := InstrumentationConfig{} + + if instrumentation == nil { + instrumentation = common.NewConfig() + } + err = instrumentation.Unpack(&config) + + if err != nil { + return nil, fmt.Errorf("could not create tracer, err: %v", err) + } + + return initTracer(config, info) +} + +func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) { + + logger := logp.NewLogger("tracing") + + if !cfg.IsEnabled() { + os.Setenv("ELASTIC_APM_ACTIVE", "false") + logger.Infof("APM instrumentation is disabled") + return nil, nil + } else { + os.Setenv("ELASTIC_APM_ACTIVE", "true") + logger.Infof("APM instrumentation is enabled") + } + + if cfg.Profiling.CPU.IsEnabled() { + interval := cfg.Profiling.CPU.Interval + duration := cfg.Profiling.CPU.Duration + logger.Infof("CPU profiling: every %s for %s", interval, duration) + os.Setenv("ELASTIC_APM_CPU_PROFILE_INTERVAL", fmt.Sprintf("%dms", int(interval.Seconds()*1000))) + os.Setenv("ELASTIC_APM_CPU_PROFILE_DURATION", fmt.Sprintf("%dms", int(duration.Seconds()*1000))) + } + if cfg.Profiling.Heap.IsEnabled() { + interval := cfg.Profiling.Heap.Interval + logger.Infof("Heap profiling: every %s", interval) + os.Setenv("ELASTIC_APM_HEAP_PROFILE_INTERVAL", fmt.Sprintf("%dms", int(interval.Seconds()*1000))) + } + + var tracerTransport transport.Transport + var tracerListener net.Listener + if cfg.Hosts != nil { + // tracing destined for host explicitly set + t, err := transport.NewHTTPTransport() + + if err != nil { + return nil, err + } + t.SetServerURL(cfg.Hosts...) + if cfg.APIKey != "" { + t.SetAPIKey(cfg.APIKey) + } else { + t.SetSecretToken(cfg.SecretToken) + } + tracerTransport = t + logger.Infof("self pipe directed to %s", cfg.Hosts) + } else { + // if the host is not set, the running beat is an APM Server sending traces to itself + // if another beat is running without an APM Server host configured, we default to localhost + pipeListener := pipe.NewListener() + pipeTransport, err := transport.NewHTTPTransport() + if err != nil { + return nil, err + } + pipeTransport.SetServerURL(&url.URL{Scheme: "http", Host: "localhost"}) + pipeTransport.Client.Transport = &http.Transport{ + DialContext: pipeListener.DialContext, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + } + tracerTransport = pipeTransport + // the traceListener will allow APM Server to create a ad-hoc server for tracing + tracerListener = pipeListener + } + + var environment string + if cfg.Environment != nil { + environment = *cfg.Environment + } + tracer, err := apm.NewTracerOptions(apm.TracerOptions{ + ServiceName: info.Beat, + ServiceVersion: info.Version, + ServiceEnvironment: environment, + Transport: tracerTransport, + }) + if tracer != nil { + tracer.SetLogger(logger) + } + + return &Instrumentation{ + tracer: tracer, + Listener: tracerListener, + }, err +} diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index ee5529c9036..6e7dc8b06a9 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -96,11 +96,12 @@ type beatConfig struct { Seccomp *common.Config `config:"seccomp"` // beat internal components configurations - HTTP *common.Config `config:"http"` - Path paths.Path `config:"path"` - Logging *common.Config `config:"logging"` - MetricLogging *common.Config `config:"logging.metrics"` - Keystore *common.Config `config:"keystore"` + HTTP *common.Config `config:"http"` + Path paths.Path `config:"path"` + Logging *common.Config `config:"logging"` + MetricLogging *common.Config `config:"logging.metrics"` + Keystore *common.Config `config:"keystore"` + Instrumentation *common.Config `config:"pipe"` // output/publishing related configurations Pipeline pipeline.Config `config:",inline"` @@ -144,11 +145,6 @@ func initRand() { } func preventDefaultTracing() { - // By default, the APM tracer is active. We switch behaviour to not require users to have - // an APM Server running, making it opt-in - if os.Getenv("ELASTIC_APM_ACTIVE") == "" { - os.Setenv("ELASTIC_APM_ACTIVE", "false") - } // we need to close the default tracer to prevent the beat sending events to localhost:8200 apm.DefaultTracer.Close() } @@ -343,18 +339,12 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) { return nil, errors.New(msg) } } - - tracer, err := apm.NewTracer(b.Info.Beat, b.Info.Version) - if err != nil { - return nil, err - } - pipeline, err := pipeline.Load(b.Info, pipeline.Monitors{ Metrics: reg, Telemetry: monitoring.GetNamespace("state").GetRegistry(), Logger: logp.L().Named("publisher"), - Tracer: tracer, + Tracer: b.Instrumentation.GetTracer(), }, b.Config.Pipeline, b.processing, @@ -446,7 +436,11 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error { } ctx, cancel := context.WithCancel(context.Background()) - svc.HandleSignals(beater.Stop, cancel) + var stopBeat = func() { + b.Instrumentation.GetTracer().Close() + beater.Stop() + } + svc.HandleSignals(stopBeat, cancel) err = b.loadDashboards(ctx, false) if err != nil { @@ -601,6 +595,12 @@ func (b *Beat) configure(settings Settings) error { // TODO: Allow the options to be more flexible for dynamic changes common.OverwriteConfigOpts(configOpts(store)) } + //tracer, _ := apm.NewTracer("foo", "bar") + tracer, err := beat.CreateTracer(cfg, b.Info) + if err != nil { + return err + } + b.Beat.Instrumentation = tracer b.keystore = store b.Beat.Keystore = store diff --git a/libbeat/pipe/listener.go b/libbeat/pipe/listener.go new file mode 100644 index 00000000000..7d879b4b701 --- /dev/null +++ b/libbeat/pipe/listener.go @@ -0,0 +1,103 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package pipe + +import ( + "context" + "errors" + "net" + "sync" +) + +// errListenerClosed is the error returned by the Accept +// and DialContext methods of a closed listener. +var errListenerClosed = errors.New("listener is closed") + +// Listener is a net.Listener that uses net.Pipe +// It is only relevant for the APM Server instrumentation of itself +type Listener struct { + conns chan net.Conn + closeOnce sync.Once + closed chan struct{} +} + +// NewListener returns a new Listener. +func NewListener() *Listener { + l := &Listener{ + conns: make(chan net.Conn), + closed: make(chan struct{}), + } + return l +} + +// Close closes the listener. +// This is part of the net.Listener interface. +func (l *Listener) Close() error { + l.closeOnce.Do(func() { close(l.closed) }) + return nil +} + +// Addr returns the listener's network address. +// This is part of the net.Listener interface. +// +// The returned address's network and value are always both +// "pipe", the same as the addresses returned by net.Pipe +// connections. +func (l *Listener) Addr() net.Addr { + return pipeAddr{} +} + +// Accept waits for and returns the next connection to the listener. +// This is part of the net.Listener address. +func (l *Listener) Accept() (net.Conn, error) { + select { + case <-l.closed: + return nil, errListenerClosed + case conn := <-l.conns: + return conn, nil + } +} + +// DialContext dials a connection to the listener, blocking until +// a paired Accept call is made, the listener is closed, or the +// context is canceled/expired. +func (l *Listener) DialContext(ctx context.Context, network, addr string) (net.Conn, error) { + client, server := net.Pipe() + select { + case <-l.closed: + client.Close() + server.Close() + return nil, errListenerClosed + case <-ctx.Done(): + client.Close() + server.Close() + return nil, ctx.Err() + case l.conns <- server: + return client, nil + } +} + +type pipeAddr struct{} + +func (pipeAddr) Network() string { + return "pipe" +} + +func (pipeAddr) String() string { + return "pipe" +} From 6a60a1cd749bed8797b4d6bfacff8a5da7c04913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Tue, 2 Jun 2020 10:02:23 +0200 Subject: [PATCH 02/13] Update yml files --- auditbeat/auditbeat.reference.yml | 36 +++++++++++++++++++ auditbeat/auditbeat.yml | 23 ++++++++++++ filebeat/filebeat.reference.yml | 36 +++++++++++++++++++ filebeat/filebeat.yml | 23 ++++++++++++ heartbeat/heartbeat.reference.yml | 36 +++++++++++++++++++ heartbeat/heartbeat.yml | 23 ++++++++++++ journalbeat/journalbeat.reference.yml | 36 +++++++++++++++++++ journalbeat/journalbeat.yml | 23 ++++++++++++ metricbeat/metricbeat.reference.yml | 36 +++++++++++++++++++ metricbeat/metricbeat.yml | 23 ++++++++++++ packetbeat/packetbeat.reference.yml | 36 +++++++++++++++++++ packetbeat/packetbeat.yml | 23 ++++++++++++ winlogbeat/winlogbeat.reference.yml | 36 +++++++++++++++++++ winlogbeat/winlogbeat.yml | 23 ++++++++++++ x-pack/auditbeat/auditbeat.reference.yml | 36 +++++++++++++++++++ x-pack/auditbeat/auditbeat.yml | 23 ++++++++++++ x-pack/filebeat/filebeat.reference.yml | 36 +++++++++++++++++++ x-pack/filebeat/filebeat.yml | 23 ++++++++++++ .../functionbeat/functionbeat.reference.yml | 36 +++++++++++++++++++ x-pack/functionbeat/functionbeat.yml | 23 ++++++++++++ x-pack/metricbeat/metricbeat.reference.yml | 36 +++++++++++++++++++ x-pack/metricbeat/metricbeat.yml | 23 ++++++++++++ x-pack/winlogbeat/winlogbeat.reference.yml | 36 +++++++++++++++++++ x-pack/winlogbeat/winlogbeat.yml | 23 ++++++++++++ 24 files changed, 708 insertions(+) diff --git a/auditbeat/auditbeat.reference.yml b/auditbeat/auditbeat.reference.yml index 95bdb13eb7c..0b515ba93f9 100644 --- a/auditbeat/auditbeat.reference.yml +++ b/auditbeat/auditbeat.reference.yml @@ -1482,6 +1482,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the auditbeat. +#instrumentation: + # Set to true to enable instrumentation of auditbeat. + #enabled: false + + # Environment in which auditbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/auditbeat/auditbeat.yml b/auditbeat/auditbeat.yml index 79cca537a8a..7e1e096f1db 100644 --- a/auditbeat/auditbeat.yml +++ b/auditbeat/auditbeat.yml @@ -187,6 +187,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the auditbeat. +#instrumentation: + # Set to true to enable instrumentation of auditbeat. + #enabled: false + + # Environment in which auditbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/filebeat/filebeat.reference.yml b/filebeat/filebeat.reference.yml index 0a3d03d98be..0691c5843ab 100644 --- a/filebeat/filebeat.reference.yml +++ b/filebeat/filebeat.reference.yml @@ -2195,6 +2195,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the filebeat. +#instrumentation: + # Set to true to enable instrumentation of filebeat. + #enabled: false + + # Environment in which filebeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/filebeat/filebeat.yml b/filebeat/filebeat.yml index 9dbcc8f6c64..9654f0158e5 100644 --- a/filebeat/filebeat.yml +++ b/filebeat/filebeat.yml @@ -212,6 +212,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the filebeat. +#instrumentation: + # Set to true to enable instrumentation of filebeat. + #enabled: false + + # Environment in which filebeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/heartbeat/heartbeat.reference.yml b/heartbeat/heartbeat.reference.yml index 9ceb79b1e9f..ec01d9a0af6 100644 --- a/heartbeat/heartbeat.reference.yml +++ b/heartbeat/heartbeat.reference.yml @@ -1632,6 +1632,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the heartbeat. +#instrumentation: + # Set to true to enable instrumentation of heartbeat. + #enabled: false + + # Environment in which heartbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/heartbeat/heartbeat.yml b/heartbeat/heartbeat.yml index 425329e7c9a..032e599cd63 100644 --- a/heartbeat/heartbeat.yml +++ b/heartbeat/heartbeat.yml @@ -163,6 +163,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the heartbeat. +#instrumentation: + # Set to true to enable instrumentation of heartbeat. + #enabled: false + + # Environment in which heartbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/journalbeat/journalbeat.reference.yml b/journalbeat/journalbeat.reference.yml index 6824dfe28cf..643db011b8d 100644 --- a/journalbeat/journalbeat.reference.yml +++ b/journalbeat/journalbeat.reference.yml @@ -1424,6 +1424,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the journalbeat. +#instrumentation: + # Set to true to enable instrumentation of journalbeat. + #enabled: false + + # Environment in which journalbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/journalbeat/journalbeat.yml b/journalbeat/journalbeat.yml index e3d72984701..092c8e9c5df 100644 --- a/journalbeat/journalbeat.yml +++ b/journalbeat/journalbeat.yml @@ -188,6 +188,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the journalbeat. +#instrumentation: + # Set to true to enable instrumentation of journalbeat. + #enabled: false + + # Environment in which journalbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/metricbeat/metricbeat.reference.yml b/metricbeat/metricbeat.reference.yml index f16da443cba..5023b176a5f 100644 --- a/metricbeat/metricbeat.reference.yml +++ b/metricbeat/metricbeat.reference.yml @@ -2248,6 +2248,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the metricbeat. +#instrumentation: + # Set to true to enable instrumentation of metricbeat. + #enabled: false + + # Environment in which metricbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/metricbeat/metricbeat.yml b/metricbeat/metricbeat.yml index 96975ee6027..84558a2a25f 100644 --- a/metricbeat/metricbeat.yml +++ b/metricbeat/metricbeat.yml @@ -160,6 +160,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the metricbeat. +#instrumentation: + # Set to true to enable instrumentation of metricbeat. + #enabled: false + + # Environment in which metricbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/packetbeat/packetbeat.reference.yml b/packetbeat/packetbeat.reference.yml index 850e7c71501..eaca0280195 100644 --- a/packetbeat/packetbeat.reference.yml +++ b/packetbeat/packetbeat.reference.yml @@ -1908,6 +1908,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the packetbeat. +#instrumentation: + # Set to true to enable instrumentation of packetbeat. + #enabled: false + + # Environment in which packetbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/packetbeat/packetbeat.yml b/packetbeat/packetbeat.yml index 66e1bc85991..c8287c1941a 100644 --- a/packetbeat/packetbeat.yml +++ b/packetbeat/packetbeat.yml @@ -240,6 +240,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the packetbeat. +#instrumentation: + # Set to true to enable instrumentation of packetbeat. + #enabled: false + + # Environment in which packetbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/winlogbeat/winlogbeat.reference.yml b/winlogbeat/winlogbeat.reference.yml index 019f328e159..2441e5a54ec 100644 --- a/winlogbeat/winlogbeat.reference.yml +++ b/winlogbeat/winlogbeat.reference.yml @@ -1404,6 +1404,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the winlogbeat. +#instrumentation: + # Set to true to enable instrumentation of winlogbeat. + #enabled: false + + # Environment in which winlogbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/winlogbeat/winlogbeat.yml b/winlogbeat/winlogbeat.yml index 999557a8bed..f9a07d7f4ce 100644 --- a/winlogbeat/winlogbeat.yml +++ b/winlogbeat/winlogbeat.yml @@ -171,6 +171,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the winlogbeat. +#instrumentation: + # Set to true to enable instrumentation of winlogbeat. + #enabled: false + + # Environment in which winlogbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/auditbeat/auditbeat.reference.yml b/x-pack/auditbeat/auditbeat.reference.yml index 864a6bc00c4..42fb63e92e4 100644 --- a/x-pack/auditbeat/auditbeat.reference.yml +++ b/x-pack/auditbeat/auditbeat.reference.yml @@ -1538,6 +1538,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the auditbeat. +#instrumentation: + # Set to true to enable instrumentation of auditbeat. + #enabled: false + + # Environment in which auditbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/auditbeat/auditbeat.yml b/x-pack/auditbeat/auditbeat.yml index 408e52004e6..4f319db36f5 100644 --- a/x-pack/auditbeat/auditbeat.yml +++ b/x-pack/auditbeat/auditbeat.yml @@ -214,6 +214,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the auditbeat. +#instrumentation: + # Set to true to enable instrumentation of auditbeat. + #enabled: false + + # Environment in which auditbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/filebeat/filebeat.reference.yml b/x-pack/filebeat/filebeat.reference.yml index f18b1247838..b7017db5833 100644 --- a/x-pack/filebeat/filebeat.reference.yml +++ b/x-pack/filebeat/filebeat.reference.yml @@ -2945,6 +2945,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the filebeat. +#instrumentation: + # Set to true to enable instrumentation of filebeat. + #enabled: false + + # Environment in which filebeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/filebeat/filebeat.yml b/x-pack/filebeat/filebeat.yml index 9dbcc8f6c64..9654f0158e5 100644 --- a/x-pack/filebeat/filebeat.yml +++ b/x-pack/filebeat/filebeat.yml @@ -212,6 +212,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the filebeat. +#instrumentation: + # Set to true to enable instrumentation of filebeat. + #enabled: false + + # Environment in which filebeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/functionbeat/functionbeat.reference.yml b/x-pack/functionbeat/functionbeat.reference.yml index 61cf8a20042..3111cba3da7 100644 --- a/x-pack/functionbeat/functionbeat.reference.yml +++ b/x-pack/functionbeat/functionbeat.reference.yml @@ -1396,6 +1396,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the functionbeat. +#instrumentation: + # Set to true to enable instrumentation of functionbeat. + #enabled: false + + # Environment in which functionbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/functionbeat/functionbeat.yml b/x-pack/functionbeat/functionbeat.yml index bb8322840c8..df8d499cabb 100644 --- a/x-pack/functionbeat/functionbeat.yml +++ b/x-pack/functionbeat/functionbeat.yml @@ -476,6 +476,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the functionbeat. +#instrumentation: + # Set to true to enable instrumentation of functionbeat. + #enabled: false + + # Environment in which functionbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/metricbeat/metricbeat.reference.yml b/x-pack/metricbeat/metricbeat.reference.yml index 1b5327397a4..60f5fa99980 100644 --- a/x-pack/metricbeat/metricbeat.reference.yml +++ b/x-pack/metricbeat/metricbeat.reference.yml @@ -2680,6 +2680,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the metricbeat. +#instrumentation: + # Set to true to enable instrumentation of metricbeat. + #enabled: false + + # Environment in which metricbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/metricbeat/metricbeat.yml b/x-pack/metricbeat/metricbeat.yml index 96975ee6027..84558a2a25f 100644 --- a/x-pack/metricbeat/metricbeat.yml +++ b/x-pack/metricbeat/metricbeat.yml @@ -160,6 +160,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the metricbeat. +#instrumentation: + # Set to true to enable instrumentation of metricbeat. + #enabled: false + + # Environment in which metricbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/winlogbeat/winlogbeat.reference.yml b/x-pack/winlogbeat/winlogbeat.reference.yml index 40bd93a8cce..3c66e055456 100644 --- a/x-pack/winlogbeat/winlogbeat.reference.yml +++ b/x-pack/winlogbeat/winlogbeat.reference.yml @@ -1447,6 +1447,42 @@ logging.files: # Enable or disable seccomp system call filtering on Linux. Default is enabled. #seccomp.enabled: true +# ============================== Instrumentation =============================== + +# Instrumentation support for the winlogbeat. +#instrumentation: + # Set to true to enable instrumentation of winlogbeat. + #enabled: false + + # Environment in which winlogbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # Enable profiling of the server, recording profile samples as events. + # + # This feature is experimental. + #profiling: + #cpu: + # Set to true to enable CPU profiling. + #enabled: false + #interval: 60s + #duration: 10s + #heap: + # Set to true to enable heap profiling. + #enabled: false + #interval: 60s + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases diff --git a/x-pack/winlogbeat/winlogbeat.yml b/x-pack/winlogbeat/winlogbeat.yml index b346ede616c..265ae400c2e 100644 --- a/x-pack/winlogbeat/winlogbeat.yml +++ b/x-pack/winlogbeat/winlogbeat.yml @@ -214,6 +214,29 @@ processors: # uncomment the following line. #monitoring.elasticsearch: +# ============================== Instrumentation =============================== + +# Instrumentation support for the winlogbeat. +#instrumentation: + # Set to true to enable instrumentation of winlogbeat. + #enabled: false + + # Environment in which winlogbeat is running on (eg: staging, production, etc.) + #environment: "" + + # APM Server hosts to report instrumentation results to. + # For APM Server to send traces to itself, leave hosts empty. + #hosts: + # - http://localhost:8200 + + # API Key for the APM Server(s). + # If api_key is set then secret_token will be ignored. + #api_key: + + # Secret token for the APM Server(s). + #secret_token: + + # ================================= Migration ================================== # This allows to enable 6.7 migration aliases From bd791f757e2e556e40bff21f116dc2c9b7518543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Tue, 2 Jun 2020 12:29:24 +0200 Subject: [PATCH 03/13] Fix + Add test --- libbeat/beat/instrumentation.go | 4 ++-- libbeat/cmd/instance/beat.go | 6 +++--- libbeat/cmd/instance/beat_test.go | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index a4de448ab8c..dbc639d3e0c 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -94,8 +94,8 @@ type HeapProfiling struct { Interval time.Duration `config:"interval" validate:"positive"` } -// CreateTracer configures and returns an instrumentation object for tracing -func CreateTracer(cfg *common.Config, info Info) (*Instrumentation, error) { +// CreateInstrumentation configures and returns an instrumentation object for tracing +func CreateInstrumentation(cfg *common.Config, info Info) (*Instrumentation, error) { if !cfg.HasField("instrumentation") { return nil, nil } diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 6e7dc8b06a9..72bf2325311 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -595,12 +595,12 @@ func (b *Beat) configure(settings Settings) error { // TODO: Allow the options to be more flexible for dynamic changes common.OverwriteConfigOpts(configOpts(store)) } - //tracer, _ := apm.NewTracer("foo", "bar") - tracer, err := beat.CreateTracer(cfg, b.Info) + + instrumentation, err := beat.CreateInstrumentation(cfg, b.Info) if err != nil { return err } - b.Beat.Instrumentation = tracer + b.Beat.Instrumentation = instrumentation b.keystore = store b.Beat.Keystore = store diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index 81e4575f64e..d902b7a2307 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -24,9 +24,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/require" + "github.com/elastic/beats/v7/libbeat/beat" + "github.com/elastic/beats/v7/libbeat/common" - "go.elastic.co/apm" + "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/libbeat/cfgfile" @@ -121,8 +122,26 @@ func TestEmptyMetaJson(t *testing.T) { } func TestAPMTracerDisabledByDefault(t *testing.T) { - tracer, err := apm.NewTracer("", "") + b, err := NewBeat("filebeat", "testidx", "0.9") require.NoError(t, err) + + tracer := b.Instrumentation.GetTracer() defer tracer.Close() assert.False(t, tracer.Active()) } + +func TestAPMInstrumentationConfig(t *testing.T) { + cfg := common.MustNewConfigFrom(map[string]interface{}{ + "instrumentation": map[string]interface{}{ + "enabled": "true", + }, + }) + instrumentation, err := beat.CreateInstrumentation(cfg, beat.Info{Name: "filebeat", Version: "8.0"}) + require.NoError(t, err) + + assert.NotNil(t, instrumentation.Listener) + + tracer := instrumentation.GetTracer() + defer tracer.Close() + assert.True(t, tracer.Active()) +} From 9bda5dc434dd4fa33e86307e4c11ded393c329e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Wed, 3 Jun 2020 10:54:45 +0200 Subject: [PATCH 04/13] Move everything to the beat package --- libbeat/beat/instrumentation.go | 5 ++ libbeat/beat/instrumentation_test.go | 77 ++++++++++++++++++++++++++++ libbeat/cmd/instance/beat.go | 8 --- libbeat/cmd/instance/beat_test.go | 30 ----------- 4 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 libbeat/beat/instrumentation_test.go diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index dbc639d3e0c..e6fc6864b3a 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -33,6 +33,11 @@ import ( "github.com/elastic/beats/v7/libbeat/pipe" ) +func init() { + // we need to close the default tracer to prevent the beat sending events to localhost:8200 + apm.DefaultTracer.Close() +} + // Instrumentation holds an APM tracer a net.Listener type Instrumentation struct { tracer *apm.Tracer diff --git a/libbeat/beat/instrumentation_test.go b/libbeat/beat/instrumentation_test.go new file mode 100644 index 00000000000..d66bf7efb98 --- /dev/null +++ b/libbeat/beat/instrumentation_test.go @@ -0,0 +1,77 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package beat + +import ( + "net/url" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/beats/v7/libbeat/version" +) + +func TestAPMTracerDisabledByDefault(t *testing.T) { + b := Beat{ + Info: Info{ + Beat: "my-beat", + IndexPrefix: "my-beat-*", + Version: version.GetDefaultVersion(), + Name: "my-beat", + }, + } + tracer := b.Instrumentation.GetTracer() + require.NotNil(t, tracer) + defer tracer.Close() + assert.False(t, tracer.Active()) +} + +func TestAPMInstrumentationConfig(t *testing.T) { + cfg := common.MustNewConfigFrom(map[string]interface{}{ + "instrumentation": map[string]interface{}{ + "enabled": "true", + }, + }) + instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) + require.NoError(t, err) + + assert.NotNil(t, instrumentation.Listener) + + tracer := instrumentation.GetTracer() + defer tracer.Close() + assert.True(t, tracer.Active()) +} + +func TestAPMInstrumentationExplicitHosts(t *testing.T) { + cfg := common.MustNewConfigFrom(map[string]interface{}{ + "instrumentation": map[string]interface{}{ + "enabled": "true", + "hosts": []url.URL{{ + Scheme: "http", + Host: "localhost:8200", + }}, + }, + }) + instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) + require.NoError(t, err) + defer instrumentation.GetTracer().Close() + + assert.Nil(t, instrumentation.Listener) +} diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 72bf2325311..4e7ac663cf2 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -33,8 +33,6 @@ import ( "strings" "time" - "go.elastic.co/apm" - "github.com/gofrs/uuid" errw "github.com/pkg/errors" "go.uber.org/zap" @@ -124,7 +122,6 @@ var debugf = logp.MakeDebug("beat") func init() { initRand() - preventDefaultTracing() } // initRand initializes the runtime random number generator seed using @@ -144,11 +141,6 @@ func initRand() { rand.Seed(seed) } -func preventDefaultTracing() { - // we need to close the default tracer to prevent the beat sending events to localhost:8200 - apm.DefaultTracer.Close() -} - // Run initializes and runs a Beater implementation. name is the name of the // Beat (e.g. packetbeat or metricbeat). version is version number of the Beater // implementation. bt is the `Creator` callback for creating a new beater diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index d902b7a2307..8c04e87390f 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -24,11 +24,6 @@ import ( "os" "testing" - "github.com/elastic/beats/v7/libbeat/beat" - "github.com/elastic/beats/v7/libbeat/common" - - "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/gofrs/uuid" @@ -120,28 +115,3 @@ func TestEmptyMetaJson(t *testing.T) { assert.Equal(t, nil, err, "Unable to load meta file properly") assert.NotEqual(t, uuid.Nil, b.Info.ID, "Beats UUID is not set") } - -func TestAPMTracerDisabledByDefault(t *testing.T) { - b, err := NewBeat("filebeat", "testidx", "0.9") - require.NoError(t, err) - - tracer := b.Instrumentation.GetTracer() - defer tracer.Close() - assert.False(t, tracer.Active()) -} - -func TestAPMInstrumentationConfig(t *testing.T) { - cfg := common.MustNewConfigFrom(map[string]interface{}{ - "instrumentation": map[string]interface{}{ - "enabled": "true", - }, - }) - instrumentation, err := beat.CreateInstrumentation(cfg, beat.Info{Name: "filebeat", Version: "8.0"}) - require.NoError(t, err) - - assert.NotNil(t, instrumentation.Listener) - - tracer := instrumentation.GetTracer() - defer tracer.Close() - assert.True(t, tracer.Active()) -} From ee755b62a280088f95053c3fdd8f73438d413bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Wed, 3 Jun 2020 13:35:55 +0200 Subject: [PATCH 05/13] Update changelog --- CHANGELOG-developer.next.asciidoc | 1 + CHANGELOG.next.asciidoc | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index b89bd78fbbb..0aeb5006398 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -52,6 +52,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only. ==== Added +- Add configuration for APM instrumentation and expose the tracer trough the Beat object. {pull}17938[17938] - Make the behavior of clientWorker and netClientWorker consistent when error is returned from publisher pipeline - Metricset generator generates beta modules by default now. {pull}10657[10657] - The `beat.Event` accessor methods now support `@metadata` keys. {pull}10761[10761] diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index d9522335487..21decfb5fc6 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -227,6 +227,7 @@ field. You can revert this change by configuring tags for the module and omittin *Affecting all Beats* +- Add configuration for APM instrumentation and expose the tracer trough the Beat object. {pull}17938[17938] - Add document_id setting to decode_json_fields processor. {pull}15859[15859] - Include network information by default on add_host_metadata and add_observer_metadata. {issue}15347[15347] {pull}16077[16077] - Add `aws_ec2` provider for autodiscover. {issue}12518[12518] {pull}14823[14823] From 82722ed44cfc5340da7b22ceb775b9e8c5629524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 4 Jun 2020 11:07:05 +0200 Subject: [PATCH 06/13] Update libbeat/beat/instrumentation.go Co-authored-by: Andrew Wilkins --- libbeat/beat/instrumentation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index e6fc6864b3a..2f912a24854 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -41,7 +41,7 @@ func init() { // Instrumentation holds an APM tracer a net.Listener type Instrumentation struct { tracer *apm.Tracer - // the Listener is only relevant for APM Server sending tracing data to itself + // Listener is only relevant for APM Server sending tracing data to itself // APM Server needs this Listener to create an ad-hoc tracing server Listener net.Listener } From daf0561a8d85f936576f410adfc65d24686e4e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 4 Jun 2020 11:07:31 +0200 Subject: [PATCH 07/13] Update libbeat/beat/instrumentation.go Co-authored-by: Andrew Wilkins --- libbeat/beat/instrumentation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index 2f912a24854..79000e6b677 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -166,7 +166,7 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) t.SetSecretToken(cfg.SecretToken) } tracerTransport = t - logger.Infof("self pipe directed to %s", cfg.Hosts) + logger.Infof("APM tracer directed to %s", cfg.Hosts) } else { // if the host is not set, the running beat is an APM Server sending traces to itself // if another beat is running without an APM Server host configured, we default to localhost From 59c5b14d2fbfc332edd2d5f5a3f310aaa6303355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 4 Jun 2020 11:07:42 +0200 Subject: [PATCH 08/13] Update libbeat/beat/instrumentation.go Co-authored-by: Andrew Wilkins --- libbeat/beat/instrumentation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index 79000e6b677..2fc2a4e1848 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -168,7 +168,7 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) tracerTransport = t logger.Infof("APM tracer directed to %s", cfg.Hosts) } else { - // if the host is not set, the running beat is an APM Server sending traces to itself + // if the host is not set, the running beat is assumed to be an APM Server sending traces to itself // if another beat is running without an APM Server host configured, we default to localhost pipeListener := pipe.NewListener() pipeTransport, err := transport.NewHTTPTransport() From 4e2da7e135eb9be9ff418001801357ef5b774205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 4 Jun 2020 11:07:58 +0200 Subject: [PATCH 09/13] Update libbeat/beat/instrumentation.go Co-authored-by: Andrew Wilkins --- libbeat/beat/instrumentation.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index 2fc2a4e1848..031786cd1ef 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -196,12 +196,13 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) ServiceEnvironment: environment, Transport: tracerTransport, }) - if tracer != nil { - tracer.SetLogger(logger) + if err != nil { + return nil, err } - + + tracer.SetLogger(logger) return &Instrumentation{ tracer: tracer, Listener: tracerListener, - }, err + }, nil } From a0c056ec83767c82c6a7952b0f2a0bb9ad63bd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 4 Jun 2020 18:08:38 +0200 Subject: [PATCH 10/13] Code review & fix more things --- libbeat/beat/instrumentation.go | 75 +++++++++++++------ libbeat/beat/instrumentation_test.go | 34 ++++++--- libbeat/pipe/doc.go | 21 ++++++ libbeat/pipe/listener_test.go | 106 +++++++++++++++++++++++++++ 4 files changed, 204 insertions(+), 32 deletions(-) create mode 100644 libbeat/pipe/doc.go create mode 100644 libbeat/pipe/listener_test.go diff --git a/libbeat/beat/instrumentation.go b/libbeat/beat/instrumentation.go index 031786cd1ef..fb2edc0d3f4 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/beat/instrumentation.go @@ -59,12 +59,40 @@ func (t *Instrumentation) GetTracer() *apm.Tracer { type InstrumentationConfig struct { Enabled *bool `config:"enabled"` Environment *string `config:"environment"` - Hosts []*url.URL `config:"hosts"` + Hosts urls `config:"hosts"` Profiling ProfilingConfig `config:"profiling"` APIKey string `config:"api_key"` SecretToken string `config:"secret_token"` } +type urls []*url.URL + +func (u *urls) Unpack(c interface{}) error { + if c == nil { + return nil + } + hosts, ok := c.([]interface{}) + if !ok { + return fmt.Errorf("hosts must be a list, got: %#v", c) + } + + nu := make(urls, len(hosts)) + for i, host := range hosts { + h, ok := host.(string) + if !ok { + return fmt.Errorf("host must be a string, got: %#v", host) + } + url, err := url.Parse(h) + if err != nil { + return err + } + nu[i] = url + } + *u = nu + + return nil +} + // ProfilingConfig holds config information about self profiling the APM Server type ProfilingConfig struct { CPU *CPUProfiling `config:"cpu"` @@ -152,38 +180,43 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) var tracerTransport transport.Transport var tracerListener net.Listener - if cfg.Hosts != nil { - // tracing destined for host explicitly set - t, err := transport.NewHTTPTransport() - if err != nil { - return nil, err - } - t.SetServerURL(cfg.Hosts...) - if cfg.APIKey != "" { - t.SetAPIKey(cfg.APIKey) - } else { - t.SetSecretToken(cfg.SecretToken) - } - tracerTransport = t - logger.Infof("APM tracer directed to %s", cfg.Hosts) - } else { - // if the host is not set, the running beat is assumed to be an APM Server sending traces to itself - // if another beat is running without an APM Server host configured, we default to localhost + if cfg.Hosts == nil && info.Name == "apm-server" { pipeListener := pipe.NewListener() pipeTransport, err := transport.NewHTTPTransport() if err != nil { return nil, err } - pipeTransport.SetServerURL(&url.URL{Scheme: "http", Host: "localhost"}) + pipeTransport.SetServerURL(&url.URL{Scheme: "http", Host: "localhost:8200"}) pipeTransport.Client.Transport = &http.Transport{ DialContext: pipeListener.DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, } tracerTransport = pipeTransport - // the traceListener will allow APM Server to create a ad-hoc server for tracing + // the traceListener will allow APM Server to create an ad-hoc server for tracing tracerListener = pipeListener + + } else { + t, err := transport.NewHTTPTransport() + if err != nil { + return nil, err + } + hosts := cfg.Hosts + if hosts == nil { + hosts = []*url.URL{{ + Scheme: "http", + Host: "localhost:8200", + }} + } + t.SetServerURL(hosts...) + if cfg.APIKey != "" { + t.SetAPIKey(cfg.APIKey) + } else { + t.SetSecretToken(cfg.SecretToken) + } + tracerTransport = t + logger.Infof("APM tracer directed to %s", hosts) } var environment string @@ -199,7 +232,7 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) if err != nil { return nil, err } - + tracer.SetLogger(logger) return &Instrumentation{ tracer: tracer, diff --git a/libbeat/beat/instrumentation_test.go b/libbeat/beat/instrumentation_test.go index d66bf7efb98..af03afaffbe 100644 --- a/libbeat/beat/instrumentation_test.go +++ b/libbeat/beat/instrumentation_test.go @@ -18,7 +18,6 @@ package beat import ( - "net/url" "testing" "github.com/stretchr/testify/assert" @@ -43,7 +42,7 @@ func TestAPMTracerDisabledByDefault(t *testing.T) { assert.False(t, tracer.Active()) } -func TestAPMInstrumentationConfig(t *testing.T) { +func TestInstrumentationConfig(t *testing.T) { cfg := common.MustNewConfigFrom(map[string]interface{}{ "instrumentation": map[string]interface{}{ "enabled": "true", @@ -52,26 +51,39 @@ func TestAPMInstrumentationConfig(t *testing.T) { instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) require.NoError(t, err) - assert.NotNil(t, instrumentation.Listener) + tracer := instrumentation.GetTracer() + defer tracer.Close() + assert.True(t, tracer.Active()) + assert.Nil(t, instrumentation.Listener) +} +func TestInstrumentationConfigExplicitHosts(t *testing.T) { + cfg := common.MustNewConfigFrom(map[string]interface{}{ + "instrumentation": map[string]interface{}{ + "enabled": "true", + "hosts": []string{"localhost:8200"}, + }, + }, + ) + instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) + require.NoError(t, err) tracer := instrumentation.GetTracer() defer tracer.Close() assert.True(t, tracer.Active()) + assert.Nil(t, instrumentation.Listener) } -func TestAPMInstrumentationExplicitHosts(t *testing.T) { +func TestInstrumentationConfigListener(t *testing.T) { cfg := common.MustNewConfigFrom(map[string]interface{}{ "instrumentation": map[string]interface{}{ "enabled": "true", - "hosts": []url.URL{{ - Scheme: "http", - Host: "localhost:8200", - }}, }, }) - instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) + instrumentation, err := CreateInstrumentation(cfg, Info{Name: "apm-server", Version: version.GetDefaultVersion()}) require.NoError(t, err) - defer instrumentation.GetTracer().Close() - assert.Nil(t, instrumentation.Listener) + tracer := instrumentation.GetTracer() + defer tracer.Close() + assert.True(t, tracer.Active()) + assert.NotNil(t, instrumentation.Listener) } diff --git a/libbeat/pipe/doc.go b/libbeat/pipe/doc.go new file mode 100644 index 00000000000..f26f6cbf625 --- /dev/null +++ b/libbeat/pipe/doc.go @@ -0,0 +1,21 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Package pipe provides a net.Listener using net.Conn, +// for in-process communication. + +package pipe diff --git a/libbeat/pipe/listener_test.go b/libbeat/pipe/listener_test.go new file mode 100644 index 00000000000..592ddf57bc1 --- /dev/null +++ b/libbeat/pipe/listener_test.go @@ -0,0 +1,106 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package pipe + +import ( + "context" + "net" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNew(t *testing.T) { + l := NewListener() + assert.NotNil(t, l) + defer l.Close() + assert.Implements(t, new(net.Listener), l) +} + +func TestAddr(t *testing.T) { + l := NewListener() + assert.NotNil(t, l) + defer l.Close() + + addr := l.Addr() + assert.NotNil(t, addr) + assert.Equal(t, "pipe", addr.Network()) + assert.Equal(t, "pipe", addr.String()) +} + +func TestDialAccept(t *testing.T) { + l := NewListener() + assert.NotNil(t, l) + defer l.Close() + + clientCh := make(chan net.Conn, 1) + go func() { + defer close(clientCh) + client, err := l.DialContext(context.Background(), "foo", "bar") + if assert.NoError(t, err) { + clientCh <- client + } + }() + + server, err := l.Accept() + assert.NoError(t, err) + client := <-clientCh + defer server.Close() + defer client.Close() + + hello := []byte("hello!") + go client.Write(hello) + buf := make([]byte, len(hello)) + _, err = server.Read(buf) + assert.NoError(t, err) + assert.Equal(t, string(hello), string(buf)) +} + +func TestAcceptClosed(t *testing.T) { + l := NewListener() + assert.NotNil(t, l) + defer l.Close() + + err := l.Close() + assert.NoError(t, err) + _, err = l.Accept() + assert.Error(t, errListenerClosed, err) +} + +func TestDialClosed(t *testing.T) { + l := NewListener() + assert.NotNil(t, l) + defer l.Close() + + err := l.Close() + assert.NoError(t, err) + _, err = l.DialContext(context.Background(), "foo", "bar") + assert.Error(t, errListenerClosed, err) +} + +func TestDialContextCanceled(t *testing.T) { + l := NewListener() + assert.NotNil(t, l) + defer l.Close() + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + _, err := l.DialContext(ctx, "foo", "bar") + assert.Error(t, context.Canceled, err) +} From b14c24f1aa4bff824ea628b63a411f8d83dff229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 11 Jun 2020 14:00:33 +0200 Subject: [PATCH 11/13] Code review follow up --- auditbeat/auditbeat.reference.yml | 1 - auditbeat/auditbeat.yml | 1 - filebeat/filebeat.reference.yml | 1 - filebeat/filebeat.yml | 1 - heartbeat/heartbeat.reference.yml | 1 - heartbeat/heartbeat.yml | 1 - journalbeat/journalbeat.reference.yml | 1 - journalbeat/journalbeat.yml | 1 - .../config/instrumentation.reference.yml.tmpl | 1 - libbeat/_meta/config/instrumentation.yml.tmpl | 1 - libbeat/beat/beat.go | 3 +- libbeat/cmd/instance/beat.go | 7 +- .../transport/pipelistener.go} | 26 +++--- .../transport/pipelistener_test.go} | 14 +-- .../instrumentation.go | 89 ++++++++++--------- .../instrumentation_test.go | 43 ++++----- libbeat/pipe/doc.go | 21 ----- metricbeat/metricbeat.reference.yml | 1 - metricbeat/metricbeat.yml | 1 - packetbeat/packetbeat.reference.yml | 1 - packetbeat/packetbeat.yml | 1 - winlogbeat/winlogbeat.reference.yml | 1 - winlogbeat/winlogbeat.yml | 1 - x-pack/auditbeat/auditbeat.reference.yml | 1 - x-pack/auditbeat/auditbeat.yml | 1 - x-pack/filebeat/filebeat.reference.yml | 1 - x-pack/filebeat/filebeat.yml | 1 - .../functionbeat/functionbeat.reference.yml | 1 - x-pack/functionbeat/functionbeat.yml | 1 - x-pack/metricbeat/metricbeat.reference.yml | 1 - x-pack/metricbeat/metricbeat.yml | 1 - x-pack/winlogbeat/winlogbeat.reference.yml | 1 - x-pack/winlogbeat/winlogbeat.yml | 1 - 33 files changed, 90 insertions(+), 139 deletions(-) rename libbeat/{pipe/listener.go => common/transport/pipelistener.go} (79%) rename libbeat/{pipe/listener_test.go => common/transport/pipelistener_test.go} (93%) rename libbeat/{beat => instrumentation}/instrumentation.go (74%) rename libbeat/{beat => instrumentation}/instrumentation_test.go (70%) delete mode 100644 libbeat/pipe/doc.go diff --git a/auditbeat/auditbeat.reference.yml b/auditbeat/auditbeat.reference.yml index 0b515ba93f9..f075f27639b 100644 --- a/auditbeat/auditbeat.reference.yml +++ b/auditbeat/auditbeat.reference.yml @@ -1493,7 +1493,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/auditbeat/auditbeat.yml b/auditbeat/auditbeat.yml index 7e1e096f1db..916e5da9b5d 100644 --- a/auditbeat/auditbeat.yml +++ b/auditbeat/auditbeat.yml @@ -198,7 +198,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/filebeat/filebeat.reference.yml b/filebeat/filebeat.reference.yml index 0691c5843ab..814d7adf59f 100644 --- a/filebeat/filebeat.reference.yml +++ b/filebeat/filebeat.reference.yml @@ -2206,7 +2206,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/filebeat/filebeat.yml b/filebeat/filebeat.yml index 9654f0158e5..2a3e678c542 100644 --- a/filebeat/filebeat.yml +++ b/filebeat/filebeat.yml @@ -223,7 +223,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/heartbeat/heartbeat.reference.yml b/heartbeat/heartbeat.reference.yml index ec01d9a0af6..3387a60e36d 100644 --- a/heartbeat/heartbeat.reference.yml +++ b/heartbeat/heartbeat.reference.yml @@ -1643,7 +1643,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/heartbeat/heartbeat.yml b/heartbeat/heartbeat.yml index 032e599cd63..367f59d37a9 100644 --- a/heartbeat/heartbeat.yml +++ b/heartbeat/heartbeat.yml @@ -174,7 +174,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/journalbeat/journalbeat.reference.yml b/journalbeat/journalbeat.reference.yml index 643db011b8d..7ac42991b3b 100644 --- a/journalbeat/journalbeat.reference.yml +++ b/journalbeat/journalbeat.reference.yml @@ -1435,7 +1435,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/journalbeat/journalbeat.yml b/journalbeat/journalbeat.yml index 092c8e9c5df..fc92dbc4765 100644 --- a/journalbeat/journalbeat.yml +++ b/journalbeat/journalbeat.yml @@ -199,7 +199,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/libbeat/_meta/config/instrumentation.reference.yml.tmpl b/libbeat/_meta/config/instrumentation.reference.yml.tmpl index 0db13c5bf55..6e960e53161 100644 --- a/libbeat/_meta/config/instrumentation.reference.yml.tmpl +++ b/libbeat/_meta/config/instrumentation.reference.yml.tmpl @@ -9,7 +9,6 @@ #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/libbeat/_meta/config/instrumentation.yml.tmpl b/libbeat/_meta/config/instrumentation.yml.tmpl index 8b9cbc4dd0a..a1a72679b62 100644 --- a/libbeat/_meta/config/instrumentation.yml.tmpl +++ b/libbeat/_meta/config/instrumentation.yml.tmpl @@ -9,7 +9,6 @@ #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/libbeat/beat/beat.go b/libbeat/beat/beat.go index 164b03376b0..9dbc758a425 100644 --- a/libbeat/beat/beat.go +++ b/libbeat/beat/beat.go @@ -19,6 +19,7 @@ package beat import ( "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/beats/v7/libbeat/instrumentation" "github.com/elastic/beats/v7/libbeat/keystore" "github.com/elastic/beats/v7/libbeat/management" ) @@ -70,7 +71,7 @@ type Beat struct { Keystore keystore.Keystore - Instrumentation *Instrumentation // Instrumentation holds an APM agent for capturing and reporting traces + Instrumentation instrumentation.Instrumentation // instrumentation holds an APM agent for capturing and reporting traces } // BeatConfig struct contains the basic configuration of every beat diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 4e7ac663cf2..043b8403b54 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -49,6 +49,7 @@ import ( "github.com/elastic/beats/v7/libbeat/dashboards" "github.com/elastic/beats/v7/libbeat/esleg/eslegclient" "github.com/elastic/beats/v7/libbeat/idxmgmt" + "github.com/elastic/beats/v7/libbeat/instrumentation" "github.com/elastic/beats/v7/libbeat/keystore" "github.com/elastic/beats/v7/libbeat/kibana" "github.com/elastic/beats/v7/libbeat/logp" @@ -336,7 +337,7 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) { Metrics: reg, Telemetry: monitoring.GetNamespace("state").GetRegistry(), Logger: logp.L().Named("publisher"), - Tracer: b.Instrumentation.GetTracer(), + Tracer: b.Instrumentation.Tracer(), }, b.Config.Pipeline, b.processing, @@ -429,7 +430,7 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error { ctx, cancel := context.WithCancel(context.Background()) var stopBeat = func() { - b.Instrumentation.GetTracer().Close() + b.Instrumentation.Tracer().Close() beater.Stop() } svc.HandleSignals(stopBeat, cancel) @@ -588,7 +589,7 @@ func (b *Beat) configure(settings Settings) error { common.OverwriteConfigOpts(configOpts(store)) } - instrumentation, err := beat.CreateInstrumentation(cfg, b.Info) + instrumentation, err := instrumentation.New(cfg, b.Info.Beat, b.Info.Version) if err != nil { return err } diff --git a/libbeat/pipe/listener.go b/libbeat/common/transport/pipelistener.go similarity index 79% rename from libbeat/pipe/listener.go rename to libbeat/common/transport/pipelistener.go index 7d879b4b701..1878930368c 100644 --- a/libbeat/pipe/listener.go +++ b/libbeat/common/transport/pipelistener.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package pipe +package transport import ( "context" @@ -28,17 +28,17 @@ import ( // and DialContext methods of a closed listener. var errListenerClosed = errors.New("listener is closed") -// Listener is a net.Listener that uses net.Pipe +// PipeListener is a net.PipeListener that uses net.Pipe // It is only relevant for the APM Server instrumentation of itself -type Listener struct { +type PipeListener struct { conns chan net.Conn closeOnce sync.Once closed chan struct{} } -// NewListener returns a new Listener. -func NewListener() *Listener { - l := &Listener{ +// NewPipeListener returns a new PipeListener. +func NewPipeListener() *PipeListener { + l := &PipeListener{ conns: make(chan net.Conn), closed: make(chan struct{}), } @@ -46,25 +46,25 @@ func NewListener() *Listener { } // Close closes the listener. -// This is part of the net.Listener interface. -func (l *Listener) Close() error { +// This is part of the net.PipeListener interface. +func (l *PipeListener) Close() error { l.closeOnce.Do(func() { close(l.closed) }) return nil } // Addr returns the listener's network address. -// This is part of the net.Listener interface. +// This is part of the net.listener interface. // // The returned address's network and value are always both // "pipe", the same as the addresses returned by net.Pipe // connections. -func (l *Listener) Addr() net.Addr { +func (l *PipeListener) Addr() net.Addr { return pipeAddr{} } // Accept waits for and returns the next connection to the listener. -// This is part of the net.Listener address. -func (l *Listener) Accept() (net.Conn, error) { +// This is part of the net.listener address. +func (l *PipeListener) Accept() (net.Conn, error) { select { case <-l.closed: return nil, errListenerClosed @@ -76,7 +76,7 @@ func (l *Listener) Accept() (net.Conn, error) { // DialContext dials a connection to the listener, blocking until // a paired Accept call is made, the listener is closed, or the // context is canceled/expired. -func (l *Listener) DialContext(ctx context.Context, network, addr string) (net.Conn, error) { +func (l *PipeListener) DialContext(ctx context.Context, network, addr string) (net.Conn, error) { client, server := net.Pipe() select { case <-l.closed: diff --git a/libbeat/pipe/listener_test.go b/libbeat/common/transport/pipelistener_test.go similarity index 93% rename from libbeat/pipe/listener_test.go rename to libbeat/common/transport/pipelistener_test.go index 592ddf57bc1..744dae9d495 100644 --- a/libbeat/pipe/listener_test.go +++ b/libbeat/common/transport/pipelistener_test.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package pipe +package transport import ( "context" @@ -26,14 +26,14 @@ import ( ) func TestNew(t *testing.T) { - l := NewListener() + l := NewPipeListener() assert.NotNil(t, l) defer l.Close() assert.Implements(t, new(net.Listener), l) } func TestAddr(t *testing.T) { - l := NewListener() + l := NewPipeListener() assert.NotNil(t, l) defer l.Close() @@ -44,7 +44,7 @@ func TestAddr(t *testing.T) { } func TestDialAccept(t *testing.T) { - l := NewListener() + l := NewPipeListener() assert.NotNil(t, l) defer l.Close() @@ -72,7 +72,7 @@ func TestDialAccept(t *testing.T) { } func TestAcceptClosed(t *testing.T) { - l := NewListener() + l := NewPipeListener() assert.NotNil(t, l) defer l.Close() @@ -83,7 +83,7 @@ func TestAcceptClosed(t *testing.T) { } func TestDialClosed(t *testing.T) { - l := NewListener() + l := NewPipeListener() assert.NotNil(t, l) defer l.Close() @@ -94,7 +94,7 @@ func TestDialClosed(t *testing.T) { } func TestDialContextCanceled(t *testing.T) { - l := NewListener() + l := NewPipeListener() assert.NotNil(t, l) defer l.Close() diff --git a/libbeat/beat/instrumentation.go b/libbeat/instrumentation/instrumentation.go similarity index 74% rename from libbeat/beat/instrumentation.go rename to libbeat/instrumentation/instrumentation.go index fb2edc0d3f4..980d5a5531f 100644 --- a/libbeat/beat/instrumentation.go +++ b/libbeat/instrumentation/instrumentation.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package beat +package instrumentation import ( "fmt" @@ -26,11 +26,11 @@ import ( "time" "go.elastic.co/apm" - "go.elastic.co/apm/transport" + apmtransport "go.elastic.co/apm/transport" "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/beats/v7/libbeat/common/transport" "github.com/elastic/beats/v7/libbeat/logp" - "github.com/elastic/beats/v7/libbeat/pipe" ) func init() { @@ -38,25 +38,34 @@ func init() { apm.DefaultTracer.Close() } -// Instrumentation holds an APM tracer a net.Listener -type Instrumentation struct { - tracer *apm.Tracer - // Listener is only relevant for APM Server sending tracing data to itself - // APM Server needs this Listener to create an ad-hoc tracing server - Listener net.Listener +// Instrumentation is an interface that can return an APM tracer a net.listener +type Instrumentation interface { + Tracer() *apm.Tracer + Listener() net.Listener } -// GetTracer returns the configured tracer +type instrumentation struct { + tracer *apm.Tracer + listener net.Listener +} + +// Tracer returns the configured tracer // If there is not configured tracer, it returns the DefaultTracer, which is always disabled -func (t *Instrumentation) GetTracer() *apm.Tracer { - if t == nil || t.tracer == nil { +func (t *instrumentation) Tracer() *apm.Tracer { + if t.tracer == nil { return apm.DefaultTracer } return t.tracer } -// InstrumentationConfig holds config information about self instrumenting the APM Server -type InstrumentationConfig struct { +// Listener is only relevant for APM Server sending tracing data to itself +// APM Server needs this listener to create an ad-hoc tracing server +func (t *instrumentation) Listener() net.Listener { + return t.listener +} + +// Config holds config information about self instrumenting the APM Server +type Config struct { Enabled *bool `config:"enabled"` Environment *string `config:"environment"` Hosts urls `config:"hosts"` @@ -107,7 +116,7 @@ type CPUProfiling struct { } // IsEnabled indicates whether instrumentation is enabled -func (c *InstrumentationConfig) IsEnabled() bool { +func (c *Config) IsEnabled() bool { return c != nil && c.Enabled != nil && *c.Enabled } @@ -127,32 +136,32 @@ type HeapProfiling struct { Interval time.Duration `config:"interval" validate:"positive"` } -// CreateInstrumentation configures and returns an instrumentation object for tracing -func CreateInstrumentation(cfg *common.Config, info Info) (*Instrumentation, error) { +// New configures and returns an instrumentation object for tracing +func New(cfg *common.Config, beatName, beatVersion string) (Instrumentation, error) { if !cfg.HasField("instrumentation") { - return nil, nil + return &instrumentation{}, nil } - instrumentation, err := cfg.Child("instrumentation", -1) + instrConfig, err := cfg.Child("instrumentation", -1) if err != nil { - return nil, nil + return &instrumentation{}, nil } - config := InstrumentationConfig{} + config := Config{} - if instrumentation == nil { - instrumentation = common.NewConfig() + if instrConfig == nil { + instrConfig = common.NewConfig() } - err = instrumentation.Unpack(&config) + err = instrConfig.Unpack(&config) if err != nil { return nil, fmt.Errorf("could not create tracer, err: %v", err) } - return initTracer(config, info) + return initTracer(config, beatName, beatVersion) } -func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) { +func initTracer(cfg Config, beatName, beatVersion string) (*instrumentation, error) { logger := logp.NewLogger("tracing") @@ -178,12 +187,12 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) os.Setenv("ELASTIC_APM_HEAP_PROFILE_INTERVAL", fmt.Sprintf("%dms", int(interval.Seconds()*1000))) } - var tracerTransport transport.Transport + var tracerTransport apmtransport.Transport var tracerListener net.Listener - if cfg.Hosts == nil && info.Name == "apm-server" { - pipeListener := pipe.NewListener() - pipeTransport, err := transport.NewHTTPTransport() + if cfg.Hosts == nil { + pipeListener := transport.NewPipeListener() + pipeTransport, err := apmtransport.NewHTTPTransport() if err != nil { return nil, err } @@ -198,25 +207,19 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) tracerListener = pipeListener } else { - t, err := transport.NewHTTPTransport() + t, err := apmtransport.NewHTTPTransport() if err != nil { return nil, err } - hosts := cfg.Hosts - if hosts == nil { - hosts = []*url.URL{{ - Scheme: "http", - Host: "localhost:8200", - }} + if len(cfg.Hosts) > 0 { + t.SetServerURL(cfg.Hosts...) } - t.SetServerURL(hosts...) if cfg.APIKey != "" { t.SetAPIKey(cfg.APIKey) } else { t.SetSecretToken(cfg.SecretToken) } tracerTransport = t - logger.Infof("APM tracer directed to %s", hosts) } var environment string @@ -224,8 +227,8 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) environment = *cfg.Environment } tracer, err := apm.NewTracerOptions(apm.TracerOptions{ - ServiceName: info.Beat, - ServiceVersion: info.Version, + ServiceName: beatName, + ServiceVersion: beatVersion, ServiceEnvironment: environment, Transport: tracerTransport, }) @@ -234,8 +237,8 @@ func initTracer(cfg InstrumentationConfig, info Info) (*Instrumentation, error) } tracer.SetLogger(logger) - return &Instrumentation{ + return &instrumentation{ tracer: tracer, - Listener: tracerListener, + listener: tracerListener, }, nil } diff --git a/libbeat/beat/instrumentation_test.go b/libbeat/instrumentation/instrumentation_test.go similarity index 70% rename from libbeat/beat/instrumentation_test.go rename to libbeat/instrumentation/instrumentation_test.go index af03afaffbe..8856f2d1fb6 100644 --- a/libbeat/beat/instrumentation_test.go +++ b/libbeat/instrumentation/instrumentation_test.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package beat +package instrumentation import ( "testing" @@ -27,34 +27,19 @@ import ( "github.com/elastic/beats/v7/libbeat/version" ) -func TestAPMTracerDisabledByDefault(t *testing.T) { - b := Beat{ - Info: Info{ - Beat: "my-beat", - IndexPrefix: "my-beat-*", - Version: version.GetDefaultVersion(), - Name: "my-beat", - }, - } - tracer := b.Instrumentation.GetTracer() - require.NotNil(t, tracer) - defer tracer.Close() - assert.False(t, tracer.Active()) -} - func TestInstrumentationConfig(t *testing.T) { cfg := common.MustNewConfigFrom(map[string]interface{}{ "instrumentation": map[string]interface{}{ "enabled": "true", }, }) - instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) + instrumentation, err := New(cfg, "my-beat", version.GetDefaultVersion()) require.NoError(t, err) - tracer := instrumentation.GetTracer() + tracer := instrumentation.Tracer() defer tracer.Close() assert.True(t, tracer.Active()) - assert.Nil(t, instrumentation.Listener) + assert.NotNil(t, instrumentation.Listener()) } func TestInstrumentationConfigExplicitHosts(t *testing.T) { @@ -65,12 +50,12 @@ func TestInstrumentationConfigExplicitHosts(t *testing.T) { }, }, ) - instrumentation, err := CreateInstrumentation(cfg, Info{Name: "my-beat", Version: version.GetDefaultVersion()}) + instrumentation, err := New(cfg, "my-beat", version.GetDefaultVersion()) require.NoError(t, err) - tracer := instrumentation.GetTracer() + tracer := instrumentation.Tracer() defer tracer.Close() assert.True(t, tracer.Active()) - assert.Nil(t, instrumentation.Listener) + assert.Nil(t, instrumentation.Listener()) } func TestInstrumentationConfigListener(t *testing.T) { @@ -79,11 +64,19 @@ func TestInstrumentationConfigListener(t *testing.T) { "enabled": "true", }, }) - instrumentation, err := CreateInstrumentation(cfg, Info{Name: "apm-server", Version: version.GetDefaultVersion()}) + instrumentation, err := New(cfg, "apm-server", version.GetDefaultVersion()) require.NoError(t, err) - tracer := instrumentation.GetTracer() + tracer := instrumentation.Tracer() defer tracer.Close() assert.True(t, tracer.Active()) - assert.NotNil(t, instrumentation.Listener) + assert.NotNil(t, instrumentation.Listener()) +} + +func TestAPMTracerDisabledByDefault(t *testing.T) { + instrumentation, err := New(common.NewConfig(), "beat", "8.0") + require.NoError(t, err) + tracer := instrumentation.Tracer() + require.NotNil(t, tracer) + assert.False(t, tracer.Active()) } diff --git a/libbeat/pipe/doc.go b/libbeat/pipe/doc.go deleted file mode 100644 index f26f6cbf625..00000000000 --- a/libbeat/pipe/doc.go +++ /dev/null @@ -1,21 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -// Package pipe provides a net.Listener using net.Conn, -// for in-process communication. - -package pipe diff --git a/metricbeat/metricbeat.reference.yml b/metricbeat/metricbeat.reference.yml index 5023b176a5f..c0160d0a818 100644 --- a/metricbeat/metricbeat.reference.yml +++ b/metricbeat/metricbeat.reference.yml @@ -2259,7 +2259,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/metricbeat/metricbeat.yml b/metricbeat/metricbeat.yml index 84558a2a25f..65c682f66af 100644 --- a/metricbeat/metricbeat.yml +++ b/metricbeat/metricbeat.yml @@ -171,7 +171,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/packetbeat/packetbeat.reference.yml b/packetbeat/packetbeat.reference.yml index eaca0280195..4093b9db371 100644 --- a/packetbeat/packetbeat.reference.yml +++ b/packetbeat/packetbeat.reference.yml @@ -1919,7 +1919,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/packetbeat/packetbeat.yml b/packetbeat/packetbeat.yml index c8287c1941a..c162650c6a1 100644 --- a/packetbeat/packetbeat.yml +++ b/packetbeat/packetbeat.yml @@ -251,7 +251,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/winlogbeat/winlogbeat.reference.yml b/winlogbeat/winlogbeat.reference.yml index 2441e5a54ec..aa8b7893d8a 100644 --- a/winlogbeat/winlogbeat.reference.yml +++ b/winlogbeat/winlogbeat.reference.yml @@ -1415,7 +1415,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/winlogbeat/winlogbeat.yml b/winlogbeat/winlogbeat.yml index f9a07d7f4ce..41f7e2b01c9 100644 --- a/winlogbeat/winlogbeat.yml +++ b/winlogbeat/winlogbeat.yml @@ -182,7 +182,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/auditbeat/auditbeat.reference.yml b/x-pack/auditbeat/auditbeat.reference.yml index 42fb63e92e4..9bb714069f7 100644 --- a/x-pack/auditbeat/auditbeat.reference.yml +++ b/x-pack/auditbeat/auditbeat.reference.yml @@ -1549,7 +1549,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/auditbeat/auditbeat.yml b/x-pack/auditbeat/auditbeat.yml index 4f319db36f5..e8f11e4bad1 100644 --- a/x-pack/auditbeat/auditbeat.yml +++ b/x-pack/auditbeat/auditbeat.yml @@ -225,7 +225,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/filebeat/filebeat.reference.yml b/x-pack/filebeat/filebeat.reference.yml index 7609e0ff34c..ed32b278afe 100644 --- a/x-pack/filebeat/filebeat.reference.yml +++ b/x-pack/filebeat/filebeat.reference.yml @@ -2947,7 +2947,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/filebeat/filebeat.yml b/x-pack/filebeat/filebeat.yml index 9654f0158e5..2a3e678c542 100644 --- a/x-pack/filebeat/filebeat.yml +++ b/x-pack/filebeat/filebeat.yml @@ -223,7 +223,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/functionbeat/functionbeat.reference.yml b/x-pack/functionbeat/functionbeat.reference.yml index 3111cba3da7..a2a3650d9b2 100644 --- a/x-pack/functionbeat/functionbeat.reference.yml +++ b/x-pack/functionbeat/functionbeat.reference.yml @@ -1407,7 +1407,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/functionbeat/functionbeat.yml b/x-pack/functionbeat/functionbeat.yml index df8d499cabb..ed637679c85 100644 --- a/x-pack/functionbeat/functionbeat.yml +++ b/x-pack/functionbeat/functionbeat.yml @@ -487,7 +487,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/metricbeat/metricbeat.reference.yml b/x-pack/metricbeat/metricbeat.reference.yml index 60f5fa99980..cfd85f0d5fe 100644 --- a/x-pack/metricbeat/metricbeat.reference.yml +++ b/x-pack/metricbeat/metricbeat.reference.yml @@ -2691,7 +2691,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/metricbeat/metricbeat.yml b/x-pack/metricbeat/metricbeat.yml index 84558a2a25f..65c682f66af 100644 --- a/x-pack/metricbeat/metricbeat.yml +++ b/x-pack/metricbeat/metricbeat.yml @@ -171,7 +171,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/winlogbeat/winlogbeat.reference.yml b/x-pack/winlogbeat/winlogbeat.reference.yml index 3c66e055456..c856ab060a2 100644 --- a/x-pack/winlogbeat/winlogbeat.reference.yml +++ b/x-pack/winlogbeat/winlogbeat.reference.yml @@ -1458,7 +1458,6 @@ logging.files: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 diff --git a/x-pack/winlogbeat/winlogbeat.yml b/x-pack/winlogbeat/winlogbeat.yml index 265ae400c2e..d8a1681dae9 100644 --- a/x-pack/winlogbeat/winlogbeat.yml +++ b/x-pack/winlogbeat/winlogbeat.yml @@ -225,7 +225,6 @@ processors: #environment: "" # APM Server hosts to report instrumentation results to. - # For APM Server to send traces to itself, leave hosts empty. #hosts: # - http://localhost:8200 From 7344fd110f603670504dd4e69a0848074f3b7a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Thu, 11 Jun 2020 14:06:51 +0200 Subject: [PATCH 12/13] Fix string --- libbeat/cmd/instance/beat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 27b1fa455c9..667bd137faa 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -100,7 +100,7 @@ type beatConfig struct { Logging *common.Config `config:"logging"` MetricLogging *common.Config `config:"logging.metrics"` Keystore *common.Config `config:"keystore"` - Instrumentation *common.Config `config:"pipe"` + Instrumentation *common.Config `config:"instrumentation"` // output/publishing related configurations Pipeline pipeline.Config `config:",inline"` From 00047a2b8cee7653f99f26206ede62ba06e1865e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Mon, 15 Jun 2020 15:15:24 +0200 Subject: [PATCH 13/13] code review --- libbeat/cmd/instance/beat.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 667bd137faa..f2f6545091f 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -95,12 +95,12 @@ type beatConfig struct { Seccomp *common.Config `config:"seccomp"` // beat internal components configurations - HTTP *common.Config `config:"http"` - Path paths.Path `config:"path"` - Logging *common.Config `config:"logging"` - MetricLogging *common.Config `config:"logging.metrics"` - Keystore *common.Config `config:"keystore"` - Instrumentation *common.Config `config:"instrumentation"` + HTTP *common.Config `config:"http"` + Path paths.Path `config:"path"` + Logging *common.Config `config:"logging"` + MetricLogging *common.Config `config:"logging.metrics"` + Keystore *common.Config `config:"keystore"` + Instrumentation instrumentation.Config `config:"instrumentation"` // output/publishing related configurations Pipeline pipeline.Config `config:",inline"`