From 1d06721c674b7dc8b510b75b5c16d0982ed3ed4d Mon Sep 17 00:00:00 2001 From: Paulin Todev Date: Thu, 19 Oct 2023 10:29:33 +0100 Subject: [PATCH] Add new options to spanmetrics processor in static mode: (#5407) * Add new options to spanmetrics processor in static mode: * aggregation_temporality * metrics_flush_interval --- CHANGELOG.md | 4 ++++ .../sources/static/configuration/traces-config.md | 11 ++++++++--- pkg/traces/config.go | 15 +++++++++++++++ pkg/traces/config_test.go | 7 +++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74570c5389f1..e8a8960d866c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,10 @@ v0.37.2 (2023-10-16) - Allow Out of Order writing to the WAL for metrics. (@mattdurham) +- Added new config options to spanmetrics processor in static mode (@ptodev): + - `aggregation_temporality`: configures whether to reset the metrics after flushing. + - `metrics_flush_interval`: configures how often to flush generated metrics. + ### Other changes - Use Go 1.21.3 for builds. (@tpaschalis) diff --git a/docs/sources/static/configuration/traces-config.md b/docs/sources/static/configuration/traces-config.md index dbd27dc34245..6e8537a2c0a2 100644 --- a/docs/sources/static/configuration/traces-config.md +++ b/docs/sources/static/configuration/traces-config.md @@ -157,7 +157,7 @@ remote_write: automatic_logging: # Indicates where the stream of log lines should go. Either supports writing # to a logs instance defined in this same config or to stdout. - [ backend: | default = "stdout" | supported "stdout", "logs_instance" ] + [ backend: | default = "stdout" | supported = "stdout", "logs_instance" ] # Indicates the logs instance to write logs to. # Required if backend is set to logs_instance. [ logs_instance_name: ] @@ -264,8 +264,13 @@ spanmetrics: [ metrics_instance: ] # handler_endpoint defines the endpoint where the OTel prometheus exporter will be exposed. [ handler_endpoint: ] - # dimensions_cache_size defines the size of cache for storing Dimensions - [ dimensions_cache_size: ] + # dimensions_cache_size defines the size of cache for storing Dimensions. + [ dimensions_cache_size: | default = 1000 ] + # aggregation_temporality configures whether to reset the metrics after flushing. + # It can be either AGGREGATION_TEMPORALITY_CUMULATIVE or AGGREGATION_TEMPORALITY_DELTA. + [ aggregation_temporality: | default = "AGGREGATION_TEMPORALITY_CUMULATIVE" ] + # metrics_flush_interval configures how often to flush generated metrics. + [ metrics_flush_interval: | default = 15s ] # tail_sampling supports tail-based sampling of traces in the agent. # diff --git a/pkg/traces/config.go b/pkg/traces/config.go index dbd6e28a9a44..dd55cb3a538a 100644 --- a/pkg/traces/config.go +++ b/pkg/traces/config.go @@ -365,6 +365,15 @@ type SpanMetricsConfig struct { // DimensionsCacheSize defines the size of cache for storing Dimensions, which helps to avoid cache memory growing // indefinitely over the lifetime of the collector. DimensionsCacheSize int `yaml:"dimensions_cache_size"` + + // Defines the aggregation temporality of the generated metrics. Can be either of: + // * "AGGREGATION_TEMPORALITY_CUMULATIVE" + // * "AGGREGATION_TEMPORALITY_DELTA" + AggregationTemporality string `yaml:"aggregation_temporality"` + + // MetricsEmitInterval is the time period between when metrics are flushed + // or emitted to the configured MetricsInstance or HandlerEndpoint. + MetricsFlushInterval time.Duration `yaml:"metrics_flush_interval"` } // tailSamplingConfig is the configuration for tail-based sampling @@ -739,6 +748,12 @@ func (c *InstanceConfig) otelConfig() (*otelcol.Config, error) { "latency_histogram_buckets": c.SpanMetrics.LatencyHistogramBuckets, "dimensions": c.SpanMetrics.Dimensions, } + if c.SpanMetrics.AggregationTemporality != "" { + spanMetrics["aggregation_temporality"] = c.SpanMetrics.AggregationTemporality + } + if c.SpanMetrics.MetricsFlushInterval != 0 { + spanMetrics["metrics_flush_interval"] = c.SpanMetrics.MetricsFlushInterval + } if c.SpanMetrics.DimensionsCacheSize != 0 { spanMetrics["dimensions_cache_size"] = c.SpanMetrics.DimensionsCacheSize } diff --git a/pkg/traces/config_test.go b/pkg/traces/config_test.go index 89157f809ba7..80edb01b82f5 100644 --- a/pkg/traces/config_test.go +++ b/pkg/traces/config_test.go @@ -546,6 +546,8 @@ spanmetrics: - name: http.status_code metrics_instance: traces dimensions_cache_size: 10000 + aggregation_temporality: AGGREGATION_TEMPORALITY_DELTA + metrics_flush_interval: 20s `, expectedConfig: ` receivers: @@ -572,6 +574,8 @@ processors: default: GET - name: http.status_code dimensions_cache_size: 10000 + aggregation_temporality: AGGREGATION_TEMPORALITY_DELTA + metrics_flush_interval: 20s extensions: {} service: pipelines: @@ -617,6 +621,9 @@ processors: metrics_exporter: prometheus latency_histogram_buckets: {} dimensions: {} + aggregation_temporality: AGGREGATION_TEMPORALITY_CUMULATIVE + metrics_flush_interval: 15s + dimensions_cache_size: 1000 extensions: {} service: