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
17 changes: 15 additions & 2 deletions bundle/manifests/monitoring.rhobs_monitoringstacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1715,10 +1715,23 @@ spec:
retention:
default: 120h
description: |-
Time duration to retain data for. Default is '120h',
and must match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds seconds minutes hours days weeks years).
Time duration to retain data for. Default is '120h', and the value must
match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds
seconds minutes hours days weeks years).

When both retention and retentionSize are defined, whichever triggers
first will be applied.
pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$
type: string
retentionSize:
description: |-
retentionSize defines the maximum number of bytes used by the Prometheus
data. By default the size is unlimited.

When both retention and retentionSize are defined, whichever triggers
first will be applied.
pattern: (^0|([0-9]*[.])?[0-9]+((K|M|G|T|E|P)i?)?B)$
type: string
tolerations:
description: Define tolerations for Monitoring Stack Pods.
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ metadata:
categories: Monitoring
certified: "false"
containerImage: observability-operator:1.3.0
createdAt: "2025-11-27T18:47:09Z"
createdAt: "2025-11-28T13:17:19Z"
description: A Go based Kubernetes operator to setup and manage highly available
Monitoring Stack using Prometheus, Alertmanager and Thanos Querier.
operatorframework.io/cluster-monitoring: "true"
Expand Down
17 changes: 15 additions & 2 deletions deploy/crds/common/monitoring.rhobs_monitoringstacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1715,10 +1715,23 @@ spec:
retention:
default: 120h
description: |-
Time duration to retain data for. Default is '120h',
and must match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds seconds minutes hours days weeks years).
Time duration to retain data for. Default is '120h', and the value must
match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds
seconds minutes hours days weeks years).

When both retention and retentionSize are defined, whichever triggers
first will be applied.
pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$
type: string
retentionSize:
description: |-
retentionSize defines the maximum number of bytes used by the Prometheus
data. By default the size is unlimited.

When both retention and retentionSize are defined, whichever triggers
first will be applied.
pattern: (^0|([0-9]*[.])?[0-9]+((K|M|G|T|E|P)i?)?B)$
type: string
tolerations:
description: Define tolerations for Monitoring Stack Pods.
items:
Expand Down
19 changes: 17 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,27 @@ To disable service discovery, set to null. E.g. resourceSelector:.<br/>
<td><b>retention</b></td>
<td>string</td>
<td>
Time duration to retain data for. Default is '120h',
and must match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds seconds minutes hours days weeks years).<br/>
Time duration to retain data for. Default is '120h', and the value must
match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds
seconds minutes hours days weeks years).

When both retention and retentionSize are defined, whichever triggers
first will be applied.<br/>
<br/>
<i>Default</i>: 120h<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>retentionSize</b></td>
<td>string</td>
<td>
retentionSize defines the maximum number of bytes used by the Prometheus
data. By default the size is unlimited.

When both retention and retentionSize are defined, whichever triggers
first will be applied.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#monitoringstackspectolerationsindex">tolerations</a></b></td>
<td>[]object</td>
Expand Down
18 changes: 16 additions & 2 deletions pkg/apis/monitoring/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,25 @@ type MonitoringStackSpec struct {
// +optional
CreateClusterRoleBindings ClusterRoleBindingPolicy `json:"createClusterRoleBindings,omitempty"`

// Time duration to retain data for. Default is '120h',
// and must match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds seconds minutes hours days weeks years).
// Time duration to retain data for. Default is '120h', and the value must
// match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds
// seconds minutes hours days weeks years).
//
// When both retention and retentionSize are defined, whichever triggers
// first will be applied.
//
// +kubebuilder:default="120h"
Retention monv1.Duration `json:"retention,omitempty"`

// retentionSize defines the maximum number of bytes used by the Prometheus
// data. By default the size is unlimited.
//
// When both retention and retentionSize are defined, whichever triggers
// first will be applied.
//
// +optional
RetentionSize monv1.ByteSize `json:"retentionSize,omitempty"`

// Define resources requests and limits for Monitoring Stack Pods.
// +optional
// +kubebuilder:default={requests:{cpu: "100m", memory: "256Mi"}, limits:{memory: "512Mi", cpu: "500m"}}
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/monitoring/monitoring-stack/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func newPrometheus(
}(),
},
Retention: ms.Spec.Retention,
RetentionSize: ms.Spec.RetentionSize,
RuleSelector: prometheusSelector,
RuleNamespaceSelector: ms.Spec.NamespaceSelector,
Thanos: &monv1.ThanosSpec{
Expand Down
65 changes: 44 additions & 21 deletions test/e2e/monitoring_stack_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ func reconcileRevertsManualChanges(t *testing.T) {
f.GetResourceWithRetry(t, ms.Name, ms.Namespace, &generated)

// update the prometheus created by monitoring-stack controller

modified := generated.DeepCopy()
modified.Spec.ServiceMonitorSelector = &metav1.LabelSelector{
MatchLabels: map[string]string{
Expand Down Expand Up @@ -348,28 +347,52 @@ func validateStackLogLevel(t *testing.T) {
}

func validateStackRetention(t *testing.T) {
invalidRetention := []monv1.Duration{
"100days",
"100ducks",
"100 days",
"100 hours",
"100 h",
"100 s",
"100d ",
}

ms := newMonitoringStack(t, "invalid-retention")
for _, v := range invalidRetention {
ms.Spec.Retention = v
err := f.K8sClient.Create(context.Background(), ms)
assert.ErrorContains(t, err, `spec.retention: Invalid value`)
}
t.Run("time-based", func(t *testing.T) {
invalidRetention := []monv1.Duration{
"100days",
"100ducks",
"100 days",
"100 hours",
"100 h",
"100 s",
"100d ",
}

validMS := newMonitoringStack(t, "valid-retention")
validMS.Spec.Retention = "100h"
ms := newMonitoringStack(t, "invalid-retention")
for _, v := range invalidRetention {
ms.Spec.Retention = v
err := f.K8sClient.Create(context.Background(), ms)
assert.ErrorContains(t, err, `spec.retention: Invalid value`)
}

err := f.K8sClient.Create(context.Background(), validMS)
assert.NilError(t, err, `100h is a valid retention period`)
validMS := newMonitoringStack(t, "valid-retention")
validMS.Spec.Retention = "100h"

err := f.K8sClient.Create(context.Background(), validMS)
assert.NilError(t, err, `100h is a valid retention period`)
})

t.Run("size-based", func(t *testing.T) {
invalidRetention := []monv1.ByteSize{
"1gb",
"1foo",
"1 GB",
"1GB ",
}

ms := newMonitoringStack(t, "invalid-retention-size")
for _, v := range invalidRetention {
ms.Spec.RetentionSize = v
err := f.K8sClient.Create(context.Background(), ms)
assert.ErrorContains(t, err, `spec.retentionSize: Invalid value`)
}

validMS := newMonitoringStack(t, "valid-retention-size")
validMS.Spec.RetentionSize = "1GB"

err := f.K8sClient.Create(context.Background(), validMS)
assert.NilError(t, err)
})
}

func validatePrometheusConfig(t *testing.T) {
Expand Down