Skip to content

Commit

Permalink
Merge pull request rook#13179 from rkachach/fix_issue_13159
Browse files Browse the repository at this point in the history
mgr: set interval of serviceMonitor to the value from MonitoringSpec
  • Loading branch information
travisn authored Nov 9, 2023
2 parents 77db655 + 06bc976 commit 635570a
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 635570a

Please sign in to comment.