From 9b230de65f920dfc3d2fbbd9a96c28af1a52da40 Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Wed, 18 Oct 2023 15:20:22 +0200 Subject: [PATCH] Add component.{id, binary} to monitoring metrics This commit adds `component.id` and `component.binary` to the monitoring metrics, those fields are necessary to create unique TSDB entries. --- ...35373-Add-component-fields-to-metrics.yaml | 32 ++++++++++++ .../application/monitoring/v1_monitor.go | 51 +++++++++++++++++-- 2 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 changelog/fragments/1697735373-Add-component-fields-to-metrics.yaml diff --git a/changelog/fragments/1697735373-Add-component-fields-to-metrics.yaml b/changelog/fragments/1697735373-Add-component-fields-to-metrics.yaml new file mode 100644 index 00000000000..780093d1434 --- /dev/null +++ b/changelog/fragments/1697735373-Add-component-fields-to-metrics.yaml @@ -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 diff --git a/internal/pkg/agent/application/monitoring/v1_monitor.go b/internal/pkg/agent/application/monitoring/v1_monitor.go index 79522096b8c..1b60fcfb679 100644 --- a/internal/pkg/agent/application/monitoring/v1_monitor.go +++ b/internal/pkg/agent/application/monitoring/v1_monitor.go @@ -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", + }, + }, + }, }, }, } @@ -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, + }, + }, + }, }, }) } @@ -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, + }, + }, + }, }, }) @@ -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, + }, + }, + }, }, }) } @@ -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", @@ -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), }) } } @@ -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{}{ @@ -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, + }, + }, + }, } }