diff --git a/pkg/operator/ceph/cluster/mgr/mgr.go b/pkg/operator/ceph/cluster/mgr/mgr.go index 6c1ac5b2cd02..aa55ef0dedd5 100644 --- a/pkg/operator/ceph/cluster/mgr/mgr.go +++ b/pkg/operator/ceph/cluster/mgr/mgr.go @@ -530,6 +530,10 @@ func (c *Cluster) EnableServiceMonitor() error { if c.spec.External.Enable { serviceMonitor.Spec.Endpoints[0].Port = controller.ServiceExternalMetricName } + if c.spec.Monitoring.Interval != nil { + duration := c.spec.Monitoring.Interval.Duration.String() + serviceMonitor.Spec.Endpoints[0].Interval = monitoringv1.Duration(duration) + } err := c.clusterInfo.OwnerInfo.SetControllerReference(serviceMonitor) if err != nil { return errors.Wrapf(err, "failed to set owner reference to service monitor %q", serviceMonitor.Name) diff --git a/pkg/operator/k8sutil/prometheus_test.go b/pkg/operator/k8sutil/prometheus_test.go index b2166138270d..6802896c597a 100644 --- a/pkg/operator/k8sutil/prometheus_test.go +++ b/pkg/operator/k8sutil/prometheus_test.go @@ -18,19 +18,21 @@ limitations under the License. package k8sutil import ( - "testing" - + monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/assert" + "testing" ) func TestGetServiceMonitor(t *testing.T) { name := "rook-ceph-mgr" namespace := "rook-ceph" port := "http-metrics" + interval := monitoringv1.Duration("5s") servicemonitor := GetServiceMonitor(name, namespace, port) assert.Equal(t, name, servicemonitor.GetName()) assert.Equal(t, namespace, servicemonitor.GetNamespace()) assert.Equal(t, port, servicemonitor.Spec.Endpoints[0].Port) + assert.Equal(t, interval, servicemonitor.Spec.Endpoints[0].Interval) assert.NotNil(t, servicemonitor.GetLabels()) assert.NotNil(t, servicemonitor.Spec.NamespaceSelector.MatchNames) assert.NotNil(t, servicemonitor.Spec.Selector.MatchLabels)