Skip to content

[processor/transform] unit is copied to count metric when using extract_count_metric() #31575

Closed
@pichlermarc

Description

@pichlermarc

Component(s)

processor/transform

What happened?

Description

Using extract_count_metric() will retain the unit of the original metric. While this makes sense for extracted sum metrics, it may not be accurate in most (all?) cases of extracted count metrics.

Example (http.server.request.duration Histogram):

Its unit is s (seconds). In an app, we record how many seconds a request takes. The sum will be in seconds, as we just add those seconds together, so we should keep the unit there. However, for count the unit cannot be seconds as it's actually the number of how many requests were recorded. I think (if I'm not missing anything) that the unit for extracted count should always be 1.

Steps to Reproduce

Prerequisite files

collector-config.yaml

  • See config below

request.json

{
  "resourceMetrics": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "basic-metric-service"
            }
          }
        ],
        "droppedAttributesCount": 0
      },
      "scopeMetrics": [
        {
          "metrics": [
            {
              "description": "Example of a Histogram",
              "name": "example.histogram",
              "histogram": {
                "aggregationTemporality": 2,
                "dataPoints": [
                  {
                    "startTimeUnixNano": "1544712660300000000",
                    "timeUnixNano": "1544712660300000000",
                    "count": 2,
                    "sum": 2,
                    "bucketCounts": [1,1],
                    "explicitBounds": [1],
                    "min": 0,
                    "max": 2,
                    "attributes": []
                  }
                ]
              },
              "unit": "s"
            }
          ],
          "scope": {
            "name": "example",
            "version": ""
          }
        }
      ]
    }
  ]
}

Steps:

  • create the two files above
  • run otelcol-contrib --config collector-config.yaml
  • run curl -X POST -H "Content-Type: application/json" -d @request.json -i localhost:4318/v1/metrics
  • inspect output (see below, it includes same unit as the source metric)

Expected Result

  • Unit is not set to s on the extracted metric

Actual Result

  • Unit is set to s the extracted metric

Collector version

v0.95.0

Environment information

Environment

OS: Ubuntu 22.04

OpenTelemetry Collector configuration

receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

processors:
  transform/histogram:
    metric_statements:
      - context: metric
        statements:
          # Get count from the histogram. The new metric name will be <histogram_name>_count
          - extract_count_metric(true) where type == METRIC_DATA_TYPE_HISTOGRAM

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    metrics/otlp:
      receivers: [otlp]
      processors: [transform/histogram]
      exporters: [debug]

Log output

Metric #1
Descriptor:
     -> Name: example.histogram_count
     -> Description: Example of a Histogram
     -> Unit: s
     -> DataType: Sum
     -> IsMonotonic: true
     -> AggregationTemporality: Cumulative
NumberDataPoints #0
StartTimestamp: 2018-12-13 14:51:00.3 +0000 UTC
Timestamp: 2018-12-13 14:51:00.3 +0000 UTC
Value: 2

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions