Skip to content

Commit

Permalink
Add component.{id, binary} to monitoring metrics
Browse files Browse the repository at this point in the history
This commit adds `component.id` and `component.binary` to the
monitoring metrics, those fields are necessary to create unique TSDB
entries.
  • Loading branch information
belimawr committed Oct 19, 2023
1 parent 9196320 commit 9b230de
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: feature

# Change summary; a 80ish characters long description of the change.
summary: Add component.{id, binary} to monitoring metrics from Elastic-Agent and Beats

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: elastic-agent

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
pr: https://github.com/elastic/elastic-agent/pull/3626

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
issue: https://github.com/elastic/integrations/issues/7977
51 changes: 48 additions & 3 deletions internal/pkg/agent/application/monitoring/v1_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,15 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
"ignore_missing": true,
},
},
map[string]interface{}{
"add_fields": map[string]interface{}{
"target": "component",
"fields": map[string]interface{}{
"id": "elastic-agent",
"binary": "elastic-agent",
},
},
},
},
},
}
Expand Down Expand Up @@ -655,6 +664,15 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
},
},
},
map[string]interface{}{
"add_fields": map[string]interface{}{
"target": "component",
"fields": map[string]interface{}{
"id": unit,
"binary": binaryName,
},
},
},
},
})
}
Expand Down Expand Up @@ -715,6 +733,15 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
"ignore_missing": true,
},
},
map[string]interface{}{
"add_fields": map[string]interface{}{
"target": "component",
"fields": map[string]interface{}{
"id": unit,
"binary": binaryName,
},
},
},
},
})

Expand Down Expand Up @@ -777,6 +804,15 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
"ignore_missing": true,
},
},
map[string]interface{}{
"add_fields": map[string]interface{}{
"target": "component",
"fields": map[string]interface{}{
"id": unit,
"binary": binaryName,
},
},
},
},
})
}
Expand Down Expand Up @@ -807,7 +843,7 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
"hosts": endpoints,
"namespace": "application",
"period": metricsCollectionIntervalString,
"processors": createProcessorsForJSONInput(name, monitoringNamespace, b.agentInfo),
"processors": createProcessorsForJSONInput(name, comp.ID, monitoringNamespace, b.agentInfo),
},
map[string]interface{}{
idKey: "metrics-monitoring-shipper-stats",
Expand All @@ -821,7 +857,7 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
"hosts": endpoints,
"namespace": "agent",
"period": metricsCollectionIntervalString,
"processors": createProcessorsForJSONInput(name, monitoringNamespace, b.agentInfo),
"processors": createProcessorsForJSONInput(name, comp.ID, monitoringNamespace, b.agentInfo),
})
}
}
Expand Down Expand Up @@ -878,7 +914,7 @@ func (b *BeatsMonitor) injectMetricsInput(cfg map[string]interface{}, componentI
return nil
}

func createProcessorsForJSONInput(name string, monitoringNamespace string, agentInfo *info.AgentInfo) []interface{} {
func createProcessorsForJSONInput(name string, compID, monitoringNamespace string, agentInfo *info.AgentInfo) []interface{} {
return []interface{}{
map[string]interface{}{
"add_fields": map[string]interface{}{
Expand Down Expand Up @@ -932,6 +968,15 @@ func createProcessorsForJSONInput(name string, monitoringNamespace string, agent
"ignore_missing": true,
},
},
map[string]interface{}{
"add_fields": map[string]interface{}{
"target": "component",
"fields": map[string]interface{}{
"id": compID,
"binary": name,
},
},
},
}
}

Expand Down

0 comments on commit 9b230de

Please sign in to comment.