Skip to content

Commit

Permalink
libbeat/monitoring/inputmon: log key, id and input type when register…
Browse files Browse the repository at this point in the history
…ing/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.
  • Loading branch information
efd6 committed Jun 1, 2023
1 parent f32bc48 commit f380cf3
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 @@ -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

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 Down Expand Up @@ -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 {
Expand Down

0 comments on commit f380cf3

Please sign in to comment.