Skip to content

Commit

Permalink
[8.8](backport #35647) libbeat/monitoring/inputmon: log key, id and i…
Browse files Browse the repository at this point in the history
…nput type when registering/deregistering metrics (#35673)

* libbeat/monitoring/inputmon: log key, id and input type when registering/deregistering metrics (#35647)

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.

(cherry picked from commit 8abdf32)

# Conflicts:
#	libbeat/monitoring/inputmon/input.go

* resolve conflicts

---------

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
  • Loading branch information
3 people authored Jun 5, 2023
1 parent 6cd30a5 commit 9fbb486
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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

Expand Down
17 changes: 16 additions & 1 deletion libbeat/monitoring/inputmon/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -40,11 +43,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 = rootRegistry.NewRegistry(key)
monitoring.NewString(reg, "input").Set(inputType)
monitoring.NewString(reg, "id").Set(id)

return reg, func() { rootRegistry.Remove(key) }
return reg, func() {
log.Infow("unregistering", "input_type", inputType, "id", id, "key", key, "uuid", uuid)
rootRegistry.Remove(key)
}
}

func sanitizeID(id string) string {
Expand Down

0 comments on commit 9fbb486

Please sign in to comment.