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
7 changes: 1 addition & 6 deletions pkg/controllers/monitoring/monitoring-stack/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,7 @@ func newPrometheus(
RemoteWrite: config.RemoteWrite,
ExternalLabels: config.ExternalLabels,
EnableRemoteWriteReceiver: config.EnableRemoteWriteReceiver,
EnableFeatures: func() []monv1.EnableFeature {
if config.EnableOtlpHttpReceiver != nil && *config.EnableOtlpHttpReceiver {
return []monv1.EnableFeature{"otlp-write-receiver"}
}
return []monv1.EnableFeature{}
}(),
EnableOTLPReceiver: config.EnableOtlpHttpReceiver,
},
Retention: ms.Spec.Retention,
RuleSelector: prometheusSelector,
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/framework/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,55 @@ func (f *Framework) AssertStatefulsetReady(name, namespace string, fns ...Option
}
}

// AssertStatefulSetContainerHasArg asserts that a specific container in a StatefulSet's
// Pod template contains the expected command-line argument.
func (f *Framework) AssertStatefulSetContainerHasArg(t *testing.T, name, namespace, containerName, expectedArg string, fns ...OptionFn) func(t *testing.T) {
option := AssertOption{
PollInterval: 5 * time.Second,
WaitTimeout: DefaultTestTimeout,
}
for _, fn := range fns {
fn(&option)
}

return func(t *testing.T) {
t.Helper()
statefulSet := &appsv1.StatefulSet{}
key := types.NamespacedName{Name: name, Namespace: namespace}

if err := wait.PollUntilContextTimeout(context.Background(), option.PollInterval, option.WaitTimeout, true, func(ctx context.Context) (bool, error) {

if err := f.K8sClient.Get(ctx, key, statefulSet); apierrors.IsNotFound(err) {
return false, nil
}

var container *v1.Container
for i, c := range statefulSet.Spec.Template.Spec.Containers {
if c.Name == containerName {
container = &statefulSet.Spec.Template.Spec.Containers[i]
break
}
}

if container == nil {
return false, fmt.Errorf("container %q not found in StatefulSet template", containerName)
}

for _, arg := range container.Args {
if arg == expectedArg {
return true, nil
}
}

t.Logf("StatefulSet %s container %q args are missing %q. Retrying...", name, containerName, expectedArg)
return false, nil
}); wait.Interrupted(err) {
t.Fatalf("StatefulSet %s failed to contain argument %q in container %q within timeout. Final args: %v",
name, expectedArg, containerName, statefulSet.Spec.Template.Spec.Containers[0].Args)
}
}
}

// AssertDeploymentReady asserts that a deployment has the desired number of pods running
func (f *Framework) AssertDeploymentReady(name, namespace string, fns ...OptionFn) func(t *testing.T) {
option := AssertOption{
Expand Down
19 changes: 16 additions & 3 deletions test/e2e/monitoring_stack_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func TestMonitoringStackController(t *testing.T) {
}, {
name: "Prometheus stacks can scrape themselves behind TLS",
scenario: assertPrometheusScrapesItselfTLS,
}, {
name: "Assert OTLP receiver flag is set when enabled in CR",
scenario: assertDefaultOTLPFlagIsSet,
}}
for _, tc := range ts {
t.Run(tc.name, tc.scenario)
Expand Down Expand Up @@ -969,6 +972,18 @@ func assertPrometheusScrapesItselfTLS(t *testing.T) {
}
}

func assertDefaultOTLPFlagIsSet(t *testing.T) {
ms := newMonitoringStack(t, "otlp-flag-test")
ms.Spec.PrometheusConfig = &stack.PrometheusConfig{
EnableOtlpHttpReceiver: ptr.To(true),
}

err := f.K8sClient.Create(context.Background(), ms)
assert.NilError(t, err, "failed to create a monitoring stack")

f.AssertStatefulSetContainerHasArg(t, "prometheus-"+ms.Name, e2eTestNamespace, "prometheus", "--web.enable-otlp-receiver")(t)
}

// Update this json when a new Prometheus field is set by MonitoringStack
const oboManagedFieldsJson = `
{
Expand Down Expand Up @@ -998,9 +1013,7 @@ const oboManagedFieldsJson = `
"f:probeNamespaceSelector": {},
"f:probeSelector": {},
"f:remoteWrite": {},
"f:enableFeatures": {
"v:\"otlp-write-receiver\"": {}
},
"f:enableOTLPReceiver": {},
"f:replicas": {},
"f:resources": {},
"f:retention": {},
Expand Down