Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f6eb27
[confighttp] Add optional type to tls
mx-psi May 28, 2025
1ba683d
[confighttp] Use configoptional.Optional for CORS config
mx-psi May 28, 2025
6ea68c5
[confighttp] Use configoptional.Optional for Auth config
mx-psi May 28, 2025
7092009
[confighttp] Rename TLSSetting fields to TLS in ServerConfig
mx-psi May 28, 2025
8793522
[confighttp] Rename TLSSetting field to TLS in ClientConfig
mx-psi May 28, 2025
b8a4d7a
[confighttp] Remove pointers from remaining fields
mx-psi May 28, 2025
40b96b6
Fix toolchain directive
mx-psi May 28, 2025
901270a
Add changelog entries
mx-psi May 28, 2025
0430f78
Use Default instead of None (does not make a difference but oh well)
mx-psi May 28, 2025
ffd62e7
make crosslink
mx-psi May 28, 2025
17976dd
Some, not default
mx-psi May 28, 2025
a33082f
Merge branch 'main' into mx-psi/use-configoptional-in-confighttp
mx-psi May 28, 2025
7a14748
Merge remote-tracking branch 'origin/main' into mx-psi/use-configopti…
mx-psi Jun 6, 2025
26f8bfa
Merge remote-tracking branch 'origin/main' into mx-psi/use-configopti…
mx-psi Jun 11, 2025
f13be0b
Fix merge
mx-psi Jun 11, 2025
1051beb
Remove release note that is no longer needed, use proper versions for…
mx-psi Jun 11, 2025
8bf3df7
Make CI happy
mx-psi Jun 11, 2025
b7c1e4d
Fix test
mx-psi Jun 11, 2025
77c514d
o.notNone = true
mx-psi Jun 12, 2025
d2678d8
Merge remote-tracking branch 'origin/main' into mx-psi/use-configopti…
mx-psi Jun 17, 2025
84c962f
Merge branch 'main' into mx-psi/use-configoptional-in-confighttp
mx-psi Jun 23, 2025
b242c43
Merge branch 'main' into mx-psi/use-configoptional-in-confighttp
mx-psi Jul 7, 2025
5489fb4
Fix tests
mx-psi Jul 7, 2025
483cb80
Fix versioning
mx-psi Jul 7, 2025
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/mx-psi_use-configoptional-in-confighttp-tls.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: confighttp

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Rename `ClientConfig.TLSSetting` and `ServerConfig.TLSSetting` to `ClientConfig.TLS` and `ServerConfig.TLS`."

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

# (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]
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_use-configoptional-in-confighttp.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: confighttp

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Use configooptional.Optional in confighttp"

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

# (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]
1 change: 1 addition & 0 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var replaceModules = []string{
"/config/configmiddleware",
"/config/confignet",
"/config/configopaque",
"/config/configoptional",
"/config/configretry",
"/config/configtelemetry",
"/config/configtls",
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ replaces:
- go.opentelemetry.io/collector/config/configmiddleware => ../../config/configmiddleware
- go.opentelemetry.io/collector/config/confignet => ../../config/confignet
- go.opentelemetry.io/collector/config/configopaque => ../../config/configopaque
- go.opentelemetry.io/collector/config/configoptional => ../../config/configoptional
- go.opentelemetry.io/collector/config/configretry => ../../config/configretry
- go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry
- go.opentelemetry.io/collector/config/configtls => ../../config/configtls
Expand Down
3 changes: 3 additions & 0 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ require (
go.opentelemetry.io/collector/config/configmiddleware v0.127.0 // indirect
go.opentelemetry.io/collector/config/confignet v1.33.0 // indirect
go.opentelemetry.io/collector/config/configopaque v1.33.0 // indirect
go.opentelemetry.io/collector/config/configoptional v0.0.0-20250528115901-279ccad9f437 // indirect
go.opentelemetry.io/collector/config/configretry v1.33.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.127.0 // indirect
go.opentelemetry.io/collector/config/configtls v1.33.0 // indirect
Expand Down Expand Up @@ -197,6 +198,8 @@ replace go.opentelemetry.io/collector/config/confignet => ../../config/confignet

replace go.opentelemetry.io/collector/config/configopaque => ../../config/configopaque

replace go.opentelemetry.io/collector/config/configoptional => ../../config/configoptional

replace go.opentelemetry.io/collector/config/configretry => ../../config/configretry

replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry
Expand Down
53 changes: 28 additions & 25 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/collector/config/confighttp/internal"
"go.opentelemetry.io/collector/config/configmiddleware"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/extension/extensionauth"
)
Expand All @@ -53,8 +54,8 @@ type ClientConfig struct {
// ProxyURL setting for the collector
ProxyURL string `mapstructure:"proxy_url,omitempty"`

// TLSSetting struct exposes TLS client configuration.
TLSSetting configtls.ClientConfig `mapstructure:"tls,omitempty"`
// TLS struct exposes TLS client configuration.
TLS configtls.ClientConfig `mapstructure:"tls,omitempty"`

// ReadBufferSize for HTTP client. See http.Transport.ReadBufferSize.
// Default is 0.
Expand All @@ -74,7 +75,7 @@ type ClientConfig struct {
Headers map[string]configopaque.String `mapstructure:"headers,omitempty"`

// Auth configuration for outgoing HTTP calls.
Auth *configauth.Config `mapstructure:"auth,omitempty"`
Auth configoptional.Optional[configauth.Config] `mapstructure:"auth,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

is zero-value of Optional a None value?

Copy link
Member

Choose a reason for hiding this comment

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

also, I am curious how omitempty works for Optional. It seems like the output formatter, when do we use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

is zero-value of Optional a None value?

Yep

also, I am curious how omitempty works for Optional. It seems like the output formatter, when do we use it?

omitempty will omit None values (since it omits any zero values). It's used by confmap.Marshal which is used for things like OpAMP (to report the effective configuration to a backend)


// The compression key for supported compression types within collector.
Compression configcompression.Type `mapstructure:"compression,omitempty"`
Expand Down Expand Up @@ -116,7 +117,7 @@ type ClientConfig struct {
// If not set or set to 0, it defaults to 15s.
HTTP2PingTimeout time.Duration `mapstructure:"http2_ping_timeout,omitempty"`
// Cookies configures the cookie management of the HTTP client.
Cookies *CookiesConfig `mapstructure:"cookies,omitempty"`
Cookies CookiesConfig `mapstructure:"cookies,omitempty"`

// Middlewares are used to add custom functionality to the HTTP client.
// Middleware handlers are called in the order they appear in this list,
Expand Down Expand Up @@ -164,7 +165,7 @@ type ToClientOption interface {

// ToClient creates an HTTP client.
func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, settings component.TelemetrySettings, _ ...ToClientOption) (*http.Client, error) {
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig(ctx)
tlsCfg, err := hcs.TLS.LoadTLSConfig(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -225,13 +226,14 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett
// The Auth RoundTripper should always be the innermost to ensure that
// request signing-based auth mechanisms operate after compression
// and header middleware modifies the request
if hcs.Auth != nil {
if hcs.Auth.HasValue() {
ext := host.GetExtensions()
if ext == nil {
return nil, errors.New("extensions configuration not found")
}

httpCustomAuthRoundTripper, aerr := hcs.Auth.GetHTTPClientAuthenticator(ctx, ext)
auth := hcs.Auth.Get()
httpCustomAuthRoundTripper, aerr := auth.GetHTTPClientAuthenticator(ctx, ext)
if aerr != nil {
return nil, aerr
}
Expand Down Expand Up @@ -273,7 +275,7 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett
}

var jar http.CookieJar
if hcs.Cookies != nil && hcs.Cookies.Enabled {
if hcs.Cookies.Enabled {
jar, err = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
if err != nil {
return nil, err
Expand Down Expand Up @@ -314,14 +316,14 @@ type ServerConfig struct {
// Endpoint configures the listening address for the server.
Endpoint string `mapstructure:"endpoint,omitempty"`

// TLSSetting struct exposes TLS client configuration.
TLSSetting *configtls.ServerConfig `mapstructure:"tls"`
// TLS struct exposes TLS client configuration.
TLS configoptional.Optional[configtls.ServerConfig] `mapstructure:"tls"`

// CORS configures the server for HTTP cross-origin resource sharing (CORS).
CORS *CORSConfig `mapstructure:"cors"`
CORS configoptional.Optional[CORSConfig] `mapstructure:"cors"`

// Auth for this receiver
Auth *AuthConfig `mapstructure:"auth,omitempty"`
Auth configoptional.Optional[AuthConfig] `mapstructure:"auth,omitempty"`

// MaxRequestBodySize sets the maximum request body size in bytes. Default: 20MiB.
MaxRequestBodySize int64 `mapstructure:"max_request_body_size,omitempty"`
Expand Down Expand Up @@ -376,11 +378,10 @@ type ServerConfig struct {
// NewDefaultServerConfig returns ServerConfig type object with default values.
// We encourage to use this function to create an object of ServerConfig.
func NewDefaultServerConfig() ServerConfig {
tlsDefaultServerConfig := configtls.NewDefaultServerConfig()
return ServerConfig{
ResponseHeaders: map[string]configopaque.String{},
TLSSetting: &tlsDefaultServerConfig,
CORS: NewDefaultCORSConfig(),
TLS: configoptional.Default(configtls.NewDefaultServerConfig()),
CORS: configoptional.Default(*NewDefaultCORSConfig()),
WriteTimeout: 30 * time.Second,
ReadHeaderTimeout: 1 * time.Minute,
IdleTimeout: 1 * time.Minute,
Expand All @@ -405,9 +406,9 @@ func (hss *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) {
return nil, err
}

if hss.TLSSetting != nil {
if hss.TLS.HasValue() {
var tlsCfg *tls.Config
tlsCfg, err = hss.TLSSetting.LoadTLSConfig(ctx)
tlsCfg, err = hss.TLS.Get().LoadTLSConfig(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -486,25 +487,27 @@ func (hss *ServerConfig) ToServer(ctx context.Context, host component.Host, sett
handler = maxRequestBodySizeInterceptor(handler, hss.MaxRequestBodySize)
}

if hss.Auth != nil {
server, err := hss.Auth.GetServerAuthenticator(context.Background(), host.GetExtensions())
if hss.Auth.HasValue() {
auth := hss.Auth.Get()
server, err := auth.GetServerAuthenticator(context.Background(), host.GetExtensions())
if err != nil {
return nil, err
}

handler = authInterceptor(handler, server, hss.Auth.RequestParameters, serverOpts)
handler = authInterceptor(handler, server, auth.RequestParameters, serverOpts)
}

if hss.CORS != nil && len(hss.CORS.AllowedOrigins) > 0 {
if hss.CORS.HasValue() && len(hss.CORS.Get().AllowedOrigins) > 0 {
corsConfig := hss.CORS.Get()
co := cors.Options{
AllowedOrigins: hss.CORS.AllowedOrigins,
AllowedOrigins: corsConfig.AllowedOrigins,
AllowCredentials: true,
AllowedHeaders: hss.CORS.AllowedHeaders,
MaxAge: hss.CORS.MaxAge,
AllowedHeaders: corsConfig.AllowedHeaders,
MaxAge: corsConfig.MaxAge,
}
handler = cors.New(co).Handler(handler)
}
if hss.CORS != nil && len(hss.CORS.AllowedOrigins) == 0 && len(hss.CORS.AllowedHeaders) > 0 {
if hss.CORS.HasValue() && len(hss.CORS.Get().AllowedOrigins) == 0 && len(hss.CORS.Get().AllowedHeaders) > 0 {
settings.Logger.Warn("The CORS configuration specifies allowed headers but no allowed origins, and is therefore ignored.")
}

Expand Down
Loading
Loading