From ff20b95a61fa5a5e80e572875f7015e5b0b93d20 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. --- .../application/monitoring/v1_monitor.go | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) 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, + }, + }, + }, } }