From becf08f49a39ac0a38d84dbfcd8b4525522ca916 Mon Sep 17 00:00:00 2001 From: Moh Osman <59479562+moh-osman3@users.noreply.github.com> Date: Mon, 28 Nov 2022 17:29:55 -0500 Subject: [PATCH] Instrument obsreport.Processor (#6607) * Instrument obsreport.Processor * add processor promchecker tests * add chloggen * run make genpdata and fix linter errors * address review feedback and retest * pass cfg into createOtelMetrics --- .chloggen/depcollector.yaml | 22 ++++++ .../collector_windows_test.go | 4 +- {service => otelcol}/command_test.go | 20 ++++-- {service => otelcol}/config_provider_test.go | 7 +- otelcol/moved.go | 69 +++++++++++++++++++ otelcol/moved_windows.go | 25 +++++++ .../otelcoltest/config.go | 10 +-- .../otelcoltest/config_test.go | 2 +- .../otelcoltest}/testdata/config.yaml | 0 otelcol/testdata/otelcol-invalid.yaml | 18 +++++ otelcol/testdata/otelcol-nop.yaml | 30 ++++++++ service/collector.go | 7 ++ service/collector_windows.go | 1 + service/config.go | 2 +- service/config_provider.go | 4 ++ service/servicetest/deprecated.go | 11 +++ service/settings.go | 1 + 17 files changed, 216 insertions(+), 17 deletions(-) create mode 100755 .chloggen/depcollector.yaml rename {service => otelcol}/collector_windows_test.go (93%) rename {service => otelcol}/command_test.go (62%) rename {service => otelcol}/config_provider_test.go (96%) create mode 100644 otelcol/moved.go create mode 100644 otelcol/moved_windows.go rename service/servicetest/configprovider.go => otelcol/otelcoltest/config.go (89%) rename service/servicetest/configprovider_test.go => otelcol/otelcoltest/config_test.go (99%) rename {service/servicetest => otelcol/otelcoltest}/testdata/config.yaml (100%) create mode 100644 otelcol/testdata/otelcol-invalid.yaml create mode 100644 otelcol/testdata/otelcol-nop.yaml create mode 100644 service/servicetest/deprecated.go diff --git a/.chloggen/depcollector.yaml b/.chloggen/depcollector.yaml new file mode 100755 index 00000000000..92d5f9d59a9 --- /dev/null +++ b/.chloggen/depcollector.yaml @@ -0,0 +1,22 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate service.[Collector|NewSvcHandler|CollectorSettings|State|NewCommand] in favor of otelcol package" + +# One or more tracking issues or pull requests related to the change +issues: [6608] + +subtext: |- + - Deprecate `service.Config` in favor of `otelcol.Config`. + - Deprecate `service.ConfigProvider` in favor of `otelcol.ConfigProvider`. + - Deprecate `service.NewConfigProvider` in favor of `otelcol.NewConfigProvider`. + - Deprecate `service.CollectorSettings` in favor of `otelcol.Settings`. + - Deprecate `service.Collector` in favor of `otelcol.Settings`. + - Deprecate `service.New` in favor of `otelcol.New`. + - Deprecate `service.State` in favor of `otelcol.State`. + - Deprecate `service.NewSvcHandler` in favor of `otelcol.NewSvcHandler`. + - Deprecate `service.NewCommand` in favor of `otelcol.NewCommand`. diff --git a/service/collector_windows_test.go b/otelcol/collector_windows_test.go similarity index 93% rename from service/collector_windows_test.go rename to otelcol/collector_windows_test.go index 4929a04add5..580d096e09a 100644 --- a/service/collector_windows_test.go +++ b/otelcol/collector_windows_test.go @@ -15,7 +15,7 @@ //go:build windows // +build windows -package service +package otelcol import ( "os" @@ -38,7 +38,7 @@ func TestNewSvcHandler(t *testing.T) { factories, err := componenttest.NopFactories() require.NoError(t, err) - s := NewSvcHandler(CollectorSettings{BuildInfo: component.NewDefaultBuildInfo(), Factories: factories}) + s := NewSvcHandler(Settings{BuildInfo: component.NewDefaultBuildInfo(), Factories: factories}) colDone := make(chan struct{}) requests := make(chan svc.ChangeRequest) diff --git a/service/command_test.go b/otelcol/command_test.go similarity index 62% rename from service/command_test.go rename to otelcol/command_test.go index df5b45ae914..3e12d1a7d66 100644 --- a/service/command_test.go +++ b/otelcol/command_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package service +package otelcol import ( "path/filepath" @@ -23,10 +23,13 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/confmap/converter/expandconverter" + "go.opentelemetry.io/collector/confmap/provider/fileprovider" ) func TestNewCommandVersion(t *testing.T) { - cmd := NewCommand(CollectorSettings{BuildInfo: component.BuildInfo{Version: "test_version"}}) + cmd := NewCommand(Settings{BuildInfo: component.BuildInfo{Version: "test_version"}}) assert.Equal(t, "test_version", cmd.Version) } @@ -34,7 +37,7 @@ func TestNewCommandNoConfigURI(t *testing.T) { factories, err := componenttest.NopFactories() require.NoError(t, err) - cmd := NewCommand(CollectorSettings{Factories: factories}) + cmd := NewCommand(Settings{Factories: factories}) require.Error(t, cmd.Execute()) } @@ -42,9 +45,16 @@ func TestNewCommandInvalidComponent(t *testing.T) { factories, err := componenttest.NopFactories() require.NoError(t, err) - cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-invalid.yaml")})) + cfgProvider, err := NewConfigProvider( + ConfigProviderSettings{ + ResolverSettings: confmap.ResolverSettings{ + URIs: []string{filepath.Join("testdata", "otelcol-invalid.yaml")}, + Providers: map[string]confmap.Provider{"file": fileprovider.New()}, + Converters: []confmap.Converter{expandconverter.New()}, + }, + }) require.NoError(t, err) - cmd := NewCommand(CollectorSettings{Factories: factories, ConfigProvider: cfgProvider}) + cmd := NewCommand(Settings{Factories: factories, ConfigProvider: cfgProvider}) require.Error(t, cmd.Execute()) } diff --git a/service/config_provider_test.go b/otelcol/config_provider_test.go similarity index 96% rename from service/config_provider_test.go rename to otelcol/config_provider_test.go index fd7213ac07a..43716fd365c 100644 --- a/service/config_provider_test.go +++ b/otelcol/config_provider_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package service +package otelcol import ( "context" @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/confmap/provider/fileprovider" "go.opentelemetry.io/collector/confmap/provider/yamlprovider" "go.opentelemetry.io/collector/extension/extensiontest" + "go.opentelemetry.io/collector/service" "go.opentelemetry.io/collector/service/telemetry" ) @@ -39,9 +40,9 @@ var configNop = &Config{ Processors: map[component.ID]component.Config{component.NewID("nop"): componenttest.NewNopProcessorFactory().CreateDefaultConfig()}, Exporters: map[component.ID]component.Config{component.NewID("nop"): componenttest.NewNopExporterFactory().CreateDefaultConfig()}, Extensions: map[component.ID]component.Config{component.NewID("nop"): extensiontest.NewNopFactory().CreateDefaultConfig()}, - Service: ConfigService{ + Service: service.ConfigService{ Extensions: []component.ID{component.NewID("nop")}, - Pipelines: map[component.ID]*ConfigServicePipeline{ + Pipelines: map[component.ID]*service.ConfigServicePipeline{ component.NewID("traces"): { Receivers: []component.ID{component.NewID("nop")}, Processors: []component.ID{component.NewID("nop")}, diff --git a/otelcol/moved.go b/otelcol/moved.go new file mode 100644 index 00000000000..188e32eb392 --- /dev/null +++ b/otelcol/moved.go @@ -0,0 +1,69 @@ +// Copyright The OpenTelemetry 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 collector handles the command-line, configuration, and runs the +// OpenTelemetry Collector. +package otelcol // import "go.opentelemetry.io/collector/otelcol" + +import ( + "go.opentelemetry.io/collector/service" +) + +// State defines Collector's state. +type State = service.State //nolint:staticcheck + +const ( + StateStarting = service.StateStarting //nolint:staticcheck + StateRunning = service.StateRunning //nolint:staticcheck + StateClosing = service.StateClosing //nolint:staticcheck + StateClosed = service.StateClosed //nolint:staticcheck +) + +// Collector represents a server providing the OpenTelemetry Collector service. +type Collector = service.Collector //nolint:staticcheck + +// New creates and returns a new instance of Collector. +var New = service.New //nolint:staticcheck + +// Settings holds configuration for creating a new Collector. +type Settings = service.CollectorSettings //nolint:staticcheck + +// ConfigProvider provides the service configuration. +// +// The typical usage is the following: +// +// cfgProvider.Get(...) +// cfgProvider.Watch() // wait for an event. +// cfgProvider.Get(...) +// cfgProvider.Watch() // wait for an event. +// // repeat Get/Watch cycle until it is time to shut down the Collector process. +// cfgProvider.Shutdown() +type ConfigProvider = service.ConfigProvider //nolint:staticcheck + +// ConfigProviderSettings are the settings to configure the behavior of the ConfigProvider. +type ConfigProviderSettings = service.ConfigProviderSettings //nolint:staticcheck + +// NewConfigProvider returns a new ConfigProvider that provides the service configuration: +// * Initially it resolves the "configuration map": +// - Retrieve the confmap.Conf by merging all retrieved maps from the given `locations` in order. +// - Then applies all the confmap.Converter in the given order. +// +// * Then unmarshalls the confmap.Conf into the service Config. +var NewConfigProvider = service.NewConfigProvider //nolint:staticcheck + +// NewCommand constructs a new cobra.Command using the given CollectorSettings. +var NewCommand = service.NewCommand //nolint:staticcheck + +// Config defines the configuration for the various elements of collector or agent. +type Config = service.Config //nolint:staticcheck diff --git a/otelcol/moved_windows.go b/otelcol/moved_windows.go new file mode 100644 index 00000000000..b90eb9fc625 --- /dev/null +++ b/otelcol/moved_windows.go @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry 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. + +//go:build windows +// +build windows + +package otelcol // import "go.opentelemetry.io/collector/otelcol" + +import ( + "go.opentelemetry.io/collector/service" +) + +// NewSvcHandler constructs a new svc.Handler using the given CollectorSettings. +var NewSvcHandler = service.NewSvcHandler //nolint:staticcheck diff --git a/service/servicetest/configprovider.go b/otelcol/otelcoltest/config.go similarity index 89% rename from service/servicetest/configprovider.go rename to otelcol/otelcoltest/config.go index 227458ea93b..ceb314afc4d 100644 --- a/service/servicetest/configprovider.go +++ b/otelcol/otelcoltest/config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package servicetest // import "go.opentelemetry.io/collector/service/servicetest" +package otelcoltest // import "go.opentelemetry.io/collector/otelcol/otelcoltest" import ( "context" @@ -24,13 +24,13 @@ import ( "go.opentelemetry.io/collector/confmap/provider/fileprovider" "go.opentelemetry.io/collector/confmap/provider/httpprovider" "go.opentelemetry.io/collector/confmap/provider/yamlprovider" - "go.opentelemetry.io/collector/service" + "go.opentelemetry.io/collector/otelcol" ) // LoadConfig loads a config.Config from file, and does NOT validate the configuration. -func LoadConfig(fileName string, factories component.Factories) (*service.Config, error) { +func LoadConfig(fileName string, factories component.Factories) (*otelcol.Config, error) { // Read yaml config from file - provider, err := service.NewConfigProvider(service.ConfigProviderSettings{ + provider, err := otelcol.NewConfigProvider(otelcol.ConfigProviderSettings{ ResolverSettings: confmap.ResolverSettings{ URIs: []string{fileName}, Providers: makeMapProvidersMap(fileprovider.New(), envprovider.New(), yamlprovider.New(), httpprovider.New()), @@ -44,7 +44,7 @@ func LoadConfig(fileName string, factories component.Factories) (*service.Config } // LoadConfigAndValidate loads a config from the file, and validates the configuration. -func LoadConfigAndValidate(fileName string, factories component.Factories) (*service.Config, error) { +func LoadConfigAndValidate(fileName string, factories component.Factories) (*otelcol.Config, error) { cfg, err := LoadConfig(fileName, factories) if err != nil { return nil, err diff --git a/service/servicetest/configprovider_test.go b/otelcol/otelcoltest/config_test.go similarity index 99% rename from service/servicetest/configprovider_test.go rename to otelcol/otelcoltest/config_test.go index 2017853cb3f..0accfc07084 100644 --- a/service/servicetest/configprovider_test.go +++ b/otelcol/otelcoltest/config_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package servicetest +package otelcoltest import ( "path/filepath" diff --git a/service/servicetest/testdata/config.yaml b/otelcol/otelcoltest/testdata/config.yaml similarity index 100% rename from service/servicetest/testdata/config.yaml rename to otelcol/otelcoltest/testdata/config.yaml diff --git a/otelcol/testdata/otelcol-invalid.yaml b/otelcol/testdata/otelcol-invalid.yaml new file mode 100644 index 00000000000..133ce74d85b --- /dev/null +++ b/otelcol/testdata/otelcol-invalid.yaml @@ -0,0 +1,18 @@ +receivers: + nop: + +processors: + nop: + +exporters: + nop: + +service: + telemetry: + metrics: + address: localhost:8888 + pipelines: + traces: + receivers: [nop] + processors: [invalid] + exporters: [nop] diff --git a/otelcol/testdata/otelcol-nop.yaml b/otelcol/testdata/otelcol-nop.yaml new file mode 100644 index 00000000000..6780b937e13 --- /dev/null +++ b/otelcol/testdata/otelcol-nop.yaml @@ -0,0 +1,30 @@ +receivers: + nop: + +processors: + nop: + +exporters: + nop: + +extensions: + nop: + +service: + telemetry: + metrics: + address: localhost:8888 + extensions: [nop] + pipelines: + traces: + receivers: [nop] + processors: [nop] + exporters: [nop] + metrics: + receivers: [nop] + processors: [nop] + exporters: [nop] + logs: + receivers: [nop] + processors: [nop] + exporters: [nop] diff --git a/service/collector.go b/service/collector.go index acd10cb0613..6722fd7ea96 100644 --- a/service/collector.go +++ b/service/collector.go @@ -34,12 +34,17 @@ import ( ) // State defines Collector's state. +// Deprecated: [v0.67.0] use otelcol.State type State int const ( + // Deprecated: [v0.67.0] use otelcol.StateStarting StateStarting State = iota + // Deprecated: [v0.67.0] use otelcol.StateRunning StateRunning + // Deprecated: [v0.67.0] use otelcol.StateClosing StateClosing + // Deprecated: [v0.67.0] use otelcol.StateClosed StateClosed ) @@ -69,6 +74,7 @@ func (s State) String() string { // - Users can call (*Collector).Shutdown anytime to shut down the collector. // Collector represents a server providing the OpenTelemetry Collector service. +// Deprecated: [v0.67.0] use otelcol.Collector type Collector struct { set CollectorSettings @@ -86,6 +92,7 @@ type Collector struct { } // New creates and returns a new instance of Collector. +// Deprecated: [v0.67.0] use otelcol.New func New(set CollectorSettings) (*Collector, error) { if set.ConfigProvider == nil { return nil, errors.New("invalid nil config provider") diff --git a/service/collector_windows.go b/service/collector_windows.go index f429b6c29c0..c4ea72e18c6 100644 --- a/service/collector_windows.go +++ b/service/collector_windows.go @@ -40,6 +40,7 @@ type windowsService struct { } // NewSvcHandler constructs a new svc.Handler using the given CollectorSettings. +// Deprecated: [v0.67.0] use otelcol.NewSvcHandler func NewSvcHandler(set CollectorSettings) svc.Handler { return &windowsService{settings: set, flags: flags()} } diff --git a/service/config.go b/service/config.go index 2966209edb8..bf4f2692c53 100644 --- a/service/config.go +++ b/service/config.go @@ -30,7 +30,7 @@ var ( errMissingServicePipelineExporters = errors.New("must have at least one exporter") ) -// Config defines the configuration for the various elements of collector or agent. +// Deprecated: [v0.67.0] use otelcol.Config type Config struct { // Receivers is a map of ComponentID to Receivers. Receivers map[component.ID]component.Config diff --git a/service/config_provider.go b/service/config_provider.go index 3feba9741fe..ea9670acd17 100644 --- a/service/config_provider.go +++ b/service/config_provider.go @@ -37,6 +37,8 @@ import ( // cfgProvider.Watch() // wait for an event. // // repeat Get/Watch cycle until it is time to shut down the Collector process. // cfgProvider.Shutdown() +// +// Deprecated: [v0.67.0] use otelcol.ConfigProvider type ConfigProvider interface { // Get returns the service configuration, or error otherwise. // @@ -66,6 +68,7 @@ type configProvider struct { } // ConfigProviderSettings are the settings to configure the behavior of the ConfigProvider. +// Deprecated: [v0.67.0] use otelcol.ConfigProviderSettings type ConfigProviderSettings struct { // ResolverSettings are the settings to configure the behavior of the confmap.Resolver. ResolverSettings confmap.ResolverSettings @@ -87,6 +90,7 @@ func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings { // - Then applies all the confmap.Converter in the given order. // // * Then unmarshalls the confmap.Conf into the service Config. +// Deprecated: [v0.67.0] use otelcol.NewConfigProvider func NewConfigProvider(set ConfigProviderSettings) (ConfigProvider, error) { mr, err := confmap.NewResolver(set.ResolverSettings) if err != nil { diff --git a/service/servicetest/deprecated.go b/service/servicetest/deprecated.go new file mode 100644 index 00000000000..8991ea4bf99 --- /dev/null +++ b/service/servicetest/deprecated.go @@ -0,0 +1,11 @@ +package servicetest // import "go.opentelemetry.io/collector/service/servicetest" + +import ( + "go.opentelemetry.io/collector/otelcol/otelcoltest" +) + +// Deprecated: [v0.67.0] use otelcoltest.LoadConfig +var LoadConfig = otelcoltest.LoadConfig + +// Deprecated: [v0.67.0] use otelcoltest.LoadConfigAndValidate +var LoadConfigAndValidate = otelcoltest.LoadConfigAndValidate diff --git a/service/settings.go b/service/settings.go index 070d6911b0c..527880a1383 100644 --- a/service/settings.go +++ b/service/settings.go @@ -42,6 +42,7 @@ type settings struct { } // CollectorSettings holds configuration for creating a new Collector. +// Deprecated: [v0.66.0] use collector.Settings type CollectorSettings struct { // Factories component factories. Factories component.Factories