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

[processor/groupbyattrs] move from OpenCensus to OpenTelemetry #30764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/codeboten_rm-groupbyattrs-census.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: groupbyattrsprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: move metrics from OpenCensus to OpenTelemetry

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [30763]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
10 changes: 5 additions & 5 deletions processor/filterprocessor/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processortest"
"go.opentelemetry.io/otel/attribute"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/filterprocessor/internal/metadata"
)

type testTelemetry struct {
reader *sdkmetric.ManualReader
meterProvider *sdkmetric.MeterProvider
reader *metric.ManualReader
meterProvider *metric.MeterProvider
}

type expectedMetrics struct {
Expand All @@ -40,10 +40,10 @@ func telemetryTest(t *testing.T, name string, testFunc func(t *testing.T, tel te
}

func setupTelemetry() testTelemetry {
reader := sdkmetric.NewManualReader()
reader := metric.NewManualReader()
return testTelemetry{
reader: reader,
meterProvider: sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)),
meterProvider: metric.NewMeterProvider(metric.WithReader(reader)),
}
}

Expand Down
34 changes: 19 additions & 15 deletions processor/groupbyattrsprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ package groupbyattrsprocessor // import "github.com/open-telemetry/opentelemetry

import (
"context"
"sync"

"go.opencensus.io/stats/view"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
Expand All @@ -21,15 +19,8 @@ var (
consumerCapabilities = consumer.Capabilities{MutatesData: true}
)

var once sync.Once

// NewFactory returns a new factory for the Filter processor.
func NewFactory() processor.Factory {
once.Do(func() {
// TODO: as with other -contrib factories registering metrics, this is causing the error being ignored
_ = view.Register(metricViews()...)
})

return processor.NewFactory(
metadata.Type,
createDefaultConfig,
Expand All @@ -45,23 +36,27 @@ func createDefaultConfig() component.Config {
}
}

func createGroupByAttrsProcessor(logger *zap.Logger, attributes []string) *groupByAttrsProcessor {
func createGroupByAttrsProcessor(set processor.CreateSettings, attributes []string) (*groupByAttrsProcessor, error) {
var nonEmptyAttributes []string
presentAttributes := make(map[string]struct{})

for _, str := range attributes {
if str != "" {
_, isPresent := presentAttributes[str]
if isPresent {
logger.Warn("A grouping key is already present", zap.String("key", str))
set.Logger.Warn("A grouping key is already present", zap.String("key", str))
} else {
nonEmptyAttributes = append(nonEmptyAttributes, str)
presentAttributes[str] = struct{}{}
}
}
}

return &groupByAttrsProcessor{logger: logger, groupByKeys: nonEmptyAttributes}
it, err := newProcessorTelemetry(set.TelemetrySettings)
if err != nil {
return nil, err
}
return &groupByAttrsProcessor{logger: set.Logger, groupByKeys: nonEmptyAttributes, internalTelemetry: it}, nil
}

// createTracesProcessor creates a trace processor based on this config.
Expand All @@ -72,7 +67,10 @@ func createTracesProcessor(
nextConsumer consumer.Traces) (processor.Traces, error) {

oCfg := cfg.(*Config)
gap := createGroupByAttrsProcessor(set.Logger, oCfg.GroupByKeys)
gap, err := createGroupByAttrsProcessor(set, oCfg.GroupByKeys)
if err != nil {
return nil, err
}

return processorhelper.NewTracesProcessor(
ctx,
Expand All @@ -91,7 +89,10 @@ func createLogsProcessor(
nextConsumer consumer.Logs) (processor.Logs, error) {

oCfg := cfg.(*Config)
gap := createGroupByAttrsProcessor(set.Logger, oCfg.GroupByKeys)
gap, err := createGroupByAttrsProcessor(set, oCfg.GroupByKeys)
if err != nil {
return nil, err
}

return processorhelper.NewLogsProcessor(
ctx,
Expand All @@ -110,7 +111,10 @@ func createMetricsProcessor(
nextConsumer consumer.Metrics) (processor.Metrics, error) {

oCfg := cfg.(*Config)
gap := createGroupByAttrsProcessor(set.Logger, oCfg.GroupByKeys)
gap, err := createGroupByAttrsProcessor(set, oCfg.GroupByKeys)
if err != nil {
return nil, err
}

return processorhelper.NewMetricsProcessor(
ctx,
Expand Down
8 changes: 5 additions & 3 deletions processor/groupbyattrsprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/processor/processortest"
"go.uber.org/zap"
)

func TestDefaultConfiguration(t *testing.T) {
Expand Down Expand Up @@ -41,12 +41,14 @@ func TestCreateTestProcessor(t *testing.T) {

func TestNoKeys(t *testing.T) {
// This is allowed since can be used for compacting data
gap := createGroupByAttrsProcessor(zap.NewNop(), []string{})
gap, err := createGroupByAttrsProcessor(processortest.NewNopCreateSettings(), []string{})
require.NoError(t, err)
assert.NotNil(t, gap)
}

func TestDuplicateKeys(t *testing.T) {
gbap := createGroupByAttrsProcessor(zap.NewNop(), []string{"foo", "foo", ""})
gbap, err := createGroupByAttrsProcessor(processortest.NewNopCreateSettings(), []string{"foo", "foo", ""})
require.NoError(t, err)
assert.NotNil(t, gbap)
assert.EqualValues(t, []string{"foo"}, gbap.groupByKeys)
}
5 changes: 2 additions & 3 deletions processor/groupbyattrsprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.93.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.93.0
github.com/stretchr/testify v1.8.4
go.opencensus.io v0.24.0
go.opentelemetry.io/collector/component v0.93.1-0.20240130182548-89388addcc7f
go.opentelemetry.io/collector/confmap v0.93.1-0.20240130182548-89388addcc7f
go.opentelemetry.io/collector/consumer v0.93.1-0.20240130182548-89388addcc7f
go.opentelemetry.io/collector/pdata v1.0.2-0.20240130181942-9c7177496fd5
go.opentelemetry.io/collector/processor v0.93.1-0.20240130182548-89388addcc7f
go.opentelemetry.io/otel v1.22.0
go.opentelemetry.io/otel/metric v1.22.0
go.opentelemetry.io/otel/sdk/metric v1.22.0
go.opentelemetry.io/otel/trace v1.22.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.26.0
Expand Down Expand Up @@ -42,10 +43,8 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector v0.93.1-0.20240130182548-89388addcc7f // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.93.1-0.20240130182548-89388addcc7f // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.0 // indirect
go.opentelemetry.io/otel/sdk v1.22.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.22.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
Expand Down
Loading
Loading