Skip to content

Commit

Permalink
Create FilterMetricProcessor with processor.CreateSettings
Browse files Browse the repository at this point in the history
This is required so that we can access metadata about the processor for telemetry tags/labels.
  • Loading branch information
MacroPower committed Nov 19, 2023
1 parent d26d745 commit 0b6cbe1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion processor/filterprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func createMetricsProcessor(
cfg component.Config,
nextConsumer consumer.Metrics,
) (processor.Metrics, error) {
fp, err := newFilterMetricProcessor(set.TelemetrySettings, cfg.(*Config))
fp, err := newFilterMetricProcessor(set, cfg.(*Config))
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions processor/filterprocessor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"go.uber.org/multierr"
"go.uber.org/zap"
Expand All @@ -33,7 +33,7 @@ type filterMetricProcessor struct {
logger *zap.Logger
}

func newFilterMetricProcessor(set component.TelemetrySettings, cfg *Config) (*filterMetricProcessor, error) {
func newFilterMetricProcessor(set processor.CreateSettings, cfg *Config) (*filterMetricProcessor, error) {
var err error
fsp := &filterMetricProcessor{
logger: set.Logger,
Expand All @@ -47,14 +47,14 @@ func newFilterMetricProcessor(set component.TelemetrySettings, cfg *Config) (*fi

if cfg.Metrics.MetricConditions != nil || cfg.Metrics.DataPointConditions != nil {
if cfg.Metrics.MetricConditions != nil {
fsp.skipMetricExpr, err = filterottl.NewBoolExprForMetric(cfg.Metrics.MetricConditions, filterottl.StandardMetricFuncs(), cfg.ErrorMode, set)
fsp.skipMetricExpr, err = filterottl.NewBoolExprForMetric(cfg.Metrics.MetricConditions, filterottl.StandardMetricFuncs(), cfg.ErrorMode, set.TelemetrySettings)
if err != nil {
return nil, err
}
}

if cfg.Metrics.DataPointConditions != nil {
fsp.skipDataPointExpr, err = filterottl.NewBoolExprForDataPoint(cfg.Metrics.DataPointConditions, filterottl.StandardDataPointFuncs(), cfg.ErrorMode, set)
fsp.skipDataPointExpr, err = filterottl.NewBoolExprForDataPoint(cfg.Metrics.DataPointConditions, filterottl.StandardDataPointFuncs(), cfg.ErrorMode, set.TelemetrySettings)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions processor/filterprocessor/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -728,7 +727,7 @@ func TestFilterMetricProcessorWithOTTL(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
processor, err := newFilterMetricProcessor(componenttest.NewNopTelemetrySettings(), &Config{Metrics: tt.conditions, ErrorMode: tt.errorMode})
processor, err := newFilterMetricProcessor(processortest.NewNopCreateSettings(), &Config{Metrics: tt.conditions, ErrorMode: tt.errorMode})
assert.NoError(t, err)

got, err := processor.processMetrics(context.Background(), constructMetrics())
Expand Down
10 changes: 5 additions & 5 deletions processor/filterprocessor/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
Expand Down Expand Up @@ -55,17 +55,17 @@ type filterProcessorTelemetry struct {
droppedByFilter metric.Int64Counter
}

func newfilterProcessorTelemetry(set component.TelemetrySettings) (*filterProcessorTelemetry, error) {
id, _ := set.Resource.Attributes().Get("ID")
func newfilterProcessorTelemetry(set processor.CreateSettings) (*filterProcessorTelemetry, error) {
processorID := set.ID.String()

exportCtx, err := tag.New(context.Background(), tag.Insert(processorTagKey, id.Str()))
exportCtx, err := tag.New(context.Background(), tag.Insert(processorTagKey, processorID))
if err != nil {
return nil, err
}

fpt := &filterProcessorTelemetry{
useOtel: false,
processorAttr: []attribute.KeyValue{attribute.String(typeStr, id.Str())},
processorAttr: []attribute.KeyValue{attribute.String(typeStr, processorID)},
exportCtx: exportCtx,
}

Expand Down

0 comments on commit 0b6cbe1

Please sign in to comment.