Skip to content

Commit

Permalink
Added label to all-pods service to narrow metrics scrape selection (#277
Browse files Browse the repository at this point in the history
)
  • Loading branch information
itzg authored Oct 20, 2020
1 parent b0eae79 commit 193afa5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions operator/pkg/reconciliation/construct_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions operator/pkg/reconciliation/construct_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
}
}

0 comments on commit 193afa5

Please sign in to comment.