Skip to content

Commit

Permalink
Update OpenTelemetry Dependencies to latest (#5001)
Browse files Browse the repository at this point in the history
* Update OpenTelemetry Dependencies to latest

* update deprecated component.MarshalConfig

* rename deprecated NewCommand to NewCommandMustSetProvider

* rename deprecated CreateSettings to Settings

* make generate-metrics

* update golden file for TestHostObserver

* update golden file for TestDiscoveryReceiverWithHostObserverAndSimplePrometheusReceiverProvideStatusLogs

---------

Co-authored-by: jeffreyc-splunk <[email protected]>
  • Loading branch information
srv-gh-o11y-gdi and jeffreyc-splunk authored Jun 21, 2024
1 parent 0a2b4b6 commit ee41830
Show file tree
Hide file tree
Showing 56 changed files with 920 additions and 896 deletions.
2 changes: 1 addition & 1 deletion cmd/otelcol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
}

func runInteractive(settings otelcol.CollectorSettings) error {
cmd := otelcol.NewCommand(settings)
cmd := otelcol.NewCommandMustSetProvider(settings)
if err := cmd.Execute(); err != nil {
return fmt.Errorf("application run finished with error: %w", err)
}
Expand Down
340 changes: 171 additions & 169 deletions go.mod

Large diffs are not rendered by default.

716 changes: 360 additions & 356 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions internal/confmapprovider/discovery/discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (d *discoverer) createDiscoveryReceiversAndObservers(cfg *Config) (map[comp
return nil, nil, fmt.Errorf("error preparing discovery receiver config: %w", err)
}

if err = component.UnmarshalConfig(discoveryReceiverConfMap, discoveryReceiverConfig); err != nil {
if err = discoveryReceiverConfMap.Unmarshal(&discoveryReceiverConfig); err != nil {
return nil, nil, fmt.Errorf("failed unmarshaling discovery receiver config: %w", err)
}

Expand Down Expand Up @@ -401,7 +401,7 @@ func (d *discoverer) createObserver(observerID component.ID, cfg *Config) (otelc
return nil, fmt.Errorf("error converting environment variables in %q config: %w", observerID, err)
}

if err = component.UnmarshalConfig(observerDiscoveryConf, observerConfig); err != nil {
if err = observerDiscoveryConf.Unmarshal(&observerConfig); err != nil {
return nil, fmt.Errorf("failed unmarshaling %q config: %w", observerID, err)
}

Expand Down Expand Up @@ -538,8 +538,8 @@ func (d *discoverer) discoveryConfig(cfg *Config) (map[string]any, error) {
return sMap, nil
}

func (d *discoverer) createExtensionCreateSettings(observerID component.ID) otelcolextension.CreateSettings {
return otelcolextension.CreateSettings{
func (d *discoverer) createExtensionCreateSettings(observerID component.ID) otelcolextension.Settings {
return otelcolextension.Settings{
ID: observerID,
TelemetrySettings: component.TelemetrySettings{
Logger: zap.New(d.logger.Core()).With(zap.String("kind", observerID.String())),
Expand All @@ -551,8 +551,8 @@ func (d *discoverer) createExtensionCreateSettings(observerID component.ID) otel
}
}

func (d *discoverer) createReceiverCreateSettings() otelcolreceiver.CreateSettings {
return otelcolreceiver.CreateSettings{
func (d *discoverer) createReceiverCreateSettings() otelcolreceiver.Settings {
return otelcolreceiver.Settings{
TelemetrySettings: component.TelemetrySettings{
Logger: zap.New(d.logger.Core()).With(zap.String("kind", "receiver")),
TracerProvider: tnoop.NewTracerProvider(),
Expand Down
5 changes: 2 additions & 3 deletions internal/exporter/httpsinkexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
)

Expand All @@ -34,14 +33,14 @@ func TestLoadConfig(t *testing.T) {
e0cm, err := configs.Sub("httpsink")
require.NoError(t, err)
e0 := createDefaultConfig()
require.NoError(t, component.UnmarshalConfig(e0cm, e0))
require.NoError(t, e0cm.Unmarshal(&e0))

assert.Equal(t, NewFactory().CreateDefaultConfig(), e0)

e1cm, err := configs.Sub("httpsink/2")
require.NoError(t, err)
e1 := createDefaultConfig()
require.NoError(t, component.UnmarshalConfig(e1cm, e1))
require.NoError(t, e1cm.Unmarshal(&e1))

assert.Equal(t,
&Config{
Expand Down
4 changes: 2 additions & 2 deletions internal/exporter/httpsinkexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func createDefaultConfig() component.Config {
}

func createTracesExporter(ctx context.Context,
set exporter.CreateSettings,
set exporter.Settings,
cfg component.Config,
) (exporter.Traces, error) {
exp := newExporter(set.Logger, cfg.(*Config).Endpoint)
Expand All @@ -61,7 +61,7 @@ func createTracesExporter(ctx context.Context,
}

func createMetricsExporter(ctx context.Context,
set exporter.CreateSettings,
set exporter.Settings,
cfg component.Config,
) (exporter.Metrics, error) {
exp := newExporter(set.Logger, cfg.(*Config).Endpoint)
Expand Down
2 changes: 1 addition & 1 deletion internal/exporter/httpsinkexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCreateTracesExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

te, err := factory.CreateTracesExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
te, err := factory.CreateTracesExporter(context.Background(), exportertest.NewNopSettings(), cfg)
assert.NoError(t, err)
assert.NotNil(t, te)
}
4 changes: 2 additions & 2 deletions internal/receiver/discoveryreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestValidConfig(t *testing.T) {
cm, err := configs.Sub("discovery")
require.NoError(t, err)
cfg := createDefaultConfig().(*Config)
err = component.UnmarshalConfig(cm, cfg)
err = cm.Unmarshal(&cfg)
require.NoError(t, err)

require.Equal(t, &Config{
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestInvalidConfigs(t *testing.T) {
cm, err := config.Sub(typeStr)
require.NoError(t, err)
cfg := createDefaultConfig().(*Config)
err = component.UnmarshalConfig(cm, cfg)
err = cm.Unmarshal(&cfg)
require.NoError(t, err)
err = cfg.Validate()
require.Error(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func TestUpdateEndpoints(t *testing.T) {
cm, err := config.Sub(typeStr)
require.NoError(t, err)
cfg := createDefaultConfig().(*Config)
require.NoError(t, component.UnmarshalConfig(cm, cfg))
require.NoError(t, cm.Unmarshal(&cfg))

logger := zap.NewNop()
et := newEndpointTracker(nil, cfg, logger, nil, newCorrelationStore(logger, cfg.CorrelationTTL))
Expand Down
2 changes: 1 addition & 1 deletion internal/receiver/discoveryreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func createDefaultConfig() component.Config {

func createLogsReceiver(
_ context.Context,
settings receiver.CreateSettings,
settings receiver.Settings,
cfg component.Config,
consumer consumer.Logs,
) (receiver.Logs, error) {
Expand Down
6 changes: 3 additions & 3 deletions internal/receiver/discoveryreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestCreateLogsReceiver(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

params := otelcolreceiver.CreateSettings{}
params := otelcolreceiver.Settings{}
receiver, err := factory.CreateLogsReceiver(context.Background(), params, cfg, consumertest.NewNop())
assert.Error(t, err)
assert.EqualError(t, err, "`watch_observers` must be defined and include at least one configured observer extension")
Expand All @@ -53,7 +53,7 @@ func TestCreateMetricsReceiver(t *testing.T) {
cfg := &Config{}
require.Error(t, cfg.Validate())

params := otelcolreceiver.CreateSettings{}
params := otelcolreceiver.Settings{}
rcvr, err := factory.CreateMetricsReceiver(context.Background(), params, cfg, consumertest.NewNop())
require.Error(t, err)
assert.EqualError(t, err, "telemetry type is not supported")
Expand All @@ -65,7 +65,7 @@ func TestCreateTracesReceiver(t *testing.T) {
cfg := &Config{}
require.Error(t, cfg.Validate())

params := otelcolreceiver.CreateSettings{}
params := otelcolreceiver.Settings{}
rcvr, err := factory.CreateTracesReceiver(context.Background(), params, cfg, consumertest.NewNop())
require.Error(t, err)
assert.EqualError(t, err, "telemetry type is not supported")
Expand Down
6 changes: 3 additions & 3 deletions internal/receiver/discoveryreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type discoveryReceiver struct {
pLogs chan plog.Logs
observables map[component.ID]observer.Observable
loopFinished *sync.WaitGroup
settings receiver.CreateSettings
settings receiver.Settings
}

func newDiscoveryReceiver(
settings receiver.CreateSettings,
settings receiver.Settings,
config *Config,
consumer consumer.Logs,
) (*discoveryReceiver, error) {
Expand Down Expand Up @@ -176,7 +176,7 @@ func (d *discoveryReceiver) createAndSetReceiverCreator() error {
id := component.MustNewIDWithName(receiverCreatorFactory.Type().String(), d.settings.ID.String())
// receiverCreatorConfig.SetIDName(d.settings.ID.String())

receiverCreatorSettings := receiver.CreateSettings{
receiverCreatorSettings := receiver.Settings{
ID: id,
TelemetrySettings: component.TelemetrySettings{
Logger: d.statementEvaluator.evaluatedLogger.With(
Expand Down
4 changes: 2 additions & 2 deletions internal/receiver/discoveryreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestNewDiscoveryReceiver(t *testing.T) {
rcs := otelcolreceiver.CreateSettings{
rcs := otelcolreceiver.Settings{
TelemetrySettings: component.TelemetrySettings{
Logger: zap.NewNop(),
MeterProvider: mnoop.NewMeterProvider(),
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestObservablesFromHost(t *testing.T) {
} {
test := tt
t.Run(test.name, func(t *testing.T) {
rcs := otelcolreceiver.CreateSettings{
rcs := otelcolreceiver.Settings{
TelemetrySettings: component.TelemetrySettings{
Logger: zap.NewNop(),
TracerProvider: tnoop.NewTracerProvider(),
Expand Down
3 changes: 1 addition & 2 deletions internal/receiver/lightprometheusreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/receiver/scraperhelper"
Expand All @@ -35,7 +34,7 @@ func TestValidConfig(t *testing.T) {
require.NoError(t, err)

cfg := createDefaultConfig().(*Config)
err = component.UnmarshalConfig(cm, cfg)
err = cm.Unmarshal(&cfg)
require.NoError(t, err)
require.NoError(t, cfg.Validate())

Expand Down
2 changes: 1 addition & 1 deletion internal/receiver/lightprometheusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewFactory() receiver.Factory {
// createMetricsReceiver creates a metrics receiver for scraping Prometheus metrics.
func createMetricsReceiver(
_ context.Context,
params receiver.CreateSettings,
params receiver.Settings,
rConf component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/receiver/lightprometheusreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type scraper struct {
}

func newScraper(
settings receiver.CreateSettings,
settings receiver.Settings,
cfg *Config,
) *scraper {
e := &scraper{
Expand Down
2 changes: 1 addition & 1 deletion internal/receiver/lightprometheusreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestScraper(t *testing.T) {
cfg.ClientConfig.Endpoint = fmt.Sprintf("%s%s", promMock.URL, "/metrics")
require.NoError(t, component.ValidateConfig(cfg))

scraper := newScraper(receivertest.NewNopCreateSettings(), cfg)
scraper := newScraper(receivertest.NewNopSettings(), cfg)

err := scraper.start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions internal/receiver/scriptedinputsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap/confmaptest"
)
Expand All @@ -48,7 +47,7 @@ func TestValidConfig(t *testing.T) {
require.NoError(t, err)

cfg := createDefaultConfig()
err = component.UnmarshalConfig(cm, cfg)
err = cm.Unmarshal(&cfg)
require.NoError(t, err)

require.Equal(t, &Config{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
var _ component.Config = (*Config)(nil)

type Config struct {
confighttp.ServerConfig `mapstructure:",squash"`
ListenPath string `mapstructure:"path"`
BufferSize int `mapstructure:"buffer_size"`
confighttp.ServerConfig `mapstructure:",squash"`
BufferSize int `mapstructure:"buffer_size"`
}

func (c *Config) Validate() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func TestParseConfig(t *testing.T) {
sub, err = sub.Sub(metadata.Type.String())
require.NoError(t, err)
require.NotEmpty(t, sub)
require.NoError(t, component.UnmarshalConfig(sub, config))
require.NoError(t, sub.Unmarshal(&config))

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewFactory() receiver.Factory {

func createMetricsReceiver(
_ context.Context,
params receiver.CreateSettings,
params receiver.Settings,
cfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestFactory(t *testing.T) {
cfg.ListenPath = "/metrics"

nopHost := componenttest.NewNopHost()
mockSettings := receivertest.NewNopCreateSettings()
mockSettings := receivertest.NewNopSettings()
mockConsumer := consumertest.NewNop()
receiver, err := newReceiver(mockSettings, cfg, mockConsumer)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ type prometheusRemoteWriteReceiver struct {
nextConsumer consumer.Metrics
cancel context.CancelFunc
config *Config
settings receiver.CreateSettings
settings receiver.Settings
}

func newReceiver(
settings receiver.CreateSettings,
settings receiver.Settings,
config *Config,
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type otelReporter struct {
obsrecv *receiverhelper.ObsReport
}

func newOtelReporter(settings receiver.CreateSettings) (reporter, error) {
func newOtelReporter(settings receiver.Settings) (reporter, error) {
obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: settings.ID,
Transport: "tcp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ type prometheusRemoteWriteServer struct {
}

type serverConfig struct {
confighttp.ServerConfig
component.TelemetrySettings
Reporter reporter
component.Host
Mc chan<- pmetric.Metrics
Parser *prometheusRemoteOtelParser
Path string
confighttp.ServerConfig
}

func newPrometheusRemoteWriteServer(ctx context.Context, config *serverConfig) (*prometheusRemoteWriteServer, error) {
Expand Down
Loading

0 comments on commit ee41830

Please sign in to comment.