Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sub command to generate sample configuration for the collector #5943

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- Expose `AsRaw` and `FromRaw` `pcommon.Value` methods (#6090)
- Convert `ValueTypeBytes` attributes in logging exporter (#6153)
- Updated how `telemetryInitializer` is created so it's instanced per Collector instance rather than global to the process (#6138)
- Add subcommand `config` which returns a sample configuration for the given components (#5943)

## v0.60.0 Beta

Expand Down Expand Up @@ -96,7 +97,7 @@
### 💡 Enhancements 💡

- Add `skip-get-modules` builder flag to support isolated environment executions (#6009)
- Skip unnecessary Go binary path validation when the builder is used with `skip-compilation` and `skip-get-modules` flags (#6026)
- Skip unnecessary Go binary path validation when the builder is used with `skip-compilation` and `skip-get-modules` flags (#6026)
- Make the otlpreceiver support to use jsoniter to unmarshal JSON payloads. (#6040)
- Add mapstructure hook function for confmap.Unmarshaler interface (#6029)
- Add CopyTo and MoveTo methods to primitive slices (#6044)
Expand Down
15 changes: 12 additions & 3 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ require (
)

require (
cloud.google.com/go/compute v1.8.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
github.com/AlecAivazis/survey/v2 v2.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
Expand All @@ -27,13 +29,18 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.15.10 // indirect
github.com/knadh/koanf v1.4.3 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
Expand Down Expand Up @@ -70,11 +77,13 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
59 changes: 41 additions & 18 deletions cmd/otelcorecol/go.sum

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,24 @@ type Factory interface {
// Type gets the type of the component created by this factory.
Type() config.Type

// SampleConfig returns a sample configuration defined for this component.
// Authors must ensure to return a valid YAML string which minimally represents a valid Configuration
// for the component.
SampleConfig() string

unexportedFactoryFunc()
}

type baseFactory struct {
cfgType config.Type
cfgType config.Type
sampleConfig string
}

func (baseFactory) unexportedFactoryFunc() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this won't cause backward compatibility issues because we are forcing implementations to embed the base factory, right?


func (bf baseFactory) Type() config.Type {
return bf.cfgType
}
func (bf baseFactory) SampleConfig() string {
return bf.sampleConfig
}
7 changes: 7 additions & 0 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func (e exporterFactory) LogsExporterStability() StabilityLevel {
return e.logsStabilityLevel
}

// WithExporterSampleConfig sets the configuration string for the exporter factory type.
func WithExporterSampleConfig(yamlConfig string) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.baseFactory.sampleConfig = yamlConfig
})
}

// WithTracesExporter overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level.
func WithTracesExporter(createTracesExporter CreateTracesExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
Expand Down
31 changes: 29 additions & 2 deletions component/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ type ExtensionFactory interface {
ExtensionStability() StabilityLevel
}

type ExtensionFactoryOption interface {
// applyExtensionFactoryOption applies the option.
applyExtensionFactoryOption(o *extensionFactory)
}

var _ ExtensionFactoryOption = (*extensionFactoryOptionFunc)(nil)

// extensionFactoryOptionFunc is an ExtensionFactoryOption created through a function.
type extensionFactoryOptionFunc func(*extensionFactory)

func (f extensionFactoryOptionFunc) applyExtensionFactoryOption(o *extensionFactory) {
f(o)
}

type extensionFactory struct {
baseFactory
ExtensionCreateDefaultConfigFunc
Expand All @@ -99,16 +113,29 @@ func (ef *extensionFactory) ExtensionStability() StabilityLevel {
return ef.extensionStability
}

// WithExtensionSampleConfig sets the configuration string for the Extension factory type.
func WithExtensionSampleConfig(yamlConfig string) ExtensionFactoryOption {
return extensionFactoryOptionFunc(func(o *extensionFactory) {
o.baseFactory.sampleConfig = yamlConfig
})
}

// NewExtensionFactory returns a new ExtensionFactory based on this configuration.
func NewExtensionFactory(
cfgType config.Type,
createDefaultConfig ExtensionCreateDefaultConfigFunc,
createServiceExtension CreateExtensionFunc,
sl StabilityLevel) ExtensionFactory {
return &extensionFactory{
sl StabilityLevel, options ...ExtensionFactoryOption) ExtensionFactory {
ext := &extensionFactory{
baseFactory: baseFactory{cfgType: cfgType},
ExtensionCreateDefaultConfigFunc: createDefaultConfig,
CreateExtensionFunc: createServiceExtension,
extensionStability: sl,
}

for _, opt := range options {
opt.applyExtensionFactoryOption(ext)
}

return ext
}
7 changes: 7 additions & 0 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func (p processorFactory) LogsProcessorStability() StabilityLevel {
return p.logsStabilityLevel
}

// WithProcessorSampleConfig sets the configuration string for the processor factory type.
func WithProcessorSampleConfig(yamlConfig string) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.baseFactory.sampleConfig = yamlConfig
})
}

// WithTracesProcessor overrides the default "error not supported" implementation for CreateTracesProcessor and the default "undefined" stability level.
func WithTracesProcessor(createTracesProcessor CreateTracesProcessorFunc, sl StabilityLevel) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
Expand Down
7 changes: 7 additions & 0 deletions component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ func (r receiverFactory) LogsReceiverStability() StabilityLevel {
return r.logsStabilityLevel
}

// WithReceiverSampleConfig sets the configuration string for the receiver factory type.
func WithReceiverSampleConfig(yamlConfig string) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.baseFactory.sampleConfig = yamlConfig
})
}

// WithTracesReceiver overrides the default "error not supported" implementation for CreateTracesReceiver and the default "undefined" stability level.
func WithTracesReceiver(createTracesReceiver CreateTracesReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
Expand Down
5 changes: 5 additions & 0 deletions exporter/loggingexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package loggingexporter // import "go.opentelemetry.io/collector/exporter/loggin

import (
"context"
_ "embed"
"time"

"go.uber.org/zap"
Expand All @@ -34,6 +35,9 @@ const (
defaultSamplingThereafter = 500
)

//go:embed logging.sample.yaml
var sampleConfig string

// NewFactory creates a factory for Logging exporter
func NewFactory() component.ExporterFactory {
return component.NewExporterFactory(
Expand All @@ -42,6 +46,7 @@ func NewFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter, component.StabilityLevelInDevelopment),
component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelInDevelopment),
component.WithLogsExporter(createLogsExporter, component.StabilityLevelInDevelopment),
component.WithExporterSampleConfig(sampleConfig),
)
}

Expand Down
7 changes: 7 additions & 0 deletions exporter/loggingexporter/logging.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
logging:
# LogLevel defines log level of the logging exporter; options are debug, info, warn, error.
loglevel: 0
# SamplingInitial defines how many samples are initially logged during each second.
sampling_initial: 2
# SamplingThereafter defines the sampling rate after the initial samples are logged.
sampling_thereafter: 500
5 changes: 5 additions & 0 deletions exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexpor

import (
"context"
_ "embed"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
Expand All @@ -30,6 +31,9 @@ const (
typeStr = "otlp"
)

//go:embed otlp.sample.yaml
var sampleConfig string

// NewFactory creates a factory for OTLP exporter.
func NewFactory() component.ExporterFactory {
return component.NewExporterFactory(
Expand All @@ -38,6 +42,7 @@ func NewFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable),
component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable),
component.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta),
component.WithExporterSampleConfig(sampleConfig),
)
}

Expand Down
30 changes: 30 additions & 0 deletions exporter/otlpexporter/otlp.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
otlp:
# Timeout is the timeout for every attempt to send data to the backend.
timeout: 5s
# The target to which the exporter is going to send traces or metrics,
# using the gRPC protocol. The valid syntax is described at
# https://github.com/grpc/grpc/blob/master/doc/naming.md.
endpoint: "otel-collector.default:4317"
# The compression key for supported compression types within collector.
compression: gzip
# TLSSetting struct exposes TLS client configuration.
tls:
# Path to the CA cert. For a client this verifies the server certificate.
# For a server this verifies client certificates. If empty uses system root CA.
# (optional)
ca_file: "/path/to/ca"
# Path to the TLS cert to use for TLS required connections. (optional)
cert_file: "/path/to/cert"
# Path to the TLS key to use for TLS required connections. (optional)
key_file: "/path/to/key"
# In gRPC when set to true, this is used to disable the client transport security.
# See https://godoc.org/google.golang.org/grpc#WithInsecure.
# In HTTP, this disables verifying the server's certificate chain and host name
# (InsecureSkipVerify in the tls Config). Please refer to
# https://godoc.org/crypto/tls#Config for more information.
# (optional, default false)
insecure: false
# InsecureSkipVerify will enable TLS but not verify the certificate.
insecure_skip_verify: false
# The headers associated with gRPC requests.
headers: null
5 changes: 5 additions & 0 deletions exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package otlphttpexporter // import "go.opentelemetry.io/collector/exporter/otlph

import (
"context"
_ "embed"
"fmt"
"net/url"
"time"
Expand All @@ -33,6 +34,9 @@ const (
typeStr = "otlphttp"
)

//go:embed otlphttp.sample.yaml
var sampleConfig string

// NewFactory creates a factory for OTLP exporter.
func NewFactory() component.ExporterFactory {
return component.NewExporterFactory(
Expand All @@ -41,6 +45,7 @@ func NewFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable),
component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable),
component.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta),
component.WithExporterSampleConfig(sampleConfig),
)
}

Expand Down
29 changes: 29 additions & 0 deletions exporter/otlphttpexporter/otlphttp.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
otlphttp:
# The target URL to send data to (e.g.: http://some.url:9411/v1/traces).
endpoint: "localhost:3333"
# TLSSetting struct exposes TLS client configuration.
tls:
# Path to the CA cert. For a client this verifies the server certificate.
# For a server this verifies client certificates. If empty uses system root CA.
# (optional)
ca_file: "/path/to/ca"
# Path to the TLS cert to use for TLS required connections. (optional)
cert_file: "/path/to/cert"
# Path to the TLS key to use for TLS required connections. (optional)
key_file: "/path/to/key"
# In HTTP, this disables verifying the server's certificate chain and host name
# (InsecureSkipVerify in the tls Config). Please refer to
# https://godoc.org/crypto/tls#Config for more information.
# (optional, default false)
insecure: false
# InsecureSkipVerify will enable TLS but not verify the certificate.
insecure_skip_verify: false
# Timeout parameter configures `http.Client.Timeout`.
timeout: 30s
# Additional headers attached to each HTTP request sent by the client.
# Existing header values are overwritten if collision happens.
headers: null
# The compression key for supported compression types within collector.
compression: gzip
# The URL to send metrics to. If omitted the Endpoint + "/v1/metrics" will be used.
metrics_endpoint: "/api/v2/metrics/consume"
11 changes: 10 additions & 1 deletion extension/ballastextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ballastextension // import "go.opentelemetry.io/collector/extension/ball

import (
"context"
_ "embed"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
Expand All @@ -27,12 +28,20 @@ const (
typeStr = "memory_ballast"
)

//go:embed memoryballast.sample.yaml
var sampleConfig string

// memHandler returns the total memory of the target host/vm
var memHandler = iruntime.TotalMemory

// NewFactory creates a factory for FluentBit extension.
func NewFactory() component.ExtensionFactory {
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
return component.NewExtensionFactory(
typeStr,
createDefaultConfig,
createExtension,
component.StabilityLevelBeta,
component.WithExtensionSampleConfig(sampleConfig))
}

func createDefaultConfig() config.Extension {
Expand Down
7 changes: 7 additions & 0 deletions extension/ballastextension/memoryballast.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
memory_ballast:
# SizeMiB is the size, in MiB, of the memory ballast
# to be created for this process.
size_mib: 500
# SizeInPercentage is the maximum amount of memory ballast, in %, targeted to be
# allocated. The fixed memory settings SizeMiB has a higher precedence.
size_in_percentage: 50
12 changes: 11 additions & 1 deletion extension/zpagesextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package zpagesextension // import "go.opentelemetry.io/collector/extension/zpage

import (
"context"
_ "embed"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
Expand All @@ -29,9 +30,18 @@ const (
defaultEndpoint = "localhost:55679"
)

//go:embed zpages.sample.yaml
var sampleConfig string

// NewFactory creates a factory for Z-Pages extension.
func NewFactory() component.ExtensionFactory {
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
return component.NewExtensionFactory(
typeStr,
createDefaultConfig,
createExtension,
component.StabilityLevelBeta,
component.WithExtensionSampleConfig(sampleConfig),
)
}

func createDefaultConfig() config.Extension {
Expand Down
Loading