Skip to content
Open
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
10 changes: 10 additions & 0 deletions pkg/apis/monitoring/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ type PrometheusConfig struct {
// The resulting endpoint is /api/v1/otlp/v1/metrics.
// +optional
EnableOtlpHttpReceiver *bool `json:"enableOtlpHttpReceiver,omitempty"`
// Enable access to Prometheus feature flags. By default, no features are enabled.
// Enabling features which are disabled by default is entirely outside the
// scope of what the maintainers will support and by doing so, you accept
// that this behaviour may break at any time without notice.
//
// For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/
//
// +optional
// +kubebuilder:validation:items:MinLength=1
EnableFeatures []string `json:"enableFeatures,omitempty"`
// Default interval between scrapes.
// +optional
ScrapeInterval *monv1.Duration `json:"scrapeInterval,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go

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

13 changes: 13 additions & 0 deletions pkg/controllers/monitoring/monitoring-stack/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func newPrometheus(
ExternalLabels: config.ExternalLabels,
EnableRemoteWriteReceiver: config.EnableRemoteWriteReceiver,
EnableOTLPReceiver: config.EnableOtlpHttpReceiver,
EnableFeatures: toEnableFeatures(config.EnableFeatures),
},
Retention: ms.Spec.Retention,
RetentionSize: ms.Spec.RetentionSize,
Expand Down Expand Up @@ -565,3 +566,15 @@ func podLabels(component string, msName string) map[string]string {
"app.kubernetes.io/part-of": msName,
}
}

// toEnableFeatures converts a slice of strings to a slice of EnableFeature.
func toEnableFeatures(features []string) []monv1.EnableFeature {
if len(features) == 0 {
return nil
}
result := make([]monv1.EnableFeature, len(features))
for i, f := range features {
result[i] = monv1.EnableFeature(f)
}
return result
}
36 changes: 36 additions & 0 deletions pkg/controllers/monitoring/monitoring-stack/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,42 @@ import (
stack "github.com/rhobs/observability-operator/pkg/apis/monitoring/v1alpha1"
)

func TestToEnableFeatures(t *testing.T) {
tt := []struct {
name string
input []string
expected []monv1.EnableFeature
}{
{
name: "nil input returns nil",
input: nil,
expected: nil,
},
{
name: "empty input returns nil",
input: []string{},
expected: nil,
},
{
name: "single feature",
input: []string{"exemplar-storage"},
expected: []monv1.EnableFeature{"exemplar-storage"},
},
{
name: "multiple features",
input: []string{"exemplar-storage", "otlp-write-receiver"},
expected: []monv1.EnableFeature{"exemplar-storage", "otlp-write-receiver"},
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
actual := toEnableFeatures(tc.input)
assert.DeepEqual(t, tc.expected, actual)
})
}
}

func TestStorageSpec(t *testing.T) {
validPVCSpec := &corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Expand Down
1 change: 1 addition & 0 deletions test/e2e/monitoring_stack_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ func assertPrometheusManagedFields(t *testing.T) {
},
EnableRemoteWriteReceiver: true,
EnableOtlpHttpReceiver: func(b bool) *bool { return &b }(true),
EnableFeatures: []string{"exemplar-storage"},
WebTLSConfig: &stack.WebTLSConfig{
Certificate: stack.SecretKeySelector{
Name: "prom-test-managedfields-tls-secret",
Expand Down