From c82a1226858489b4ffe561a66337268aa0607d98 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Mon, 17 Jan 2022 11:23:52 +0100 Subject: [PATCH 1/6] Fix panic in prom_sd_processor when address is empty --- CHANGELOG.md | 2 ++ pkg/traces/promsdprocessor/prom_sd_processor.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a76d3b0770..270afc8c55fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ WAL loading while old WALs are being deleted or the `/agent/api/v1/targets` endpoint is called. (@tpaschalis) +- [BUGFIX] Fix panic in prom_sd_processor when address is empty (@mapno) + # v0.22.0 (2022-01-13) This release has deprecations. Please read [DEPRECATION] entries and consult diff --git a/pkg/traces/promsdprocessor/prom_sd_processor.go b/pkg/traces/promsdprocessor/prom_sd_processor.go index 13d4fcc19c78..82eef1aac2f5 100644 --- a/pkg/traces/promsdprocessor/prom_sd_processor.go +++ b/pkg/traces/promsdprocessor/prom_sd_processor.go @@ -119,7 +119,12 @@ func stringAttributeFromMap(attrs pdata.AttributeMap, key string) string { } func getConnectionIP(ctx context.Context) string { - return client.FromContext(ctx).Addr.String() + c := client.FromContext(ctx) + if c.Addr == nil { + return "" + } + + return c.Addr.String() } func (p *promServiceDiscoProcessor) getPodIP(ctx context.Context, attrs pdata.AttributeMap) string { From 62ff1489521b9934c7ba98b3dbbf27e1133c9226 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Mon, 17 Jan 2022 11:23:52 +0100 Subject: [PATCH 2/6] Fix panic in prom_sd_processor when address is empty --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 270afc8c55fc..3253a4ecb7ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ for detailed information. - [BUGFIX] Grafana Agent Operator: The /-/ready and /-/healthy endpoints will no longer always return 404 (@rfratto). +- [BUGFIX] Fix panic in prom_sd_processor when address is empty (@mapno) + - [DEPRECATION] The node_exporter integration's `netdev_device_whitelist` field is deprecated in favor of `netdev_device_include`. Support for the old field name will be removed in a future version. (@rfratto) From b02d61e9eb6d362b258e3f58af793ec20e76277d Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Mon, 17 Jan 2022 12:13:03 +0100 Subject: [PATCH 3/6] Fix docs --- docs/configuration/traces-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/traces-config.md b/docs/configuration/traces-config.md index 2cf6cf1ffeb4..83557549a591 100644 --- a/docs/configuration/traces-config.md +++ b/docs/configuration/traces-config.md @@ -168,7 +168,7 @@ scrape_configs: # # By default, all methods are enabled, and evaluated in the order specified above. # Order of evaluation is honored when multiple methods are enabled. -prom_sd_pod_association: +prom_sd_pod_associations: - [ ... ] # spanmetrics supports aggregating Request, Error and Duration (R.E.D) metrics From f0f2495bcad56bf0d9797414a653e6e6b14e1d73 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Mon, 17 Jan 2022 12:19:53 +0100 Subject: [PATCH 4/6] Add test case --- pkg/traces/promsdprocessor/prom_sd_processor_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/traces/promsdprocessor/prom_sd_processor_test.go b/pkg/traces/promsdprocessor/prom_sd_processor_test.go index 18d49642e3cc..f7a9dc159945 100644 --- a/pkg/traces/promsdprocessor/prom_sd_processor_test.go +++ b/pkg/traces/promsdprocessor/prom_sd_processor_test.go @@ -248,6 +248,16 @@ func TestPodAssociation(t *testing.T) { attrMapFn: func(*testing.T) pdata.AttributeMap { return pdata.NewAttributeMap() }, expectedIP: ipStr, }, + { + name: "connection IP is empty", + podAssociations: []string{podAssociationConnectionIP}, + ctxFn: func(t *testing.T) context.Context { + c := client.FromContext(context.Background()) + return client.NewContext(context.Background(), c) + }, + attrMapFn: func(*testing.T) pdata.AttributeMap { return pdata.NewAttributeMap() }, + expectedIP: "", + }, { name: "ip attribute", ctxFn: func(t *testing.T) context.Context { return context.Background() }, From 59bc5be482c055fd0d1b81e327ce294260569007 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Mon, 17 Jan 2022 12:26:40 +0100 Subject: [PATCH 5/6] Lint --- pkg/traces/promsdprocessor/prom_sd_processor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/traces/promsdprocessor/prom_sd_processor_test.go b/pkg/traces/promsdprocessor/prom_sd_processor_test.go index f7a9dc159945..6c0485d5c2c6 100644 --- a/pkg/traces/promsdprocessor/prom_sd_processor_test.go +++ b/pkg/traces/promsdprocessor/prom_sd_processor_test.go @@ -249,7 +249,7 @@ func TestPodAssociation(t *testing.T) { expectedIP: ipStr, }, { - name: "connection IP is empty", + name: "connection IP is empty", podAssociations: []string{podAssociationConnectionIP}, ctxFn: func(t *testing.T) context.Context { c := client.FromContext(context.Background()) From a6baa23947c8f120b9fbd4e91a3565685ba4e669 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Mon, 17 Jan 2022 12:36:01 +0100 Subject: [PATCH 6/6] Move to unreleased --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3253a4ecb7ba..270afc8c55fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,8 +55,6 @@ for detailed information. - [BUGFIX] Grafana Agent Operator: The /-/ready and /-/healthy endpoints will no longer always return 404 (@rfratto). -- [BUGFIX] Fix panic in prom_sd_processor when address is empty (@mapno) - - [DEPRECATION] The node_exporter integration's `netdev_device_whitelist` field is deprecated in favor of `netdev_device_include`. Support for the old field name will be removed in a future version. (@rfratto)