From 4a850eddd3acc5c73c1baf827c85c192de5bc5e9 Mon Sep 17 00:00:00 2001 From: Gil Raphaelli Date: Wed, 9 Jun 2021 09:05:40 -0400 Subject: [PATCH] libbeat: monitor version (#26214) (cherry picked from commit 383f689855086910652fe1ab69d529865cf515e9) --- CHANGELOG.next.asciidoc | 1 + .../cmd/instance/metrics/metrics_common.go | 2 ++ .../instance/metrics/metrics_common_test.go | 33 +++++++++++++++++++ libbeat/monitoring/report/log/log.go | 1 + 4 files changed, 37 insertions(+) create mode 100644 libbeat/cmd/instance/metrics/metrics_common_test.go diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index ebe763c9a1f..81eca3ec8c3 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -437,6 +437,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Add new option `suffix` to `logging.files` to control how log files are rotated. {pull}25464[25464] - Validate that required functionality in Elasticsearch is available upon initial connection. {pull}25351[25351] - Improve ES output error insights. {pull}25825[25825] +- Libbeat: report beat version to monitoring. {pull}26214[26214] *Auditbeat* diff --git a/libbeat/cmd/instance/metrics/metrics_common.go b/libbeat/cmd/instance/metrics/metrics_common.go index f9a4a2866c1..1f76aa71c6a 100644 --- a/libbeat/cmd/instance/metrics/metrics_common.go +++ b/libbeat/cmd/instance/metrics/metrics_common.go @@ -25,6 +25,7 @@ import ( "github.com/elastic/beats/v7/libbeat/logp" "github.com/elastic/beats/v7/libbeat/monitoring" "github.com/elastic/beats/v7/libbeat/monitoring/report/log" + "github.com/elastic/beats/v7/libbeat/version" ) var ( @@ -59,4 +60,5 @@ func reportInfo(_ monitoring.Mode, V monitoring.Visitor) { }) monitoring.ReportString(V, "ephemeral_id", ephemeralID.String()) + monitoring.ReportString(V, "version", version.GetDefaultVersion()) } diff --git a/libbeat/cmd/instance/metrics/metrics_common_test.go b/libbeat/cmd/instance/metrics/metrics_common_test.go new file mode 100644 index 00000000000..d5c6ce59132 --- /dev/null +++ b/libbeat/cmd/instance/metrics/metrics_common_test.go @@ -0,0 +1,33 @@ +// 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 metrics + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/elastic/beats/v7/libbeat/monitoring" + "github.com/elastic/beats/v7/libbeat/version" +) + +func TestMonitoring(t *testing.T) { + metrics := monitoring.Default.GetRegistry("beat") + metricsSnapshot := monitoring.CollectFlatSnapshot(metrics, monitoring.Full, true) + assert.Equal(t, version.GetDefaultVersion(), metricsSnapshot.Strings["info.version"]) +} diff --git a/libbeat/monitoring/report/log/log.go b/libbeat/monitoring/report/log/log.go index 2139f7cf978..f05214cd932 100644 --- a/libbeat/monitoring/report/log/log.go +++ b/libbeat/monitoring/report/log/log.go @@ -66,6 +66,7 @@ var gauges = map[string]bool{ // TODO: Change this when gauges are refactored, too. var strConsts = map[string]bool{ "beat.info.ephemeral_id": true, + "beat.info.version": true, } var (