Skip to content

Commit

Permalink
Merge branch 'main' into mvscrapererr
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdandrutu authored Mar 6, 2021
2 parents b189316 + 68871bd commit efa59ab
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 167 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

## 🛑 Breaking changes 🛑

- Rename ServiceExtension to just Extension (#2581)
- Remove `consumerdata.TraceData` (#2551)
- Move `consumerdata.MetricsData` to `internaldata.MetricsData` (#2512)
- Remove custom OpenCensus sematic conventions that have equivalent in otel (#2552)
- Move ScrapeErrors and PartialScrapeError to `scrapererror` (#2580)
- Remove support for deprecated unmarshaler `CustomUnmarshaler`, only `Unmarshal` is supported (#2591)
- Remove deprecated componenterror.CombineErrors (#2598)

## v0.21.0 Beta
Expand Down
41 changes: 41 additions & 0 deletions component/application_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 component

// ApplicationStartInfo is the information that is logged at the application start and
// passed into each component. This information can be overridden in custom builds.
type ApplicationStartInfo struct {
// Executable file name, e.g. "otelcol".
ExeName string

// Long name, used e.g. in the logs.
LongName string

// Version string.
Version string

// Git hash of the source code.
GitHash string
}

// DefaultApplicationStartInfo returns the default ApplicationStartInfo.
func DefaultApplicationStartInfo() ApplicationStartInfo {
return ApplicationStartInfo{
ExeName: "otelcol",
LongName: "OpenTelemetry Collector",
Version: "latest",
GitHash: "<NOT PROPERLY GENERATED>",
}
}
20 changes: 2 additions & 18 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type Host interface {
// Typically is used to find an extension by type or by full config name. Both cases
// can be done by iterating the returned map. There are typically very few extensions
// so there there is no performance implications due to iteration.
GetExtensions() map[configmodels.Extension]ServiceExtension
GetExtensions() map[configmodels.NamedEntity]Extension

// Return map of exporters. Only enabled and created exporters will be returned.
// Typically is used to find exporters by type or by full config name. Both cases
Expand All @@ -92,7 +92,7 @@ type Host interface {
// Note that an exporter with the same name may be attached to multiple pipelines and
// thus we may have an instance of the exporter for multiple data types.
// This is an experimental function that may change or even be removed completely.
GetExporters() map[configmodels.DataType]map[configmodels.Exporter]Exporter
GetExporters() map[configmodels.DataType]map[configmodels.NamedEntity]Exporter
}

// Factory interface must be implemented by all component factories.
Expand All @@ -119,19 +119,3 @@ type ConfigUnmarshaler interface {
// intoCfg interface{}
// An empty interface wrapping a pointer to the config struct to unmarshal into.
type CustomUnmarshaler func(componentViperSection *viper.Viper, intoCfg interface{}) error

// ApplicationStartInfo is the information that is logged at the application start and
// passed into each component. This information can be overridden in custom builds.
type ApplicationStartInfo struct {
// Executable file name, e.g. "otelcol".
ExeName string

// Long name, used e.g. in the logs.
LongName string

// Version string.
Version string

// Git hash of the source code.
GitHash string
}
29 changes: 0 additions & 29 deletions component/componenttest/application_start_info.go

This file was deleted.

4 changes: 2 additions & 2 deletions component/componenttest/error_waiting_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func (ews *ErrorWaitingHost) GetFactory(_ component.Kind, _ configmodels.Type) c
return nil
}

func (ews *ErrorWaitingHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension {
func (ews *ErrorWaitingHost) GetExtensions() map[configmodels.NamedEntity]component.Extension {
return nil
}

func (ews *ErrorWaitingHost) GetExporters() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter {
func (ews *ErrorWaitingHost) GetExporters() map[configmodels.DataType]map[configmodels.NamedEntity]component.Exporter {
return nil
}
15 changes: 4 additions & 11 deletions component/componenttest/example_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ func (f *ExampleReceiverFactory) CreateDefaultConfig() configmodels.Receiver {
}
}

// CustomUnmarshaler implements the deprecated way to provide custom unmarshalers.
func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler {
return nil
}

// CreateTraceReceiver creates a trace receiver based on this config.
func (f *ExampleReceiverFactory) CreateTracesReceiver(
_ context.Context,
Expand Down Expand Up @@ -280,11 +275,9 @@ func (f *ExampleExporterFactory) CreateDefaultConfig() configmodels.Exporter {
}
}

// CustomUnmarshaler implements the deprecated way to provide custom unmarshalers.
func (f *ExampleExporterFactory) CustomUnmarshaler() component.CustomUnmarshaler {
return func(componentViperSection *viper.Viper, intoCfg interface{}) error {
return componentViperSection.UnmarshalExact(intoCfg)
}
// Unmarshal implements the custom unmarshalers.
func (f *ExampleExporterFactory) Unmarshal(componentViperSection *viper.Viper, intoCfg interface{}) error {
return componentViperSection.UnmarshalExact(intoCfg)
}

// CreateTracesExporter creates a trace exporter based on this config.
Expand Down Expand Up @@ -473,7 +466,7 @@ func (f *ExampleExtensionFactory) CreateDefaultConfig() configmodels.Extension {
}

// CreateExtension creates an Extension based on this config.
func (f *ExampleExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.ServiceExtension, error) {
func (f *ExampleExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.Extension, error) {
if f.FailCreation {
return nil, fmt.Errorf("cannot create %q extension type", f.Type())
}
Expand Down
4 changes: 2 additions & 2 deletions component/componenttest/nop_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func (nh *nopHost) GetFactory(_ component.Kind, _ configmodels.Type) component.F
return nil
}

func (nh *nopHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension {
func (nh *nopHost) GetExtensions() map[configmodels.NamedEntity]component.Extension {
return nil
}

func (nh *nopHost) GetExporters() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter {
func (nh *nopHost) GetExporters() map[configmodels.DataType]map[configmodels.NamedEntity]component.Exporter {
return nil
}
14 changes: 7 additions & 7 deletions component/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ import (
"go.opentelemetry.io/collector/config/configmodels"
)

// ServiceExtension is the interface for objects hosted by the OpenTelemetry Collector that
// Extension is the interface for objects hosted by the OpenTelemetry Collector that
// don't participate directly on data pipelines but provide some functionality
// to the service, examples: health check endpoint, z-pages, etc.
type ServiceExtension interface {
type Extension interface {
Component
}

// PipelineWatcher is an extra interface for ServiceExtension hosted by the OpenTelemetry
// PipelineWatcher is an extra interface for Extension hosted by the OpenTelemetry
// Collector that is to be implemented by extensions interested in changes to pipeline
// states. Typically this will be used by extensions that change their behavior if data is
// being ingested or not, e.g.: a k8s readiness probe.
type PipelineWatcher interface {
// Ready notifies the ServiceExtension that all pipelines were built and the
// Ready notifies the Extension that all pipelines were built and the
// receivers were started, i.e.: the service is ready to receive data
// (notice that it may already have received data when this method is called).
Ready() error

// NotReady notifies the ServiceExtension that all receivers are about to be stopped,
// NotReady notifies the Extension that all receivers are about to be stopped,
// i.e.: pipeline receivers will not accept new data.
// This is sent before receivers are stopped, so the ServiceExtension can take any
// This is sent before receivers are stopped, so the Extension can take any
// appropriate action before that happens.
NotReady() error
}
Expand Down Expand Up @@ -70,5 +70,5 @@ type ExtensionFactory interface {
CreateDefaultConfig() configmodels.Extension

// CreateExtension creates a service extension based on the given config.
CreateExtension(ctx context.Context, params ExtensionCreateParams, cfg configmodels.Extension) (ServiceExtension, error)
CreateExtension(ctx context.Context, params ExtensionCreateParams, cfg configmodels.Extension) (Extension, error)
}
16 changes: 0 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ type pipelineSettings struct {
Exporters []string `mapstructure:"exporters"`
}

// deprecatedUnmarshaler is the old/deprecated way to provide custom unmarshaler.
type deprecatedUnmarshaler interface {
// CustomUnmarshaler returns a custom unmarshaler for the configuration or nil if
// there is no need for custom unmarshaling. This is typically used if viper.UnmarshalExact()
// is not sufficient to unmarshal correctly.
CustomUnmarshaler() component.CustomUnmarshaler
}

// typeAndNameSeparator is the separator that is used between type and name in type/name composite keys.
const typeAndNameSeparator = "/"

Expand Down Expand Up @@ -736,14 +728,6 @@ func unmarshaler(factory component.Factory) component.CustomUnmarshaler {
if fu, ok := factory.(component.ConfigUnmarshaler); ok {
return fu.Unmarshal
}

if du, ok := factory.(deprecatedUnmarshaler); ok {
cu := du.CustomUnmarshaler()
if cu != nil {
return cu
}
}

return defaultUnmarshaler
}

Expand Down
2 changes: 1 addition & 1 deletion config/configcheck/configcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ func (b badConfigExtensionFactory) CreateDefaultConfig() configmodels.Extension
}{}
}

func (b badConfigExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.ServiceExtension, error) {
func (b badConfigExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.Extension, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions extension/extensionhelper/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type FactoryOption func(o *factory)
type CreateDefaultConfig func() configmodels.Extension

// CreateServiceExtension is the equivalent of component.ExtensionFactory.CreateExtension()
type CreateServiceExtension func(context.Context, component.ExtensionCreateParams, configmodels.Extension) (component.ServiceExtension, error)
type CreateServiceExtension func(context.Context, component.ExtensionCreateParams, configmodels.Extension) (component.Extension, error)

type factory struct {
cfgType configmodels.Type
Expand Down Expand Up @@ -83,7 +83,7 @@ func (f *factory) CreateDefaultConfig() configmodels.Extension {
func (f *factory) CreateExtension(
ctx context.Context,
params component.ExtensionCreateParams,
cfg configmodels.Extension) (component.ServiceExtension, error) {
cfg configmodels.Extension) (component.Extension, error) {
return f.createServiceExtension(ctx, params, cfg)
}

Expand Down
2 changes: 1 addition & 1 deletion extension/extensionhelper/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func defaultConfig() configmodels.Extension {
return defaultCfg
}

func createExtension(context.Context, component.ExtensionCreateParams, configmodels.Extension) (component.ServiceExtension, error) {
func createExtension(context.Context, component.ExtensionCreateParams, configmodels.Extension) (component.Extension, error) {
return nopExtensionInstance, nil
}

Expand Down
2 changes: 1 addition & 1 deletion extension/fluentbitextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func createDefaultConfig() configmodels.Extension {
}
}

func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.ServiceExtension, error) {
func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.Extension, error) {
config := cfg.(*Config)
return newProcessManager(config, params.Logger), nil
}
2 changes: 1 addition & 1 deletion extension/healthcheckextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func createDefaultConfig() configmodels.Extension {
}
}

func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.ServiceExtension, error) {
func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.Extension, error) {
config := cfg.(*Config)

// The runtime settings are global to the application, so while in principle it
Expand Down
2 changes: 1 addition & 1 deletion extension/pprofextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func createDefaultConfig() configmodels.Extension {
}
}

func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.ServiceExtension, error) {
func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.Extension, error) {
config := cfg.(*Config)
if config.Endpoint == "" {
return nil, errors.New("\"endpoint\" is required when using the \"pprof\" extension")
Expand Down
2 changes: 1 addition & 1 deletion extension/zpagesextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func createDefaultConfig() configmodels.Extension {
}

// createExtension creates the extension based on this config.
func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.ServiceExtension, error) {
func createExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.Extension, error) {
config := cfg.(*Config)
if config.Endpoint == "" {
return nil, errors.New("\"endpoint\" is required when using the \"zpages\" extension")
Expand Down
10 changes: 5 additions & 5 deletions service/builder/exporters_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func (exps Exporters) ShutdownAll(ctx context.Context) error {
return consumererror.CombineErrors(errs)
}

func (exps Exporters) ToMapByDataType() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter {
func (exps Exporters) ToMapByDataType() map[configmodels.DataType]map[configmodels.NamedEntity]component.Exporter {

exportersMap := make(map[configmodels.DataType]map[configmodels.Exporter]component.Exporter)
exportersMap := make(map[configmodels.DataType]map[configmodels.NamedEntity]component.Exporter)

exportersMap[configmodels.TracesDataType] = make(map[configmodels.Exporter]component.Exporter, len(exps))
exportersMap[configmodels.MetricsDataType] = make(map[configmodels.Exporter]component.Exporter, len(exps))
exportersMap[configmodels.LogsDataType] = make(map[configmodels.Exporter]component.Exporter, len(exps))
exportersMap[configmodels.TracesDataType] = make(map[configmodels.NamedEntity]component.Exporter, len(exps))
exportersMap[configmodels.MetricsDataType] = make(map[configmodels.NamedEntity]component.Exporter, len(exps))
exportersMap[configmodels.LogsDataType] = make(map[configmodels.NamedEntity]component.Exporter, len(exps))

for cfg, bexp := range exps {
for t, exp := range bexp.expByDataType {
Expand Down
10 changes: 5 additions & 5 deletions service/builder/exporters_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestExportersBuilder_Build(t *testing.T) {
},
}

exporters, err := NewExportersBuilder(zap.NewNop(), componenttest.TestApplicationStartInfo(), cfg, factories.Exporters).Build()
exporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build()

assert.NoError(t, err)
require.NotNil(t, exporters)
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestExportersBuilder_Build(t *testing.T) {
// This should result in creating an exporter that has none of consumption
// functions set.
delete(cfg.Service.Pipelines, "trace")
exporters, err = NewExportersBuilder(zap.NewNop(), componenttest.TestApplicationStartInfo(), cfg, factories.Exporters).Build()
exporters, err = NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build()
assert.NotNil(t, exporters)
assert.NoError(t, err)

Expand Down Expand Up @@ -131,7 +131,7 @@ func TestExportersBuilder_BuildLogs(t *testing.T) {
},
}

exporters, err := NewExportersBuilder(zap.NewNop(), componenttest.TestApplicationStartInfo(), cfg, factories.Exporters).Build()
exporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build()

assert.NoError(t, err)
require.NotNil(t, exporters)
Expand All @@ -156,7 +156,7 @@ func TestExportersBuilder_BuildLogs(t *testing.T) {
// This should result in creating an exporter that has none of consumption
// functions set.
delete(cfg.Service.Pipelines, "logs")
exporters, err = NewExportersBuilder(zap.NewNop(), componenttest.TestApplicationStartInfo(), cfg, factories.Exporters).Build()
exporters, err = NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build()
assert.NotNil(t, exporters)
assert.Nil(t, err)

Expand Down Expand Up @@ -260,7 +260,7 @@ func TestExportersBuilder_ErrorOnNilExporter(t *testing.T) {
},
}

exporters, err := NewExportersBuilder(zap.NewNop(), componenttest.TestApplicationStartInfo(), cfg, fm).Build()
exporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, fm).Build()
assert.Error(t, err)
assert.Zero(t, len(exporters))
})
Expand Down
Loading

0 comments on commit efa59ab

Please sign in to comment.