Skip to content

Commit

Permalink
Remove unnecessary check for a cfg'd ES output. (#33950) (#33989)
Browse files Browse the repository at this point in the history
Remove the check for a configured Elasticsearch output when setting up
global Elasticsearch connection callbacks.

When a Beat is started under the V2 agent, it no longer has or reads the
default configuration file that configures an Elasticsearch output on
localhost. This has the consequence that the global "OnConnect"
Elasticsearch callbacks never get registered, one of which fetches the
cluster UUID which is a dependency of the Metricbeat beat monitoring
module used by agent. In V2 the initial output configuration is sent
sometime after startup via the control protocol.

Since the callbacks here are just added to a global map of functions to
invoke when connecting to Elasticsearch, there is actually no reason to
guard them with a check for an Elasticsearch output. Bypass that to
restore beat metrics collection under agent.

I looked for other similar uses of b.Config access that assume a
configuration file is available immediately when the Beat, and while
there are a few they don't seem like they apply to running under agent.
The Beats historically were able to assume they were loading a
configuration file from disk, which doesn't apply anymore.

(cherry picked from commit 76ea65f)

Co-authored-by: Craig MacKenzie <[email protected]>
  • Loading branch information
2 people authored and chrisberkhout committed Jun 1, 2023
1 parent e014d09 commit e8c4684
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func (b *Beat) loadDashboards(ctx context.Context, force bool) error {
// to is at least on the same version as the Beat.
// If the check is disabled or the output is not Elasticsearch, nothing happens.
func (b *Beat) checkElasticsearchVersion() {
if !isElasticsearchOutput(b.Config.Output.Name()) || b.isConnectionToOlderVersionAllowed() {
if b.isConnectionToOlderVersionAllowed() {
return
}

Expand Down Expand Up @@ -931,7 +931,7 @@ func (b *Beat) isConnectionToOlderVersionAllowed() bool {
// policy as a callback with the elasticsearch output. It is important the
// registration happens before the publisher is created.
func (b *Beat) registerESIndexManagement() error {
if !isElasticsearchOutput(b.Config.Output.Name()) || !b.IdxSupporter.Enabled() {
if !b.IdxSupporter.Enabled() {
return nil
}

Expand Down Expand Up @@ -978,10 +978,8 @@ func (b *Beat) createOutput(stats outputs.Observer, cfg config.Namespace) (outpu
}

func (b *Beat) registerClusterUUIDFetching() {
if isElasticsearchOutput(b.Config.Output.Name()) {
callback := b.clusterUUIDFetchingCallback()
_, _ = elasticsearch.RegisterConnectCallback(callback)
}
callback := b.clusterUUIDFetchingCallback()
_, _ = elasticsearch.RegisterConnectCallback(callback)
}

// Build and return a callback to fetch the Elasticsearch cluster_uuid for monitoring
Expand Down

0 comments on commit e8c4684

Please sign in to comment.