Skip to content

Commit

Permalink
Fix panic in prom_sd_processor when address is empty (grafana#1279)
Browse files Browse the repository at this point in the history
* Fix panic in prom_sd_processor when address is empty

* Fix panic in prom_sd_processor when address is empty

* Fix docs

* Add test case

* Lint

* Move to unreleased
  • Loading branch information
mapno committed Jan 25, 2022
1 parent d9e4eaf commit c2073cd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/traces-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- [ <string>... ]

# spanmetrics supports aggregating Request, Error and Duration (R.E.D) metrics
Expand Down
7 changes: 6 additions & 1 deletion pkg/traces/promsdprocessor/prom_sd_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/traces/promsdprocessor/prom_sd_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
Expand Down

0 comments on commit c2073cd

Please sign in to comment.