From 629b379e72083d740f374837a41a5cb84caa4424 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Fri, 12 Jun 2020 12:47:54 -0400 Subject: [PATCH 1/2] Fix unused libbeat.config.module metrics These metrics existed in the code but were unused and hence always 0. "libbeat":{"config":{"module":{"running":0,"starts":0,"stops":0} I updated the module reload code to increment and set the metrics when changes are applied. --- CHANGELOG.next.asciidoc | 1 + libbeat/cfgfile/list.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 72a24160d8a..7872c437797 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -128,6 +128,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - The `monitoring.elasticsearch.api_key` value is correctly base64-encoded before being sent to the monitoring Elasticsearch cluster. {issue}18939[18939] {pull}18945[18945] - Fix kafka topic setting not allowing upper case characters. {pull}18854[18854] {issue}18640[18640] - Fix redis key setting not allowing upper case characters. {pull}18854[18854] {issue}18640[18640] +- Fix config reload metrics (`libbeat.config.module.start/stops/running`). {pull}19168[19168] *Auditbeat* diff --git a/libbeat/cfgfile/list.go b/libbeat/cfgfile/list.go index 975dcee1c28..4d441a2db47 100644 --- a/libbeat/cfgfile/list.go +++ b/libbeat/cfgfile/list.go @@ -84,6 +84,7 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error { r.logger.Debugf("Stopping runner: %s", runner) delete(r.runners, hash) go runner.Stop() + moduleStops.Add(1) } // Start new runners @@ -101,8 +102,11 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error { r.logger.Debugf("Starting runner: %s", runner) r.runners[hash] = runner runner.Start() + moduleStarts.Add(1) } + moduleRunning.Set(int64(len(r.runners))) + return errs.Err() } From b74ae1529cd91614dd2b0c659f58b99f1fdafe48 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Mon, 15 Jun 2020 19:12:59 -0400 Subject: [PATCH 2/2] Add comments about libbeat.config.module.running --- libbeat/cfgfile/list.go | 4 ++++ libbeat/cfgfile/reload.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libbeat/cfgfile/list.go b/libbeat/cfgfile/list.go index 4d441a2db47..41f0ad7ab77 100644 --- a/libbeat/cfgfile/list.go +++ b/libbeat/cfgfile/list.go @@ -105,6 +105,10 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error { moduleStarts.Add(1) } + // NOTE: This metric tracks the number of modules in the list. The true + // number of modules in the running state may differ because modules can + // stop on their own (i.e. on errors) and also when this stops a module + // above it is done asynchronously. moduleRunning.Set(int64(len(r.runners))) return errs.Err() diff --git a/libbeat/cfgfile/reload.go b/libbeat/cfgfile/reload.go index d5b9d9c315f..b4458e543b0 100644 --- a/libbeat/cfgfile/reload.go +++ b/libbeat/cfgfile/reload.go @@ -52,7 +52,7 @@ var ( configReloads = monitoring.NewInt(nil, "libbeat.config.reloads") moduleStarts = monitoring.NewInt(nil, "libbeat.config.module.starts") moduleStops = monitoring.NewInt(nil, "libbeat.config.module.stops") - moduleRunning = monitoring.NewInt(nil, "libbeat.config.module.running") + moduleRunning = monitoring.NewInt(nil, "libbeat.config.module.running") // Number of modules in the runner list (not necessarily in the running state). ) // DynamicConfig loads config files from a given path, allowing to reload new changes