Merge pull request #13186 from rook/mergify/bp/release-1.12/pr-13179

mgr: set interval of serviceMonitor to the value from MonitoringSpec (backport #13179)
This commit is contained in:
Travis Nielsen authored and GitHub committed 2023-11-10 10:36:39 -07:00
commit 8141632996
2 files changed
+8 -2

No files matched your search

+4
View File
@@ -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)
+4 -2
View File
@@ -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)