Skip to content
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

Fixes bug where we tried to default config for the wrong components #3337

Merged
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
4 changes: 3 additions & 1 deletion .chloggen/add_all_receiver_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ issues: [3126]
# (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:
subtext: |
This feature is enabled by default. It can be disabled by specifying
`--feature-gates=-operator.collector.default.config`.
4 changes: 4 additions & 0 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/open-telemetry/opentelemetry-operator/internal/fips"
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
)

var (
Expand Down Expand Up @@ -100,6 +101,9 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error {
if len(otelcol.Spec.ManagementState) == 0 {
otelcol.Spec.ManagementState = ManagementStateManaged
}
if !featuregate.EnableConfigDefaulting.IsEnabled() {
return nil
}
return otelcol.Spec.Config.ApplyDefaults(c.logger)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/components/generic_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func (g *GenericParser[T]) GetDefaultConfig(logger logr.Logger, config interface
return config, nil
}

if g.settings.defaultRecAddr == "" {
if g.settings.defaultRecAddr == "" || g.settings.port == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

👍

return config, nil
}

var parsed T
if err := mapstructure.Decode(config, &parsed); err != nil {
return nil, err
}
return g.defaultsApplier(logger, g.settings.defaultRecAddr, g.settings.GetServicePort().Port, parsed)
return g.defaultsApplier(logger, g.settings.defaultRecAddr, g.settings.port, parsed)
}

func (g *GenericParser[T]) GetLivenessProbe(logger logr.Logger, config interface{}) (*corev1.Probe, error) {
Expand Down
24 changes: 24 additions & 0 deletions internal/components/receivers/single_endpoint_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package receivers_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -82,6 +83,7 @@ func TestDownstreamParsers(t *testing.T) {
{"awsxray", "awsxray", "__awsxray", 2000, false},
{"tcplog", "tcplog", "__tcplog", 0, true},
{"udplog", "udplog", "__udplog", 0, true},
{"k8s_cluster", "k8s_cluster", "__k8s_cluster", 0, false},
} {
t.Run(tt.receiverName, func(t *testing.T) {
t.Run("builds successfully", func(t *testing.T) {
Expand Down Expand Up @@ -143,6 +145,28 @@ func TestDownstreamParsers(t *testing.T) {
assert.EqualValues(t, 65535, ports[0].Port)
assert.Equal(t, naming.PortName(tt.receiverName, int32(tt.defaultPort)), ports[0].Name)
})

t.Run("returns a default config", func(t *testing.T) {
// prepare
parser := receivers.ReceiverFor(tt.receiverName)

// test
config, err := parser.GetDefaultConfig(logger, map[string]interface{}{})

// verify
assert.NoError(t, err)
configMap, ok := config.(map[string]interface{})
assert.True(t, ok)
if tt.defaultPort == 0 {
assert.Empty(t, configMap, 0)
return
}
if tt.listenAddrParser {
assert.Equal(t, configMap["listen_address"], fmt.Sprintf("0.0.0.0:%d", tt.defaultPort))
} else {
assert.Equal(t, configMap["endpoint"], fmt.Sprintf("0.0.0.0:%d", tt.defaultPort))
}
})
})
}
}
7 changes: 7 additions & 0 deletions pkg/featuregate/featuregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ var (
featuregate.WithRegisterDescription("enables feature to set GOMEMLIMIT and GOMAXPROCS automatically"),
featuregate.WithRegisterFromVersion("v0.100.0"),
)
// EnableConfigDefaulting is the feature gate that enables the operator to default the endpoint for known components.
EnableConfigDefaulting = featuregate.GlobalRegistry().MustRegister(
"operator.collector.default.config",
featuregate.StageBeta,
featuregate.WithRegisterDescription("enables the operator to default the endpoint for known components"),
featuregate.WithRegisterFromVersion("v0.110.0"),
)
Copy link
Member

Choose a reason for hiding this comment

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

Since no e2e breaks, I assume its enabled by default? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes :)

)

// Flags creates a new FlagSet that represents the available featuregate flags using the supplied featuregate registry.
Expand Down
Loading