Skip to content

Commit

Permalink
[processor/spanmetrics] Simplify spanmetrics config tests. (#18496)
Browse files Browse the repository at this point in the history
Parse only relevant to the component configuration.
It allows us to drop some unnecessary dependencies.
  • Loading branch information
kovrus authored Feb 13, 2023
1 parent e920e75 commit 527702d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 533 deletions.
124 changes: 53 additions & 71 deletions processor/spanmetricsprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,96 +22,78 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/otlpexporter"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/processor/batchprocessor"
"go.opentelemetry.io/collector/receiver/otlpreceiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver"
)

func TestLoadConfig(t *testing.T) {
t.Parallel()

defaultMethod := "GET"
testcases := []struct {
configFile string
wantMetricsExporter string
wantLatencyHistogramBuckets []time.Duration
wantDimensions []Dimension
wantDimensionsCacheSize int
wantAggregationTemporality string
wantMetricsFlushInterval time.Duration
tests := []struct {
name string
id component.ID
expected component.Config
}{
{
configFile: "config-2-pipelines.yaml",
wantMetricsExporter: "prometheus",
wantAggregationTemporality: cumulative,
wantDimensionsCacheSize: 500,
wantMetricsFlushInterval: 15 * time.Second, // Default.
name: "configuration with dimensions size cache",
id: component.NewIDWithName(typeStr, "dimensions"),
expected: &Config{
MetricsExporter: "prometheus",
AggregationTemporality: cumulative,
DimensionsCacheSize: 500,
MetricsFlushInterval: 15 * time.Second,
},
},
{
configFile: "config-3-pipelines.yaml",
wantMetricsExporter: "otlp/spanmetrics",
wantAggregationTemporality: cumulative,
wantDimensionsCacheSize: defaultDimensionsCacheSize,
wantMetricsFlushInterval: 15 * time.Second, // Default.
name: "configuration with aggregation temporality",
id: component.NewIDWithName(typeStr, "temp"),
expected: &Config{
MetricsExporter: "otlp/spanmetrics",
AggregationTemporality: cumulative,
DimensionsCacheSize: defaultDimensionsCacheSize,
MetricsFlushInterval: 15 * time.Second,
},
},
{
configFile: "config-full.yaml",
wantMetricsExporter: "otlp/spanmetrics",
wantLatencyHistogramBuckets: []time.Duration{
100 * time.Microsecond,
1 * time.Millisecond,
2 * time.Millisecond,
6 * time.Millisecond,
10 * time.Millisecond,
100 * time.Millisecond,
250 * time.Millisecond,
},
wantDimensions: []Dimension{
{"http.method", &defaultMethod},
{"http.status_code", nil},
name: "configuration with all available parameters",
id: component.NewIDWithName(typeStr, "full"),
expected: &Config{
MetricsExporter: "otlp/spanmetrics",
AggregationTemporality: delta,
DimensionsCacheSize: 1500,
MetricsFlushInterval: 30 * time.Second,
LatencyHistogramBuckets: []time.Duration{
100 * time.Microsecond,
1 * time.Millisecond,
2 * time.Millisecond,
6 * time.Millisecond,
10 * time.Millisecond,
100 * time.Millisecond,
250 * time.Millisecond,
},
Dimensions: []Dimension{
{"http.method", &defaultMethod},
{"http.status_code", nil},
},
},
wantDimensionsCacheSize: 1500,
wantAggregationTemporality: delta,
wantMetricsFlushInterval: 30 * time.Second,
},
}
for _, tc := range testcases {
t.Run(tc.configFile, func(t *testing.T) {
// Prepare
factories, err := otelcoltest.NopFactories()
require.NoError(t, err)

factories.Receivers["otlp"] = otlpreceiver.NewFactory()
factories.Receivers["jaeger"] = jaegerreceiver.NewFactory()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)

factories.Processors[typeStr] = NewFactory()
factories.Processors["batch"] = batchprocessor.NewFactory()
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

factories.Exporters["otlp"] = otlpexporter.NewFactory()
factories.Exporters["prometheus"] = prometheusexporter.NewFactory()
factories.Exporters["jaeger"] = jaegerexporter.NewFactory()
sub, err := cm.Sub(tt.id.String())
require.NoError(t, err)

// Test
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", tc.configFile), factories)
require.NoError(t, component.UnmarshalConfig(sub, cfg))

// Verify
require.NoError(t, err)
require.NotNil(t, cfg)
assert.Equal(t,
&Config{
MetricsExporter: tc.wantMetricsExporter,
LatencyHistogramBuckets: tc.wantLatencyHistogramBuckets,
Dimensions: tc.wantDimensions,
DimensionsCacheSize: tc.wantDimensionsCacheSize,
AggregationTemporality: tc.wantAggregationTemporality,
MetricsFlushInterval: tc.wantMetricsFlushInterval,
},
cfg.Processors[component.NewID(typeStr)],
)
assert.Equal(t, tt.expected, cfg)
})
}
}
Expand Down
71 changes: 5 additions & 66 deletions processor/spanmetricsprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,58 @@ go 1.18

require (
github.com/hashicorp/golang-lru v0.5.4
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.71.0
github.com/stretchr/testify v1.8.1
github.com/tilinna/clock v1.1.0
go.opentelemetry.io/collector v0.71.0
go.opentelemetry.io/collector/component v0.71.0
go.opentelemetry.io/collector/confmap v0.71.0
go.opentelemetry.io/collector/consumer v0.71.0
go.opentelemetry.io/collector/exporter/otlpexporter v0.71.0
go.opentelemetry.io/collector/featuregate v0.71.0
go.opentelemetry.io/collector/pdata v1.0.0-rc5
go.opentelemetry.io/collector/processor/batchprocessor v0.71.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.71.0
go.opentelemetry.io/collector/semconv v0.71.0
go.uber.org/zap v1.24.0
google.golang.org/grpc v1.52.3
)

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
github.com/apache/thrift v0.17.0 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jaegertracing/jaeger v1.41.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.1.17 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.71.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.71.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.71.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/shirou/gopsutil/v3 v3.23.1 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector/confmap v0.71.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.39.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.14.0 // indirect
go.opentelemetry.io/otel v1.13.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.36.0 // indirect
go.opentelemetry.io/otel/metric v0.36.0 // indirect
go.opentelemetry.io/otel/sdk v1.13.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.36.0 // indirect
go.opentelemetry.io/otel/trace v1.13.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
gonum.org/v1/gonum v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand All @@ -114,30 +71,12 @@ replace cloud.google.com/go => cloud.google.com/go v0.100.2
// Force cloud.google.com/go/compute to be at least v1.12.1.
replace cloud.google.com/go/compute => cloud.google.com/go/compute v1.12.1

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter => ../../exporter/jaegerexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter => ../../exporter/prometheusexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter => ../../exporter/prometheusremotewriteexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry => ../../pkg/resourcetotelemetry

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger => ../../pkg/translator/jaeger

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus => ../../pkg/translator/opencensus

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus => ../../pkg/translator/prometheus

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite => ../../pkg/translator/prometheusremotewrite

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver => ../../receiver/jaegerreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver => ../../receiver/prometheusreceiver

retract v0.65.0

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil
Loading

0 comments on commit 527702d

Please sign in to comment.