agent icon indicating copy to clipboard operation
agent copied to clipboard

Many v2 integrations do not use identifiers properly

Open rfratto opened this issue 3 years ago • 1 comments
trafficstars

The following v2 integrations are not using identifiers properly:

  • [x] apache_http (#2023)
    • Identifier panics if c.Common.InstanceKey is nil
  • [ ] eventhander
    • Identifier ignores value of c.Common.InstanceKey
  • [ ] snmp_exporter
    • Identifier ignores value of c.Common.InstanceKey
    • Targets always uses empty instance label

Code example

https://github.com/grafana/agent/blob/f410158210490d70e2fa10ff0fe049245a918087/pkg/integrations/v2/apache_http/apache_http.go#L40-L43

https://github.com/grafana/agent/blob/f410158210490d70e2fa10ff0fe049245a918087/pkg/integrations/v2/apache_http/apache_http.go#L58-L65

Background

Many v2 integrations do not implement the Identifier method correctly. Some also seem to implement InstanceKey, which is not expected of the interface (though it is also implemented incorrectly).

The Identifier method should be implemented for each integration with the following behavior:

  • Return c.Common.InstanceKey if it is not nil
  • Otherwise, return an integrations-specific default value

The integration-specific default value should be something meaningful to the integration, like the URL of the SUO. If there is no meaningful default value, implementations can return globals.AgentIdentifier.

Always returning *c.Common.InstanceKey will panic if the instance key is not configured, and the instance key is an optional field.

If MetricsIntegration is implemented, the result of calling Identifier should be the value of the instance label for the target. Some v2 integrations also do not do this correctly:

https://github.com/grafana/agent/blob/f410158210490d70e2fa10ff0fe049245a918087/pkg/integrations/v2/snmp_exporter/snmp.go#L33-L65

The instance label should be set to the same value as Identifier, with the same fallback using the globals.

rfratto avatar Aug 09 '22 20:08 rfratto

cc @captncraig @marctc

rfratto avatar Aug 09 '22 20:08 rfratto

This issue has been automatically marked as stale because it has not had any activity in the past 30 days. The next time this stale check runs, the stale label will be removed if there is new activity. The issue will be closed in 7 days if there is no new activity. Thank you for your contributions!

github-actions[bot] avatar Sep 22 '22 00:09 github-actions[bot]

* [x]  `eventhander`
  
  * Identifier ignores value of c.Common.InstanceKey

This integration is not using common.MetricsConfig therefore is not possible to use c.Common.InstanceKey in this context.

marctc avatar Oct 14 '22 13:10 marctc

This integration is not using common.MetricsConfig therefore is not possible to use c.Common.InstanceKey in this context.

Ah, you're right. It should probably still provide instance key as a field though so the user can override it like they do for other integrations.

rfratto avatar Oct 14 '22 15:10 rfratto

Ah, you're right. It should probably still provide instance key as a field though so the user can override it like they do for other integrations.

Ah, makes sense. Should we reopen this an add follow-up PR?

marctc avatar Oct 14 '22 15:10 marctc

Ah, makes sense. Should we reopen this an add follow-up PR?

I can create a new issue 👍

rfratto avatar Oct 14 '22 16:10 rfratto