Skip to content

Commit

Permalink
Merge branch 'main' into validate-version-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket-0510 authored Feb 12, 2024
2 parents db1cb7b + de6287d commit ff7b6ff
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 65 deletions.
25 changes: 25 additions & 0 deletions .chloggen/remove_ReportFatalError.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove `host.ReportFatalError`

# One or more tracking issues or pull requests related to the change
issues: [6344]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
2 changes: 0 additions & 2 deletions component/componenttest/nop_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ func NewNopHost() component.Host {
return &nopHost{}
}

func (nh *nopHost) ReportFatalError(_ error) {}

func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions component/componenttest/nop_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package componenttest

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -18,7 +17,6 @@ func TestNewNopHost(t *testing.T) {
require.NotNil(t, nh)
require.IsType(t, &nopHost{}, nh)

nh.ReportFatalError(errors.New("TestError"))
assert.Nil(t, nh.GetExporters()) // nolint: staticcheck
assert.Nil(t, nh.GetExtensions())
assert.Nil(t, nh.GetFactory(component.KindReceiver, component.MustNewType("test")))
Expand Down
10 changes: 0 additions & 10 deletions component/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ package component // import "go.opentelemetry.io/collector/component"
// Host represents the entity that is hosting a Component. It is used to allow communication
// between the Component and its host (normally the service.Collector is the host).
type Host interface {
// ReportFatalError is used to report to the host that the component
// encountered a fatal error (i.e.: an error that the instance can't recover
// from) after its start function had already returned.
//
// ReportFatalError should be called by the component anytime after Component.Start() ends and
// before Component.Shutdown() begins.
// Deprecated: [0.87.0] Use TelemetrySettings.ReportComponentStatus instead (with an event
// component.StatusFatalError)
ReportFatalError(err error)

// GetFactory of the specified kind. Returns the factory for a component type.
// This allows components to create other components. For example:
// func (r MyReceiver) Start(host component.Host) error {
Expand Down
9 changes: 9 additions & 0 deletions exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexporter"

import (
"errors"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configretry"
Expand All @@ -19,4 +21,11 @@ type Config struct {
configgrpc.ClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
}

func (c *Config) Validate() error {
if c.SanitizedEndpoint() == "" {
return errors.New(`requires a non-empty "endpoint"`)
}
return nil
}

var _ component.Config = (*Config)(nil)
36 changes: 36 additions & 0 deletions exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,39 @@ func TestUnmarshalConfig(t *testing.T) {
},
}, cfg)
}

func TestUnmarshalInvalidConfig(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "invalid_configs.yaml"))
require.NoError(t, err)
factory := NewFactory()
for _, test := range []struct {
name string
errorMsg string
}{
{
name: "no_endpoint",
errorMsg: `requires a non-empty "endpoint"`,
},
{
name: "http_endpoint",
errorMsg: `requires a non-empty "endpoint"`,
},
{
name: "invalid_timeout",
errorMsg: `'timeout' must be non-negative`,
},
{
name: "invalid_retry",
errorMsg: `'randomization_factor' must be within [0, 1]`,
},
} {
t.Run(test.name, func(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub(test.name)
require.NoError(t, err)
assert.NoError(t, component.UnmarshalConfig(sub, cfg))
assert.ErrorContains(t, component.ValidateConfig(cfg), test.errorMsg)
})
}

}
15 changes: 3 additions & 12 deletions exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ func createTracesExporter(
set exporter.CreateSettings,
cfg component.Config,
) (exporter.Traces, error) {
oce, err := newExporter(cfg, set)
if err != nil {
return nil, err
}
oce := newExporter(cfg, set)
oCfg := cfg.(*Config)
return exporterhelper.NewTracesExporter(ctx, set, cfg,
oce.pushTraces,
Expand All @@ -68,10 +65,7 @@ func createMetricsExporter(
set exporter.CreateSettings,
cfg component.Config,
) (exporter.Metrics, error) {
oce, err := newExporter(cfg, set)
if err != nil {
return nil, err
}
oce := newExporter(cfg, set)
oCfg := cfg.(*Config)
return exporterhelper.NewMetricsExporter(ctx, set, cfg,
oce.pushMetrics,
Expand All @@ -89,10 +83,7 @@ func createLogsExporter(
set exporter.CreateSettings,
cfg component.Config,
) (exporter.Logs, error) {
oce, err := newExporter(cfg, set)
if err != nil {
return nil, err
}
oce := newExporter(cfg, set)
oCfg := cfg.(*Config)
return exporterhelper.NewLogsExporter(ctx, set, cfg,
oce.pushLogs,
Expand Down
20 changes: 3 additions & 17 deletions exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,10 @@ func TestCreateMetricsExporter(t *testing.T) {
func TestCreateTracesExporter(t *testing.T) {
endpoint := testutil.GetAvailableLocalAddress(t)
tests := []struct {
name string
config *Config
mustFailOnCreate bool
mustFailOnStart bool
name string
config *Config
mustFailOnStart bool
}{
{
name: "NoEndpoint",
config: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: "",
},
},
mustFailOnCreate: true,
},
{
name: "UseSecure",
config: &Config{
Expand Down Expand Up @@ -178,10 +168,6 @@ func TestCreateTracesExporter(t *testing.T) {
factory := NewFactory()
set := exportertest.NewNopCreateSettings()
consumer, err := factory.CreateTracesExporter(context.Background(), set, tt.config)
if tt.mustFailOnCreate {
assert.NotNil(t, err)
return
}
assert.NoError(t, err)
assert.NotNil(t, consumer)
err = consumer.Start(context.Background(), componenttest.NewNopHost())
Expand Down
9 changes: 2 additions & 7 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexpor

import (
"context"
"errors"
"fmt"
"runtime"
"time"
Expand Down Expand Up @@ -47,17 +46,13 @@ type baseExporter struct {
userAgent string
}

func newExporter(cfg component.Config, set exporter.CreateSettings) (*baseExporter, error) {
func newExporter(cfg component.Config, set exporter.CreateSettings) *baseExporter {
oCfg := cfg.(*Config)

if oCfg.Endpoint == "" {
return nil, errors.New("OTLP exporter config requires an Endpoint")
}

userAgent := fmt.Sprintf("%s/%s (%s/%s)",
set.BuildInfo.Description, set.BuildInfo.Version, runtime.GOOS, runtime.GOARCH)

return &baseExporter{config: oCfg, settings: set.TelemetrySettings, userAgent: userAgent}, nil
return &baseExporter{config: oCfg, settings: set.TelemetrySettings, userAgent: userAgent}
}

// start actually creates the gRPC connection. The client construction is deferred till this point as this
Expand Down
55 changes: 55 additions & 0 deletions exporter/otlpexporter/testdata/invalid_configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
no_endpoint:
timeout: 10s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 10
retry_on_failure:
enabled: true
initial_interval: 10s
randomization_factor: 0.7
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
http_endpoint:
endpoint: http://
timeout: 10s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 10
retry_on_failure:
enabled: true
initial_interval: 10s
randomization_factor: 0.7
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
invalid_timeout:
endpoint: example.com:443
timeout: -5s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 10
retry_on_failure:
enabled: true
initial_interval: 10s
randomization_factor: 0.7
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
invalid_retry:
endpoint: example.com:443
timeout: 30s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 10
retry_on_failure:
enabled: true
initial_interval: 10s
randomization_factor: -5
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
2 changes: 1 addition & 1 deletion extension/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Client interface {
PerRPCCredentials() (credentials.PerRPCCredentials, error)
}

// ClientOption represents the possible options for NewServerAuthenticator.
// ClientOption represents the possible options for NewClient.
type ClientOption func(*defaultClient)

// ClientRoundTripperFunc specifies the function that returns a RoundTripper that can be used to authenticate HTTP requests.
Expand Down
4 changes: 2 additions & 2 deletions extension/extensiontest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type nopConfig struct{}

var nopInstance = &nopExtension{}

// nopExtension stores consumed traces and metrics for testing purposes.
// nopExtension acts as an extension for testing purposes.
type nopExtension struct {
component.StartFunc
component.ShutdownFunc
}

// NewNopBuilder returns a extension.Builder that constructs nop receivers.
// NewNopBuilder returns a extension.Builder that constructs nop extension.
func NewNopBuilder() *extension.Builder {
nopFactory := NewNopFactory()
return extension.NewBuilder(
Expand Down
6 changes: 3 additions & 3 deletions processor/processortest/nop_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var nopType = component.MustNewType("nop")

// NewNopCreateSettings returns a new nop settings for Create* functions.
// NewNopCreateSettings returns a new nop settings for Create*Processor functions.
func NewNopCreateSettings() processor.CreateSettings {
return processor.CreateSettings{
ID: component.NewID(nopType),
Expand Down Expand Up @@ -53,14 +53,14 @@ var nopInstance = &nopProcessor{
Consumer: consumertest.NewNop(),
}

// nopProcessor stores consumed traces and metrics for testing purposes.
// nopProcessor acts as a processor for testing purposes.
type nopProcessor struct {
component.StartFunc
component.ShutdownFunc
consumertest.Consumer
}

// NewNopBuilder returns a processor.Builder that constructs nop receivers.
// NewNopBuilder returns a processor.Builder that constructs nop processors.
func NewNopBuilder() *processor.Builder {
nopFactory := NewNopFactory()
return processor.NewBuilder(
Expand Down
4 changes: 2 additions & 2 deletions receiver/receivertest/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

var componentType = component.MustNewType("nop")

// NewNopCreateSettings returns a new nop settings for Create* functions.
// NewNopCreateSettings returns a new nop settings for Create*Receiver functions.
func NewNopCreateSettings() receiver.CreateSettings {
return receiver.CreateSettings{
ID: component.NewID(componentType),
Expand Down Expand Up @@ -49,7 +49,7 @@ type nopConfig struct{}

var nopInstance = &nopReceiver{}

// nopReceiver stores consumed traces and metrics for testing purposes.
// nopReceiver acts as a receiver for testing purposes.
type nopReceiver struct {
component.StartFunc
component.ShutdownFunc
Expand Down
7 changes: 0 additions & 7 deletions service/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ type serviceHost struct {
serviceExtensions *extensions.Extensions
}

// ReportFatalError is used to report to the host that the receiver encountered
// a fatal error (i.e.: an error that the instance can't recover from) after
// its start function has already returned.
// Deprecated: [0.87.0] Replaced by servicetelemetry.Settings.ReportComponentStatus
func (host *serviceHost) ReportFatalError(err error) {
host.asyncErrorChannel <- err
}
func (host *serviceHost) GetFactory(kind component.Kind, componentType component.Type) component.Factory {
switch kind {
case component.KindReceiver:
Expand Down

0 comments on commit ff7b6ff

Please sign in to comment.