Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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