Skip to content
Merged
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
25 changes: 25 additions & 0 deletions .chloggen/migrate_timeout_config.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: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
component: pkg/exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Migrate `TimeoutConfig` to schema-based configuration generated by mdatagen.

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

# (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]
20 changes: 20 additions & 0 deletions exporter/exporterhelper/config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$id": "go.opentelemetry.io/collector/exporter/exporterhelper",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"timeout_config": {
"type": "object",
"properties": {
"timeout": {
"type": "string",
"description": "Defines the timeout for every attempt to send data to the backend. A zero timeout means no timeout.",
"default": "5s",
"minimum": 0,
"pattern": "^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
}
},
"description": "A timeout configuration. The timeout applies to individual attempts to send data to the backend."
}
},
"title": "pkg/exporterhelper"
}
15 changes: 15 additions & 0 deletions exporter/exporterhelper/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions exporter/exporterhelper/generated_config_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions exporter/exporterhelper/internal/config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$id": "go.opentelemetry.io/collector/exporter/exporterhelper/internal",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"timeout_config": {
"type": "object",
"properties": {
"timeout": {
"type": "string",
"description": "Defines the timeout for every attempt to send data to the backend. A zero timeout means no timeout.",
"default": "5s",
"minimum": 0,
"pattern": "^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
}
},
"description": "A timeout configuration. The timeout applies to individual attempts to send data to the backend."
}
},
"title": "exporterhelper/timeout"
}
6 changes: 6 additions & 0 deletions exporter/exporterhelper/internal/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

package internal // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal"
34 changes: 34 additions & 0 deletions exporter/exporterhelper/internal/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions exporter/exporterhelper/internal/generated_config_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions exporter/exporterhelper/internal/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: exporterhelper/timeout
parent: pkg/exporterhelper

exported_configs:
timeout_config:
description: A timeout configuration. The timeout applies to individual attempts to send data to the backend.
type: object
properties:
timeout:
description: Defines the timeout for every attempt to send data to the backend. A zero timeout means no timeout.
type: duration
default: 5s
minimum: 0
24 changes: 0 additions & 24 deletions exporter/exporterhelper/internal/timeout_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,11 @@ package internal // import "go.opentelemetry.io/collector/exporter/exporterhelpe

import (
"context"
"errors"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
)

// TimeoutConfig for timeout. The timeout applies to individual attempts to send data to the backend.
type TimeoutConfig struct {
// Timeout is the timeout for every attempt to send data to the backend.
// A zero timeout means no timeout.
Timeout time.Duration `mapstructure:"timeout"`
}

func (ts *TimeoutConfig) Validate() error {
// Negative timeouts are not acceptable, since all sends will fail.
if ts.Timeout < 0 {
return errors.New("'timeout' must be non-negative")
}
return nil
}

// NewDefaultTimeoutConfig returns the default config for TimeoutConfig.
func NewDefaultTimeoutConfig() TimeoutConfig {
return TimeoutConfig{
Timeout: 5 * time.Second,
}
}

// timeoutSender is a requestSender that adds a `timeout` to every request that passes this sender.
type timeoutSender[T any] struct {
component.StartFunc
Expand Down
4 changes: 4 additions & 0 deletions exporter/exporterhelper/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ feature_gates:
from_version: 'v0.158.0'
reference_url: 'https://github.com/open-telemetry/opentelemetry-collector/issues/15047'

exported_configs:
timeout_config:
$ref: ./internal.timeout_config

telemetry:
metrics:
exporter_enqueue_failed_log_records:
Expand Down
15 changes: 0 additions & 15 deletions exporter/exporterhelper/timeout_sender.go

This file was deleted.

2 changes: 1 addition & 1 deletion exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestUnmarshalInvalidConfig(t *testing.T) {
},
{
name: "invalid_timeout",
errorMsg: `'timeout' must be non-negative`,
errorMsg: `timeout value must be greater than or equal to 0`,
},
{
name: "invalid_retry",
Expand Down
Loading