Skip to content

Commit

Permalink
[exporter/zipkin] use confighttp.DefaultHTTPClientSettings (open-tele…
Browse files Browse the repository at this point in the history
…metry#29931)

**Description:**
Modernize the logic of validation by moving to config Validate from the
Start function
Use the HTTPClientDefaultSettings defaults when setting the config.

**Link to tracking Issue:**
open-telemetry#6641

**Testing:**
Updated tests.
  • Loading branch information
atoulme authored and cparkins committed Jan 10, 2024
1 parent 3373b56 commit e96ba3d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
27 changes: 27 additions & 0 deletions .chloggen/zipkinexporter_clientsettings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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. filelogreceiver)
component: zipkinexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use default client HTTP settings in zipkinexporter, move validation to config validation

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [29931]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: []
5 changes: 5 additions & 0 deletions exporter/zipkinexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package zipkinexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter"

import (
"errors"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand All @@ -27,5 +29,8 @@ var _ component.Config = (*Config)(nil)

// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {
if cfg.HTTPClientSettings.Endpoint == "" {
return errors.New("endpoint required")
}
return nil
}
4 changes: 4 additions & 0 deletions exporter/zipkinexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestLoadConfig(t *testing.T) {
// URL doesn't have a default value so set it directly.
defaultCfg := createDefaultConfig().(*Config)
defaultCfg.Endpoint = "http://some.location.org:9411/api/v2/spans"
maxIdleConns := 50
idleConnTimeout := 5 * time.Second

tests := []struct {
id component.ID
Expand Down Expand Up @@ -61,6 +63,8 @@ func TestLoadConfig(t *testing.T) {
TLSSetting: configtls.TLSClientSetting{
InsecureSkipVerify: true,
},
MaxIdleConns: &maxIdleConns,
IdleConnTimeout: &idleConnTimeout,
},
Format: "proto",
DefaultServiceName: "test_name",
Expand Down
19 changes: 6 additions & 13 deletions exporter/zipkinexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package zipkinexporter // import "github.com/open-telemetry/opentelemetry-collec

import (
"context"
"errors"
"time"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -33,14 +32,13 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
defaultClientHTTPSettings := confighttp.NewDefaultHTTPClientSettings()
defaultClientHTTPSettings.Timeout = defaultTimeout
defaultClientHTTPSettings.WriteBufferSize = 512 * 1024
return &Config{
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
// We almost read 0 bytes, so no need to tune ReadBufferSize.
WriteBufferSize: 512 * 1024,
},
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
HTTPClientSettings: defaultClientHTTPSettings,
Format: defaultFormat,
DefaultServiceName: defaultServiceName,
}
Expand All @@ -53,11 +51,6 @@ func createTracesExporter(
) (exporter.Traces, error) {
zc := cfg.(*Config)

if zc.Endpoint == "" {
// TODO https://github.com/open-telemetry/opentelemetry-collector/issues/215
return nil, errors.New("exporter config requires a non-empty 'endpoint'")
}

ze, err := createZipkinExporter(zc, set.TelemetrySettings)
if err != nil {
return nil, err
Expand Down
8 changes: 1 addition & 7 deletions exporter/zipkinexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ func TestCreateDefaultConfig(t *testing.T) {
func TestCreateInstanceViaFactory(t *testing.T) {
cfg := createDefaultConfig()

// Default config doesn't have default endpoint so creating from it should
// fail.
ze, err := createTracesExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
assert.Error(t, err)
assert.Nil(t, ze)

// URL doesn't have a default value so set it directly.
zeCfg := cfg.(*Config)
zeCfg.Endpoint = "http://some.location.org:9411/api/v2/spans"
ze, err = createTracesExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
ze, err := createTracesExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
assert.NoError(t, err)
assert.NotNil(t, ze)
}
2 changes: 2 additions & 0 deletions exporter/zipkinexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ zipkin/2:
endpoint: "https://somedest:1234/api/v2/spans"
format: proto
default_service_name: test_name
idle_conn_timeout: 5s
max_idle_conns: 50
sending_queue:
enabled: true
num_consumers: 2
Expand Down

0 comments on commit e96ba3d

Please sign in to comment.