From f380cf3386b41ba1a34f9f0419831e35db454263 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Fri, 2 Jun 2023 08:25:56 +0930 Subject: [PATCH] libbeat/monitoring/inputmon: log key, id and input type when registering/deregistering metrics This notes under "metric_registry" all inputmon-handled metric registration and deregistration, linking register and deregister operations by use of a unique ID unrelated to the request. --- CHANGELOG-developer.next.asciidoc | 1 + libbeat/monitoring/inputmon/input.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 5d009736c34..ae799e2592a 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -154,6 +154,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only. - Add the file path of the instance lock on the error when it's is already locked {pull}33788[33788] - Add DropFields processor to js API {pull}33458[33458] - Add support for different folders when testing data {pull}34467[34467] +- Add logging of metric registration in inputmon. {pull}35647[35647] ==== Deprecated diff --git a/libbeat/monitoring/inputmon/input.go b/libbeat/monitoring/inputmon/input.go index 51c79fc3501..39d51d94cbe 100644 --- a/libbeat/monitoring/inputmon/input.go +++ b/libbeat/monitoring/inputmon/input.go @@ -20,6 +20,9 @@ package inputmon import ( "strings" + "github.com/google/uuid" + + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/monitoring" ) @@ -49,11 +52,23 @@ func NewInputRegistry(inputType, id string, optionalParent *monitoring.Registry) // the monitoring registry, and we want a consistent flat level of nesting key := sanitizeID(id) + // Log the registration to ease tracking down duplicate ID registrations. + // Logged at INFO rather than DEBUG since it is not in a hot path and having + // the information available by default can short-circuit requests for debug + // logs during support interactions. + log := logp.NewLogger("metric_registry") + // Make an orthogonal ID to allow tracking register/deregister pairs. + uuid := uuid.New().String() + log.Infow("registering", "input_type", inputType, "id", id, "key", key, "uuid", uuid) + reg = parentRegistry.NewRegistry(key) monitoring.NewString(reg, "input").Set(inputType) monitoring.NewString(reg, "id").Set(id) - return reg, func() { parentRegistry.Remove(key) } + return reg, func() { + log.Infow("unregistering", "input_type", inputType, "id", id, "key", key, "uuid", uuid) + parentRegistry.Remove(key) + } } func sanitizeID(id string) string {