Skip to content

Commit

Permalink
Merge pull request #516 from weirdwiz/rename-service
Browse files Browse the repository at this point in the history
Bug 2236444: monitoring: set port for servicemonitor for ceph-exporter
  • Loading branch information
travisn authored Sep 5, 2023
2 parents 194fd1e + db10c33 commit 5fa6476
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/operator/ceph/cluster/mgr/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
standbyMgrStatus = "standby"
monitoringPath = "/etc/ceph-monitoring/"
serviceMonitorFile = "service-monitor.yaml"
serviceMonitorPort = "http-metrics"
// minimum amount of memory in MB to run the pod
cephMgrPodMinimumMemory uint64 = 512
// DefaultMetricsPort prometheus exporter port
Expand Down Expand Up @@ -502,7 +503,7 @@ func wellKnownModule(name string) bool {

// EnableServiceMonitor add a servicemonitor that allows prometheus to scrape from the monitoring endpoint of the cluster
func (c *Cluster) EnableServiceMonitor() error {
serviceMonitor := k8sutil.GetServiceMonitor(AppName, c.clusterInfo.Namespace)
serviceMonitor := k8sutil.GetServiceMonitor(AppName, c.clusterInfo.Namespace, serviceMonitorPort)
cephv1.GetMonitoringLabels(c.spec.Labels).OverwriteApplyToObjectMeta(&serviceMonitor.ObjectMeta)

if c.spec.External.Enable {
Expand Down
5 changes: 3 additions & 2 deletions pkg/operator/ceph/cluster/nodedaemon/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ func MakeCephExporterMetricsService(cephCluster cephv1.CephCluster, servicePortM
}

// EnableCephExporterServiceMonitor add a servicemonitor that allows prometheus to scrape from the monitoring endpoint of the exporter
func EnableCephExporterServiceMonitor(context *clusterd.Context, cephCluster cephv1.CephCluster, scheme *runtime.Scheme, opManagerContext context.Context) error {
serviceMonitor := k8sutil.GetServiceMonitor(cephExporterAppName, cephCluster.Namespace)
func EnableCephExporterServiceMonitor(context *clusterd.Context, cephCluster cephv1.CephCluster, scheme *runtime.Scheme, opManagerContext context.Context, servicePortMetricName string) error {
serviceMonitor := k8sutil.GetServiceMonitor(cephExporterAppName, cephCluster.Namespace, servicePortMetricName)

cephv1.GetCephExporterLabels(cephCluster.Spec.Labels).OverwriteApplyToObjectMeta(&serviceMonitor.ObjectMeta)

err := controllerutil.SetControllerReference(&cephCluster, serviceMonitor, scheme)
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/ceph/cluster/nodedaemon/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (r *ReconcileNode) createOrUpdateNodeDaemons(node corev1.Node, tolerations
}

if cephCluster.Spec.Monitoring.Enabled {
if err := EnableCephExporterServiceMonitor(r.context, cephCluster, r.scheme, r.opManagerContext); err != nil {
if err := EnableCephExporterServiceMonitor(r.context, cephCluster, r.scheme, r.opManagerContext, exporterServiceMetricName); err != nil {
return errors.Wrap(err, "failed to enable service monitor")
}
logger.Debug("service monitor for ceph exporter was enabled successfully")
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/k8sutil/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getMonitoringClient(context *clusterd.Context) (*monitoringclient.Clientset
}

// GetServiceMonitor creates serviceMonitor object template
func GetServiceMonitor(name string, namespace string) *monitoringv1.ServiceMonitor {
func GetServiceMonitor(name string, namespace string, portName string) *monitoringv1.ServiceMonitor {
return &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -62,7 +62,7 @@ func GetServiceMonitor(name string, namespace string) *monitoringv1.ServiceMonit
},
Endpoints: []monitoringv1.Endpoint{
{
Port: "http-metrics",
Port: portName,
Path: "/metrics",
Interval: "5s",
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/operator/k8sutil/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
func TestGetServiceMonitor(t *testing.T) {
name := "rook-ceph-mgr"
namespace := "rook-ceph"
servicemonitor := GetServiceMonitor(name, namespace)
port := "http-metrics"
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.NotNil(t, servicemonitor.GetLabels())
assert.NotNil(t, servicemonitor.Spec.NamespaceSelector.MatchNames)
assert.NotNil(t, servicemonitor.Spec.Selector.MatchLabels)
Expand Down

0 comments on commit 5fa6476

Please sign in to comment.