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

fix: do not overwrite registries when publishing otel metrics to beats #15517

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
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
36 changes: 28 additions & 8 deletions internal/beatcmd/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,21 +573,41 @@ func getScalarInt64(data metricdata.Aggregation) (int64, bool) {
}

func addAPMServerMetrics(v monitoring.Visitor, sm metricdata.ScopeMetrics) {
beatsMetrics := make(map[string]any)
for _, m := range sm.Metrics {
if suffix, ok := strings.CutPrefix(m.Name, "apm-server."); ok {
if value, ok := getScalarInt64(m.Data); ok {
keys := strings.Split(suffix, ".")
for i := 0; i < len(keys)-1; i++ {
v.OnRegistryStart()
v.OnKey(keys[i])
}
monitoring.ReportInt(v, keys[len(keys)-1], value)
for i := 0; i < len(keys)-1; i++ {
v.OnRegistryFinished()
current := beatsMetrics
suffixSlice := strings.Split(suffix, ".")
for i := 0; i < len(suffixSlice)-1; i++ {
k := suffixSlice[i]
if _, ok := current[k]; !ok {
current[k] = make(map[string]any)
}
if currentmap, ok := current[k].(map[string]any); ok {
current = currentmap
}
}
current[suffixSlice[len(suffixSlice)-1]] = value
}
}
}

reportOnKey(v, beatsMetrics)
}

func reportOnKey(v monitoring.Visitor, m map[string]any) {
for key, value := range m {
if valueMap, ok := value.(map[string]any); ok {
v.OnRegistryStart()
v.OnKey(key)
reportOnKey(v, valueMap)
v.OnRegistryFinished()
}
if valueMetric, ok := value.(int64); ok {
monitoring.ReportInt(v, key, valueMetric)
}
}
}

// Adapt go-docappender's OTel metrics to beats stack monitoring metrics,
Expand Down
Loading