newrelic / infra-integrations-sdk

New Relic Infrastructure Integrations SDK
Apache License 2.0
46 stars 24 forks source link

Common dimension not aligned with telemetry SDK #285

Closed rogercoll closed 2 years ago

rogercoll commented 2 years ago

Description

The SDK v4 is not generating a valid payload compared with the one the agent expects. In SDK v4, each entity can provide a map of common dimensions . Powerdns example:

"data": [
        {
            "common": {
                "scrapedTargetKind": "user_provided",
                "scrapedTargetName": "localhost: 9122",
                "scrapedTargetURL": "http: //localhost:9122/metrics",
                "targetName": "localhost:9122"
            },
...

The problem is that the agent defines this common field as the following data structure:

type Common struct {
    Timestamp  *int64                 `json:"timestamp"`
    Interval   *int64                 `json:"interval.ms"`
    Attributes map[string]interface{} `json:"attributes"`
}

Why to change the SDK and not the agent mapping?

SDK v4 payload data is transformed by the agent to a valid structure for the NR telemetry API. The Telemetry api defines the common structure similar to the agent one:

type metricCommonBlock struct {
    timestamp time.Time
    interval time.Duration
    forceIntervalValid bool
    attributes MapEntry
}

Telemetry expected payload example.

Expected behaviour

If we want to align the integrations SDK with the telemetry SDK, the commonDimension field should be aligned with the telemetry CommonBlock. The entity common data should be:

"data": [
        {
            "common": {
                "attributes": {
                                "scrapedTargetKind": "user_provided",
                                "scrapedTargetName": "localhost: 9122",
                                "scrapedTargetURL": "http: //localhost:9122/metrics",
                                "targetName": "localhost:9122"
                },
            },
...

Common timestamp and interval will be added but not covered in this issue as they are currently populated by the agent.

Release

Those change should not break current integrations as CommonDimensions should be added with AddCommonDimension. Nonetheless, CommonDimension field is public/exported, thus we should sync with core integrations to assure CommonDimension is not used directly.