-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sampling strategies flag to OTEL collector
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
- Loading branch information
1 parent
b99114e
commit f8094e3
Showing
7 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package jaegerreceiver | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/component" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configerror" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
"github.com/open-telemetry/opentelemetry-collector/consumer" | ||
"github.com/open-telemetry/opentelemetry-collector/receiver/jaegerreceiver" | ||
"github.com/spf13/viper" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" | ||
) | ||
|
||
// Factory wraps jaegerreceiver.Factory and makes the default config configurable via viper. | ||
// For instance this enables using flags as default values in the config object. | ||
type Factory struct { | ||
// Wrapped is Jaeger receiver. | ||
Wrapped *jaegerreceiver.Factory | ||
// Viper is used to get configuration values for default configuration | ||
Viper *viper.Viper | ||
} | ||
|
||
var _ component.ReceiverFactoryOld = (*Factory)(nil) | ||
|
||
// Type gets the type of exporter. | ||
func (f *Factory) Type() string { | ||
return f.Wrapped.Type() | ||
} | ||
|
||
// CreateDefaultConfig returns default configuration of Factory. | ||
// This function implements OTEL component.BaseFactory interface. | ||
func (f *Factory) CreateDefaultConfig() configmodels.Receiver { | ||
cfg := f.Wrapped.CreateDefaultConfig().(*jaegerreceiver.Config) | ||
strategyFile := f.Viper.GetString(static.SamplingStrategiesFile) | ||
// if remote sampling struct is not nil the factory will use default values for endpoints and enable remote sampling | ||
// the problem is that flag will always return some default value | ||
// so we cannot distinguish when it should be enabled and when not. | ||
// Using default values makes sense when a component is enabled | ||
var samplingConf *jaegerreceiver.RemoteSamplingConfig | ||
if strategyFile != "" { | ||
samplingConf = &jaegerreceiver.RemoteSamplingConfig{ | ||
StrategyFile: strategyFile, | ||
} | ||
} | ||
cfg.RemoteSampling = samplingConf | ||
return cfg | ||
} | ||
|
||
// CreateTraceReceiver creates Jaeger receiver trace receiver. | ||
// This function implements OTEL component.ReceiverFactory interface. | ||
func (f *Factory) CreateTraceReceiver( | ||
ctx context.Context, | ||
log *zap.Logger, | ||
cfg configmodels.Receiver, | ||
nextConsumer consumer.TraceConsumerOld, | ||
) (component.TraceReceiver, error) { | ||
return f.Wrapped.CreateTraceReceiver(ctx, log, cfg, nextConsumer) | ||
} | ||
|
||
// CustomUnmarshaler creates custom unmarshaller for Jaeger receiver config. | ||
// This function implements component.ReceiverFactoryBase interface. | ||
func (f *Factory) CustomUnmarshaler() component.CustomUnmarshaler { | ||
return f.Wrapped.CustomUnmarshaler() | ||
} | ||
|
||
// CreateMetricsReceiver creates a metrics receiver based on provided config. | ||
// This function implements component.ReceiverFactory. | ||
func (f *Factory) CreateMetricsReceiver( | ||
_ *zap.Logger, | ||
_ configmodels.Receiver, | ||
_ consumer.MetricsConsumerOld, | ||
) (component.MetricsReceiver, error) { | ||
return nil, configerror.ErrDataTypeIsNotSupported | ||
} |
57 changes: 57 additions & 0 deletions
57
cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package jaegerreceiver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config/configerror" | ||
"github.com/open-telemetry/opentelemetry-collector/receiver/jaegerreceiver" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" | ||
) | ||
|
||
func TestDefaultValueFromViper(t *testing.T) { | ||
v := viper.New() | ||
v.Set(static.SamplingStrategiesFile, "config.json") | ||
jr := &jaegerreceiver.Factory{} | ||
|
||
f := &Factory{ | ||
Wrapped: jr, | ||
Viper: v, | ||
} | ||
|
||
cfg := f.CreateDefaultConfig().(*jaegerreceiver.Config) | ||
assert.Equal(t, "config.json", cfg.RemoteSampling.StrategyFile) | ||
} | ||
|
||
func TestType(t *testing.T) { | ||
f := &Factory{ | ||
Wrapped: &jaegerreceiver.Factory{}, | ||
} | ||
assert.Equal(t, "jaeger", f.Type()) | ||
} | ||
|
||
func TestCreateMetricsExporter(t *testing.T) { | ||
f := &Factory{ | ||
Wrapped: &jaegerreceiver.Factory{}, | ||
} | ||
mReceiver, err := f.CreateMetricsReceiver(zap.NewNop(), nil, nil) | ||
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported) | ||
assert.Nil(t, mReceiver) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters