Skip to content

Commit

Permalink
fix: collector metrics update after collector version update (#2355)
Browse files Browse the repository at this point in the history
  • Loading branch information
RonFed authored Jan 31, 2025
1 parent 3808517 commit 5160dda
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 50 deletions.
2 changes: 1 addition & 1 deletion autoscaler/controllers/datacollection/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func calculateConfigMapData(nodeCG *odigosv1.CollectorsGroup, sources *odigosv1.
"metric_relabel_configs": []config.GenericMap{
{
"source_labels": []string{"__name__"},
"regex": "(.*odigos.*|^otelcol_processor_accepted.*)",
"regex": "(.*odigos.*)",
"action": "keep",
},
},
Expand Down
2 changes: 1 addition & 1 deletion autoscaler/controllers/gateway/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func addSelfTelemetryPipeline(c *config.Config, ownTelemetryPort int32) error {
"metric_relabel_configs": []config.GenericMap{
{
"source_labels": []string{"__name__"},
"regex": "(.*odigos.*|^otelcol_processor_accepted.*|^otelcol_exporter_sent.*)",
"regex": "(.*odigos.*|^otelcol_exporter_sent.*)",
"action": "keep",
},
},
Expand Down
30 changes: 27 additions & 3 deletions collector/processors/odigostrafficmetrics/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,47 @@

The following telemetry is emitted by this component.

### otelcol_log_data_size
### otelcol_odigos_accepted_log_records

Number of log records passed through the processor.

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| {records} | Sum | Int | true |

### otelcol_odigos_accepted_metric_points

Number of data points passed through the processor.

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| {datapoints} | Sum | Int | true |

### otelcol_odigos_accepted_spans

Number of spans passed through the processor.

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| {spans} | Sum | Int | true |

### otelcol_odigos_log_data_size

Total size of log data passed to the processor

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| By | Sum | Int | true |

### otelcol_metric_data_size
### otelcol_odigos_metric_data_size

Total size of metric data passed to the processor

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| By | Sum | Int | true |

### otelcol_trace_data_size
### otelcol_odigos_trace_data_size

Total size of trace data passed to the processor

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions collector/processors/odigostrafficmetrics/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,45 @@ status:

telemetry:
metrics:
log_data_size:
odigos_log_data_size:
enabled: true
description: "Total size of log data passed to the processor"
unit: "By"
sum:
value_type: int
monotonic: true
metric_data_size:
odigos_metric_data_size:
enabled: true
description: "Total size of metric data passed to the processor"
unit: "By"
sum:
value_type: int
monotonic: true
trace_data_size:
odigos_trace_data_size:
enabled: true
description: "Total size of trace data passed to the processor"
unit: "By"
sum:
value_type: int
monotonic: true
odigos_accepted_spans:
enabled: true
description: Number of spans passed through the processor.
unit: "{spans}"
sum:
value_type: int
monotonic: true
odigos_accepted_metric_points:
enabled: true
description: Number of data points passed through the processor.
unit: "{datapoints}"
sum:
value_type: int
monotonic: true
odigos_accepted_log_records:
enabled: true
description: Number of log records passed through the processor.
unit: "{records}"
sum:
value_type: int
monotonic: true
12 changes: 6 additions & 6 deletions collector/processors/odigostrafficmetrics/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,24 @@ func (p *dataSizesMetricsProcessor) meterAttributes(md pmetric.Metrics) []attrib

func (p *dataSizesMetricsProcessor) processTraces(ctx context.Context, td ptrace.Traces) (ptrace.Traces, error) {
if p.samplingFraction != 0 && rand.Float64() < p.samplingFraction {
p.obsrep.TraceDataSize.Add(ctx, int64(p.tracesSizer.TracesSize(td))*p.inverseSamplingFraction, metric.WithAttributes(p.traceAttributes(td)...))
p.obsrep.OdigosTraceDataSize.Add(ctx, int64(p.tracesSizer.TracesSize(td))*p.inverseSamplingFraction, metric.WithAttributes(p.traceAttributes(td)...))
p.obsrep.OdigosAcceptedSpans.Add(ctx, int64(td.SpanCount()))
}
p.obsrep.TraceDataSize.Add(ctx, int64(td.SpanCount()))
return td, nil
}

func (p *dataSizesMetricsProcessor) processLogs(ctx context.Context, ld plog.Logs) (plog.Logs, error) {
if p.samplingFraction != 0 && rand.Float64() < p.samplingFraction {
p.obsrep.LogDataSize.Add(ctx, int64(p.logsSizer.LogsSize(ld))*p.inverseSamplingFraction, metric.WithAttributes(p.logAttributes(ld)...))
p.obsrep.OdigosLogDataSize.Add(ctx, int64(p.logsSizer.LogsSize(ld))*p.inverseSamplingFraction, metric.WithAttributes(p.logAttributes(ld)...))
p.obsrep.OdigosAcceptedLogRecords.Add(ctx, int64(ld.LogRecordCount()))
}
p.obsrep.LogDataSize.Add(ctx, int64(ld.LogRecordCount()))
return ld, nil
}

func (p *dataSizesMetricsProcessor) processMetrics(ctx context.Context, md pmetric.Metrics) (pmetric.Metrics, error) {
if p.samplingFraction != 0 && rand.Float64() < p.samplingFraction {
p.obsrep.MetricDataSize.Add(ctx, int64(p.metricsSizer.MetricsSize(md))*p.inverseSamplingFraction, metric.WithAttributes(p.meterAttributes(md)...))
p.obsrep.OdigosMetricDataSize.Add(ctx, int64(p.metricsSizer.MetricsSize(md))*p.inverseSamplingFraction, metric.WithAttributes(p.meterAttributes(md)...))
p.obsrep.OdigosAcceptedMetricPoints.Add(ctx, int64(md.MetricCount()))
}
p.obsrep.MetricDataSize.Add(ctx, int64(md.MetricCount()))
return md, nil
}
4 changes: 2 additions & 2 deletions collector/processors/odigostrafficmetrics/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestProcessor_Traces(t *testing.T) {
for _, sm := range rm.ScopeMetrics {
for _, metric := range sm.Metrics {
switch metric.Name {
case "processor_odigostrafficmetrics_trace_data_size":
case "otelcol_trace_data_size":
sum := metric.Data.(metricdata.Sum[int64])
require.Equal(t, 1, len(sum.DataPoints))

Expand Down Expand Up @@ -104,7 +104,7 @@ func TestProcessor_Traces(t *testing.T) {
for _, sm := range rm.ScopeMetrics {
for _, metric := range sm.Metrics {
switch metric.Name {
case "processor_odigostrafficmetrics_trace_data_size":
case "otelcol_trace_data_size":
sum := metric.Data.(metricdata.Sum[int64])
require.Equal(t, 1, len(sum.DataPoints))

Expand Down
34 changes: 19 additions & 15 deletions frontend/services/collector_metrics/cluster_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ import (
)

const (
// These metrics are added to each exporter. And are provided by the collector exporterhelper.
// These are not stable and may change in the future.
// Using these metrics, we can estimate the amount of data sent by each exporter.
exporterSentSpansMetricName = "otelcol_exporter_sent_spans"
exporterSentMetricsMetricName = "otelcol_exporter_sent_metric_points"
exporterSentLogsMetricName = "otelcol_exporter_sent_log_records"

processorAcceptedSpansMetricName = "otelcol_processor_accepted_spans"
processorAcceptedMetricsMetricName = "otelcol_processor_accepted_metric_points"
processorAcceptedLogsMetricName = "otelcol_processor_accepted_log_records"

// Each metrics from the exporters has this attribute which is the name of the exporter.
exporterMetricAttributesKey = "exporter"
processorMetricAttributesKey = "processor"

// These metrics are added by the odigostrafficmetrics processor.
// Each processor comes with `otelcol_processor_incoming_items` and `otelcol_processor_outgoing_items` metrics.
// but since we need our processor anyway, we use our custom metrics from it to reduce the handling of breaking changes by the collector.
// These metrics are used to estimate the average size of spans/metrics/logs.
processorAcceptedSpansMetricName = "otelcol_odigos_accepted_spans"
processorAcceptedMetricsMetricName = "otelcol_odigos_accepted_metric_points"
processorAcceptedLogsMetricName = "otelcol_odigos_accepted_log_records"
)

type destinationsMetrics struct {
Expand Down Expand Up @@ -260,16 +267,13 @@ func (dm *destinationsMetrics) updateAverageEstimates(md pmetric.Metrics) {
case processorAcceptedSpansMetricName, processorAcceptedMetricsMetricName, processorAcceptedLogsMetricName:
for dataPointIndex := 0; dataPointIndex < m.Sum().DataPoints().Len(); dataPointIndex++ {
dataPoint := m.Sum().DataPoints().At(dataPointIndex)
processorName, ok := dataPoint.Attributes().Get(processorMetricAttributesKey)
if ok && processorName.Str() == "odigostrafficmetrics" {
switch m.Name() {
case processorAcceptedSpansMetricName:
acceptedSpans = int64(dataPoint.DoubleValue())
case processorAcceptedMetricsMetricName:
acceptedMetrics = int64(dataPoint.DoubleValue())
case processorAcceptedLogsMetricName:
acceptedLogs = int64(dataPoint.DoubleValue())
}
switch m.Name() {
case processorAcceptedSpansMetricName:
acceptedSpans = int64(dataPoint.DoubleValue())
case processorAcceptedMetricsMetricName:
acceptedMetrics = int64(dataPoint.DoubleValue())
case processorAcceptedLogsMetricName:
acceptedLogs = int64(dataPoint.DoubleValue())
}
}
case traceSizeMetricName, metricSizeMetricName, logSizeMetricName:
Expand Down
6 changes: 3 additions & 3 deletions frontend/services/collector_metrics/collector_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
)

const (
traceSizeMetricName = "processor_odigostrafficmetrics_trace_data_size"
metricSizeMetricName = "processor_odigostrafficmetrics_metric_data_size"
logSizeMetricName = "processor_odigostrafficmetrics_log_data_size"
traceSizeMetricName = "otelcol_odigos_trace_data_size"
metricSizeMetricName = "otelcol_odigos_metric_data_size"
logSizeMetricName = "otelcol_odigos_log_data_size"
)

var (
Expand Down
14 changes: 14 additions & 0 deletions tests/common/assert/odigos-installed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ status:
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: odigos-ui
namespace: odigos-test
status:
containerStatuses:
- name: ui
ready: true
restartCount: 0
started: true
phase: Running
---
apiVersion: v1
kind: Pod
metadata:
labels:
app.kubernetes.io/name: odiglet
Expand Down
Loading

0 comments on commit 5160dda

Please sign in to comment.