-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[receiver/zipkin] add protocols option #40277
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
ca5e99d
e987230
6b1b919
1fd9ed0
1c2aece
c99f0ed
ed66389
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,9 +29,44 @@ receivers: | |||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
The following settings are configurable: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- `endpoint` (default = localhost:9411): host:port on which the receiver is going to receive data.See our [security best practices doc](https://opentelemetry.io/docs/security/config-best-practices/#protect-against-denial-of-service-attacks) to understand how to set the endpoint in different environments. You can review the [full list of `ServerConfig`](https://github.com/open-telemetry/opentelemetry-collector/tree/main/config/confighttp). | ||||||||||||||||||||||||||||||||
### Legacy Configuration (Deprecated) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- `endpoint` (default = localhost:9411): host:port on which the receiver is going to receive data. See our [security best practices doc](https://opentelemetry.io/docs/security/config-best-practices/#protect-against-denial-of-service-attacks) to understand how to set the endpoint in different environments. For full list of `ServerConfig` refer [here](https://github.com/open-telemetry/opentelemetry-collector/tree/main/config/confighttp). | ||||||||||||||||||||||||||||||||
- `parse_string_tags` (default = false): if enabled, the receiver will attempt to parse string tags/binary annotations into int/bool/float. | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
### Protocol-Based Configuration | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Starting from v0.128.0, the zipkin receiver supports a protocol-based configuration format: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to mention in the docs the version an option appeared in. That's what the Changelog is for. |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```yaml | ||||||||||||||||||||||||||||||||
receivers: | ||||||||||||||||||||||||||||||||
zipkin: | ||||||||||||||||||||||||||||||||
protocols: | ||||||||||||||||||||||||||||||||
http: | ||||||||||||||||||||||||||||||||
endpoint: localhost:9411 | ||||||||||||||||||||||||||||||||
parse_string_tags: false | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Currently, only the HTTP protocol is supported, but this structure allows for future expansion to other protocols (such as UDP). The protocol-based design makes the receiver more extensible and follows the pattern used by other receivers in the OpenTelemetry Collector. | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I say let's not bother the users with these details here. They just want to configure the component.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
#### Future Protocol Support | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
The architecture has been designed to easily add support for additional protocols in the future. For example, a UDP protocol could be added with configuration like: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```yaml | ||||||||||||||||||||||||||||||||
receivers: | ||||||||||||||||||||||||||||||||
zipkin: | ||||||||||||||||||||||||||||||||
protocols: | ||||||||||||||||||||||||||||||||
http: | ||||||||||||||||||||||||||||||||
endpoint: localhost:9411 | ||||||||||||||||||||||||||||||||
# UDP support is not yet implemented, this is just an example | ||||||||||||||||||||||||||||||||
# udp: | ||||||||||||||||||||||||||||||||
# endpoint: localhost:9412 | ||||||||||||||||||||||||||||||||
parse_string_tags: false | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
Comment on lines
+52
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not make "forward looking statements" describing what might be possible in the future. Users might be confused on whether UDP is currently supported or not.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
The legacy configuration format is still supported for backward compatibility, but it is recommended to use the new protocol-based configuration format for new deployments. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## Advanced Configuration | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Several helper files are leveraged to provide additional capabilities automatically: | ||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,51 @@ | |
package zipkinreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver" | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/confmap" | ||
) | ||
|
||
const ( | ||
protoHTTP = "protocols::http" | ||
// Future protocol constants can be added here | ||
// protoUDP = "protocols::udp" | ||
) | ||
|
||
// HTTPConfig defines configuration for Zipkin HTTP receiver. | ||
type HTTPConfig struct { | ||
ServerConfig confighttp.ServerConfig `mapstructure:",squash"` | ||
// prevent unkeyed literal initialization | ||
_ struct{} | ||
} | ||
|
||
// UDPConfig defines configuration for a potential future Zipkin UDP receiver. | ||
// type UDPConfig struct { | ||
// Endpoint string `mapstructure:"endpoint"` | ||
// // Add other UDP-specific configuration options here | ||
// } | ||
|
||
// Protocols holds the configuration for all supported protocols. | ||
type Protocols struct { | ||
HTTP *HTTPConfig `mapstructure:"http"` | ||
// Future protocols can be added here | ||
// UDP *UDPConfig `mapstructure:"udp"` | ||
|
||
// prevent unkeyed literal initialization | ||
_ struct{} | ||
} | ||
|
||
// Config defines configuration for Zipkin receiver. | ||
type Config struct { | ||
// Configures the receiver server protocol. | ||
// Protocols is the configuration for the supported protocols, currently only HTTP. | ||
Protocols `mapstructure:"protocols"` | ||
|
||
// Deprecated: [v0.128.0] Use protocols.http instead. | ||
confighttp.ServerConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct | ||
|
||
// If enabled the zipkin receiver will attempt to parse string tags/binary annotations into int/bool/float. | ||
// Disabled by default | ||
ParseStringTags bool `mapstructure:"parse_string_tags"` | ||
|
@@ -24,5 +61,48 @@ var _ component.Config = (*Config)(nil) | |
|
||
// Validate checks the receiver configuration is valid | ||
func (cfg *Config) Validate() error { | ||
// Check if legacy configuration is used | ||
if cfg.Endpoint != "" { | ||
// Legacy configuration is used, no need to validate protocols | ||
return nil | ||
} | ||
|
||
// Check if protocols configuration is used | ||
if cfg.HTTP == nil { | ||
// Currently, only HTTP protocol is supported | ||
// When more protocols are added, this validation can be updated | ||
// to check if at least one protocol is configured | ||
return errors.New("must specify at least one protocol when using protocols configuration") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Unmarshal is a custom unmarshaler for Config | ||
func (cfg *Config) Unmarshal(conf *confmap.Conf) error { | ||
// First, unmarshal the standard fields | ||
err := conf.Unmarshal(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Check if any protocol configuration is used | ||
// Currently only checking for HTTP, but can be expanded for future protocols | ||
if !conf.IsSet(protoHTTP) { | ||
// No protocols section, using legacy configuration | ||
cfg.HTTP = &HTTPConfig{ | ||
ServerConfig: cfg.ServerConfig, | ||
} | ||
return nil | ||
} | ||
|
||
// If protocols section exists, clear the legacy endpoint to avoid confusion | ||
if cfg.Endpoint != "" && conf.IsSet(protoHTTP) { | ||
// Both legacy and new configuration used, log a warning | ||
fmt.Println("Warning: Both legacy endpoint and protocols.http configuration found. Using protocols.http configuration.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 We must never use |
||
// Clear the legacy endpoint | ||
cfg.Endpoint = "" | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should describe the recommended configuration first and legacy after that.