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

Fix statsd receiver aggregate metrics in various instruments. #30228

Closed

Conversation

charz
Copy link

@charz charz commented Dec 28, 2023

The receiver uses each metric's address as the key to create instruments, but the port in the address of each metric is dynamically assigned. This results in the StatsD receiver creating numerous instruments and being unable to aggregate metrics together.

Fixes #29508, fixex #23809

Description:

Link to tracking Issue: #29508, #23809

Testing:

Config.yaml

receivers:
  statsd:
    endpoint: "0.0.0.0:8125" # default
    aggregation_interval: 20s  # default
    enable_metric_type: false  # default
    is_monotonic_counter: true # default
    timer_histogram_mapping:
      - statsd_type: "timing"
        observer_type: "summary"
      - statsd_type: "distribution"
        observer_type: "histogram"
        histogram:
          max_size: 50

processors:
  batch:

exporters:
  file/tmp:
    path: /tmp/collector-output.json

  prometheus:
    endpoint: "0.0.0.0:9105"
    send_timestamps: false
    metric_expiration: 120m
    enable_open_metrics: false
    add_metric_suffixes: false
    resource_to_telemetry_conversion:
      enabled: true

service:
  telemetry:
    logs:
      level: debug
    metrics:
      address: ":8889"
  pipelines:
    metrics:
      receivers: [statsd]
      processors: [batch]      
      exporters: [prometheus, file/tmp]

Run custom otelcol

➜  ~/build  ./otelcol-charz --config config.yaml                     
2023-12-28T15:15:08.660+0800    info    [email protected]/telemetry.go:86 Setting up own telemetry...
2023-12-28T15:15:08.660+0800    info    [email protected]/telemetry.go:203        Serving Prometheus metrics      {"address": ":8889", "level": "Basic"}
2023-12-28T15:15:08.660+0800    debug   [email protected]/exporter.go:273        Alpha component. May change in the future.      {"kind": "exporter", "data_type": "metrics", "name": "file/tmp"}
2023-12-28T15:15:08.661+0800    debug   [email protected]/exporter.go:273        Beta component. May change in the future.       {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}
2023-12-28T15:15:08.661+0800    debug   [email protected]/processor.go:287      Stable component.       {"kind": "processor", "name": "batch", "pipeline": "metrics"}
2023-12-28T15:15:08.661+0800    debug   [email protected]/receiver.go:294        Beta component. May change in the future.       {"kind": "receiver", "name": "statsd", "data_type": "metrics"}
2023-12-28T15:15:08.661+0800    info    [email protected]/service.go:145  Starting otelcol-charz...       {"Version": "1.0.0", "NumCPU": 10}
2023-12-28T15:15:08.661+0800    info    extensions/extensions.go:34     Starting extensions...
2023-12-28T15:15:08.661+0800    warn    [email protected]/warning.go:40  Using the 0.0.0.0 address exposes this server to every network interface, which may facilitate Denial of Service attacks        {"kind": "exporter", "data_type": "metrics", "name": "prometheus", "documentation": "https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/security-best-practices.md#safeguards-against-denial-of-service-attacks"}
2023-12-28T15:15:08.661+0800    info    [email protected]/service.go:171  Everything is ready. Begin running and processing data.

2023-12-28T15:15:28.769+0800    debug   [email protected]/accumulator.go:79    accumulating metric: test.metric        {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}
2023-12-28T15:17:28.856+0800    debug   [email protected]/accumulator.go:79    accumulating metric: test.metric.ts     {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}
2023-12-28T15:17:35.643+0800    debug   [email protected]/collector.go:362     collect called  {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}
2023-12-28T15:17:35.643+0800    debug   [email protected]/accumulator.go:268   Accumulator collect called      {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}
2023-12-28T15:17:35.643+0800    debug   [email protected]/collector.go:386     metric served: Desc{fqName: "test_metric", help: "", constLabels: {}, variableLabels: {myKey}}  {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}
2023-12-28T15:17:35.643+0800    debug   [email protected]/collector.go:386     metric served: Desc{fqName: "test_metric_ts", help: "", constLabels: {}, variableLabels: {myKey}}       {"kind": "exporter", "data_type": "metrics", "name": "prometheus"}

#23809

➜  ~ echo "test.metric:10|c|#myKey:myVal" | nc -w 1 -u localhost 8125
➜  ~ echo "test.metric:20|c|#myKey:myVal" | nc -w 1 -u localhost 8125

➜  ~ cat /tmp/collector-output.json |jq; date
{
  "resourceMetrics": [
    {
      "resource": {},
      "scopeMetrics": [
        {
          "scope": {
            "name": "otelcol/statsdreceiver",
            "version": "1.0.0"
          },
          "metrics": [
            {
              "name": "test.metric",
              "sum": {
                "dataPoints": [
                  {
                    "attributes": [
                      {
                        "key": "myKey",
                        "value": {
                          "stringValue": "myVal"
                        }
                      }
                    ],
                    "startTimeUnixNano": "1703747708661566000",
                    "timeUnixNano": "1703747728661899000",
                    "asInt": "30"
                  }
                ],
                "aggregationTemporality": 1,
                "isMonotonic": true
              }
            }
          ]
        }
      ]
    }
  ]
}
Thu Dec 28 15:15:32 CST 2023

#29508

➜  ~  echo "test.metric.ts:1|ms|@1|#myKey:myVal" | nc -w 1 -u 127.0.0.1 8125;
➜  ~ echo "test.metric.ts:2|ms|@1|#myKey:myVal" | nc -w 1 -u 127.0.0.1 8125;
➜  ~ echo "test.metric.ts:22|ms|@1|#myKey:myVal" | nc -w 1 -u 127.0.0.1 8125;
➜  ~ curl -sS 127.0.0.1:9105/metrics |grep test.metric.ts; date
# HELP test_metric_ts
# TYPE test_metric_ts summary
test_metric_ts{myKey="myVal",quantile="0"} 1
test_metric_ts{myKey="myVal",quantile="0.1"} 1
test_metric_ts{myKey="myVal",quantile="0.5"} 2
test_metric_ts{myKey="myVal",quantile="0.9"} 22
test_metric_ts{myKey="myVal",quantile="0.95"} 22
test_metric_ts{myKey="myVal",quantile="1"} 22
test_metric_ts_sum{myKey="myVal"} 25
test_metric_ts_count{myKey="myVal"} 3
Thu Dec 28 15:17:35 CST 2023

Documentation: None

The receiver uses each metric's address as the key to create instruments,
but the port in the address of each metric is dynamically assigned.
This results in the StatsD receiver creating numerous instruments and
being unable to aggregate metrics together.

Fixes open-telemetry#29508, fixex open-telemetry#23809
@charz charz requested review from jmacd and dmitryax as code owners December 28, 2023 07:22
@charz charz requested a review from a team December 28, 2023 07:22
Copy link

CLA Missing ID CLA Not Signed

@github-actions github-actions bot added the receiver/statsd statsd related issues label Dec 28, 2023
@jmacd jmacd changed the title Fix statsd receiver aggregate memtrics in various instruments. Fix statsd receiver aggregate metrics in various instruments. Jan 8, 2024
@@ -119,7 +119,8 @@ func (r *statsdReceiver) Start(ctx context.Context, host component.Host) error {
}
}
case metric := <-transferChan:
if err := r.parser.Aggregate(metric.Raw, metric.Addr); err != nil {
addr, _ := net.ResolveIPAddr(r.config.NetAddr.Transport, r.config.NetAddr.Endpoint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this ResolveIPAddr() call into an initialization routine, so that it's not called on every packet.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 23, 2024
Copy link
Contributor

github-actions bot commented Feb 7, 2024

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
receiver/statsd statsd related issues Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

statsd receiver does not display well for statsd_type timing when observed as observer_type summary
3 participants