Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pichlermarc opened this issue Mar 5, 2024 · 3 comments
Assignees
Labels
bug Something isn't working priority:p2 Medium processor/transform Transform processor

Comments

@pichlermarc
Copy link
Member

pichlermarc commented Mar 5, 2024

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

@pichlermarc pichlermarc added bug Something isn't working needs triage New item requiring triage labels Mar 5, 2024
@github-actions github-actions bot added the processor/transform Transform processor label Mar 5, 2024
Copy link
Contributor

github-actions bot commented Mar 5, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@pichlermarc
Copy link
Member Author

I'd be happy to open a PR if code-owners agree that we should change it. 🙂

@evan-bradley
Copy link
Contributor

Thanks for the detailed report! This is a good catch, I agree that a count metric should have a counter unit and not the unit of the original histogram.

@evan-bradley evan-bradley added priority:p2 Medium and removed needs triage New item requiring triage labels Mar 5, 2024
TylerHelmuth added a commit that referenced this issue Mar 12, 2024
)

**Description:** 

The `transformprocessor` offers a function `extract_count_metric()`.
Currently this function copies over the `unit` from the original metric
to a new `count` metric. However, this unit is not applicable as the
value is a count of how many values were recorded in a Explicit
Bucket/Exponential Histogram or Summary.

Therefore this PR changes that function so that it adds the default unit
(`1`) to the extracted count metric instead.

**Link to tracking Issue:** #31575 

**Testing:** Unit tests (updated)

**Documentation:** Added a changelog entry as the change is user-facing
(the unit of the emitted telemetry is changed)

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
DougManton pushed a commit to DougManton/opentelemetry-collector-contrib that referenced this issue Mar 13, 2024
…n-telemetry#31636)

**Description:** 

The `transformprocessor` offers a function `extract_count_metric()`.
Currently this function copies over the `unit` from the original metric
to a new `count` metric. However, this unit is not applicable as the
value is a count of how many values were recorded in a Explicit
Bucket/Exponential Histogram or Summary.

Therefore this PR changes that function so that it adds the default unit
(`1`) to the extracted count metric instead.

**Link to tracking Issue:** open-telemetry#31575 

**Testing:** Unit tests (updated)

**Documentation:** Added a changelog entry as the change is user-facing
(the unit of the emitted telemetry is changed)

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
XinRanZhAWS pushed a commit to XinRanZhAWS/opentelemetry-collector-contrib that referenced this issue Mar 13, 2024
…n-telemetry#31636)

**Description:** 

The `transformprocessor` offers a function `extract_count_metric()`.
Currently this function copies over the `unit` from the original metric
to a new `count` metric. However, this unit is not applicable as the
value is a count of how many values were recorded in a Explicit
Bucket/Exponential Histogram or Summary.

Therefore this PR changes that function so that it adds the default unit
(`1`) to the extracted count metric instead.

**Link to tracking Issue:** open-telemetry#31575 

**Testing:** Unit tests (updated)

**Documentation:** Added a changelog entry as the change is user-facing
(the unit of the emitted telemetry is changed)

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:p2 Medium processor/transform Transform processor
Projects
None yet
Development

No branches or pull requests

3 participants