Skip to content

Commit

Permalink
[chore] filterprocessor uses mdatagen for internal metrics (open-tele…
Browse files Browse the repository at this point in the history
…metry#33197)

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten authored May 22, 2024
1 parent 4056608 commit 2dc3ac3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 41 deletions.
31 changes: 31 additions & 0 deletions processor/filterprocessor/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# filter

## Internal Telemetry

The following telemetry is emitted by this component.

### processor_filter_datapoints.filtered

Number of metric data points dropped by the filter processor

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

### processor_filter_logs.filtered

Number of logs dropped by the filter processor

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

### processor_filter_spans.filtered

Number of spans dropped by the filter processor

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| 1 | Sum | Int | true |
43 changes: 43 additions & 0 deletions processor/filterprocessor/internal/metadata/generated_telemetry.go

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.

24 changes: 24 additions & 0 deletions processor/filterprocessor/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@ status:
active: [TylerHelmuth, boostchicken]
tests:
config:

telemetry:
metrics:
processor_filter_datapoints.filtered:
enabled: true
description: Number of metric data points dropped by the filter processor
unit: 1
sum:
value_type: int
monotonic: true
processor_filter_logs.filtered:
enabled: true
description: Number of logs dropped by the filter processor
unit: 1
sum:
value_type: int
monotonic: true
processor_filter_spans.filtered:
enabled: true
description: Number of spans dropped by the filter processor
unit: 1
sum:
value_type: int
monotonic: true
51 changes: 10 additions & 41 deletions processor/filterprocessor/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"

"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"

Expand All @@ -27,61 +26,31 @@ type filterProcessorTelemetry struct {

processorAttr []attribute.KeyValue

datapointsFiltered metric.Int64Counter
logsFiltered metric.Int64Counter
spansFiltered metric.Int64Counter
telemetryBuilder *metadata.TelemetryBuilder
}

func newfilterProcessorTelemetry(set processor.CreateSettings) (*filterProcessorTelemetry, error) {
processorID := set.ID.String()

fpt := &filterProcessorTelemetry{
processorAttr: []attribute.KeyValue{attribute.String(metadata.Type.String(), processorID)},
exportCtx: context.Background(),
}

counter, err := metadata.Meter(set.TelemetrySettings).Int64Counter(
processorhelper.BuildCustomMetricName(metadata.Type.String(), "datapoints.filtered"),
metric.WithDescription("Number of metric data points dropped by the filter processor"),
metric.WithUnit("1"),
)
if err != nil {
return nil, err
}
fpt.datapointsFiltered = counter

counter, err = metadata.Meter(set.TelemetrySettings).Int64Counter(
processorhelper.BuildCustomMetricName(metadata.Type.String(), "logs.filtered"),
metric.WithDescription("Number of logs dropped by the filter processor"),
metric.WithUnit("1"),
)
if err != nil {
return nil, err
}
fpt.logsFiltered = counter

counter, err = metadata.Meter(set.TelemetrySettings).Int64Counter(
processorhelper.BuildCustomMetricName(metadata.Type.String(), "spans.filtered"),
metric.WithDescription("Number of spans dropped by the filter processor"),
metric.WithUnit("1"),
)
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
if err != nil {
return nil, err
}
fpt.spansFiltered = counter

return fpt, nil
return &filterProcessorTelemetry{
processorAttr: []attribute.KeyValue{attribute.String(metadata.Type.String(), set.ID.String())},
exportCtx: context.Background(),
telemetryBuilder: telemetryBuilder,
}, nil
}

func (fpt *filterProcessorTelemetry) record(trigger trigger, dropped int64) {
var triggerMeasure metric.Int64Counter
switch trigger {
case triggerMetricDataPointsDropped:
triggerMeasure = fpt.datapointsFiltered
triggerMeasure = fpt.telemetryBuilder.ProcessorFilterDatapointsFiltered
case triggerLogsDropped:
triggerMeasure = fpt.logsFiltered
triggerMeasure = fpt.telemetryBuilder.ProcessorFilterLogsFiltered
case triggerSpansDropped:
triggerMeasure = fpt.spansFiltered
triggerMeasure = fpt.telemetryBuilder.ProcessorFilterSpansFiltered
}

triggerMeasure.Add(fpt.exportCtx, dropped, metric.WithAttributes(fpt.processorAttr...))
Expand Down

0 comments on commit 2dc3ac3

Please sign in to comment.