Skip to content

Commit

Permalink
Instrument obsreport.Processor (#6607)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
moh-osman3 authored and bogdandrutu committed Dec 5, 2022
1 parent c049580 commit becf08f
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 17 deletions.
22 changes: 22 additions & 0 deletions .chloggen/depcollector.yaml
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//go:build windows
// +build windows

package service
package otelcol

import (
"os"
Expand All @@ -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)
Expand Down
20 changes: 15 additions & 5 deletions service/command_test.go → otelcol/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,28 +23,38 @@ 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)
}

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())
}

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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package service
package otelcol

import (
"context"
Expand All @@ -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"
)

Expand All @@ -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")},
Expand Down
69 changes: 69 additions & 0 deletions otelcol/moved.go
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions otelcol/moved_windows.go
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions otelcol/testdata/otelcol-invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
receivers:
nop:

processors:
nop:

exporters:
nop:

service:
telemetry:
metrics:
address: localhost:8888
pipelines:
traces:
receivers: [nop]
processors: [invalid]
exporters: [nop]
30 changes: 30 additions & 0 deletions otelcol/testdata/otelcol-nop.yaml
Original file line number Diff line number Diff line change
@@ -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]
7 changes: 7 additions & 0 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions service/collector_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
}
Expand Down
2 changes: 1 addition & 1 deletion service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions service/servicetest/deprecated.go
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit becf08f

Please sign in to comment.