Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added label to all-pods service to narrow metrics scrape selection #277

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}