Skip to content

Commit

Permalink
mgr: set interval of serviceMonitor to the value from MonitoringSpec
Browse files Browse the repository at this point in the history
This change updates the serviceMonitor interval field with the
value from the MonitoringSpec.

closes: rook#13159

Signed-off-by: Redouane Kachach <[email protected]>
  • Loading branch information
rkachach committed Nov 9, 2023
1 parent 572f389 commit 06bc976
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/operator/ceph/cluster/mgr/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/operator/k8sutil/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 06bc976

Please sign in to comment.