diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index 36f3bb296..ce51d4227 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -34,6 +34,9 @@ const ( // RackLabel is the operator's label for the rack name CassOperatorProgressLabel = "cassandra.datastax.com/operator-progress" + // PromMetricsLabel is a service label that can be selected for prometheus metrics scraping + PromMetricsLabel = "cassandra.datastax.com/prom-metrics" + // CassNodeState CassNodeState = "cassandra.datastax.com/node-state" diff --git a/operator/pkg/reconciliation/construct_service.go b/operator/pkg/reconciliation/construct_service.go index 645b0056d..9c3778005 100644 --- a/operator/pkg/reconciliation/construct_service.go +++ b/operator/pkg/reconciliation/construct_service.go @@ -155,6 +155,7 @@ func newNodePortServiceForCassandraDatacenter(dc *api.CassandraDatacenter) *core func newAllPodsServiceForCassandraDatacenter(dc *api.CassandraDatacenter) *corev1.Service { service := makeGenericHeadlessService(dc) service.ObjectMeta.Name = dc.GetAllPodsServiceName() + service.ObjectMeta.Labels[api.PromMetricsLabel] = "true" service.Spec.PublishNotReadyAddresses = true nativePort := api.DefaultNativePort diff --git a/operator/pkg/reconciliation/construct_service_test.go b/operator/pkg/reconciliation/construct_service_test.go index a19635c47..b8ca2200f 100644 --- a/operator/pkg/reconciliation/construct_service_test.go +++ b/operator/pkg/reconciliation/construct_service_test.go @@ -4,6 +4,8 @@ package reconciliation import ( + "github.com/datastax/cass-operator/operator/pkg/oplabels" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "reflect" "testing" @@ -27,3 +29,27 @@ func TestCassandraDatacenter_buildLabelSelectorForSeedService(t *testing.T) { t.Errorf("buildLabelSelectorForSeedService = %v, want %v", got, want) } } + +func TestCassandraDatacenter_allPodsServiceLabels(t *testing.T) { + dc := &api.CassandraDatacenter{ + ObjectMeta: metav1.ObjectMeta{ + Name: "dc1", + }, + Spec: api.CassandraDatacenterSpec{ + ClusterName: "bob", + }, + } + wantLabels := map[string]string{ + oplabels.ManagedByLabel: oplabels.ManagedByLabelValue, + api.ClusterLabel: "bob", + api.DatacenterLabel: "dc1", + api.PromMetricsLabel: "true", + } + + service := newAllPodsServiceForCassandraDatacenter(dc) + + gotLabels := service.ObjectMeta.Labels + if !reflect.DeepEqual(wantLabels, gotLabels) { + t.Errorf("allPodsService labels = %v, want %v", gotLabels, wantLabels) + } +}