Skip to content

Commit

Permalink
Add namespace label on metrics (#574)
Browse files Browse the repository at this point in the history
* Add namespace label on metrics

* Add changelog entry

* Address Michael's comment
  • Loading branch information
adejanovski authored Oct 2, 2023
1 parent d9dfbc5 commit 34e2ae6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti

## unreleased

* [CHANGE] [#573](https://github.com/k8ssandra/cass-operator/issues/573) Add the namespace as env variable in the server-system-logger container to label metrics with.

## v1.17.2

* [ENHANCEMENT] [#571](https://github.com/k8ssandra/cass-operator/issues/571) Ensure both "server-config-init" as well as "server-config-init-base" are always created in the initContainers if 4.1.x is used.
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciliation/construct_podtemplatespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ func buildContainers(dc *api.CassandraDatacenter, baseTemplate *corev1.PodTempla
{Name: "CLUSTER_NAME", Value: dc.Spec.ClusterName},
{Name: "DATACENTER_NAME", Value: dc.DatacenterName()},
{Name: "RACK_NAME", ValueFrom: selectorFromFieldPath("metadata.labels['cassandra.datastax.com/rack']")},
{Name: "NAMESPACE", ValueFrom: selectorFromFieldPath("metadata.namespace")},
}

loggerContainer.Env = combineEnvSlices(loggerEnvDefaults, loggerContainer.Env)
Expand Down
4 changes: 3 additions & 1 deletion pkg/reconciliation/construct_podtemplatespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ func TestLoggerContainerEnvVars(t *testing.T) {
podNameEnvVar := corev1.EnvVar{Name: "POD_NAME", ValueFrom: selectorFromFieldPath("metadata.name")}
nodeNameEnvVar := corev1.EnvVar{Name: "NODE_NAME", ValueFrom: selectorFromFieldPath("spec.nodeName")}
rackNameEnvVar := corev1.EnvVar{Name: "RACK_NAME", ValueFrom: selectorFromFieldPath("metadata.labels['cassandra.datastax.com/rack']")}
namespaceEnvVar := corev1.EnvVar{Name: "NAMESPACE", ValueFrom: selectorFromFieldPath("metadata.namespace")}

templateSpec := &corev1.PodTemplateSpec{}
dc := &api.CassandraDatacenter{
Expand All @@ -482,11 +483,12 @@ func TestLoggerContainerEnvVars(t *testing.T) {
loggerContainer := findContainer(templateSpec.Spec.Containers, SystemLoggerContainerName)
assert.Equal(SystemLoggerContainerName, loggerContainer.Name)

assert.Equal(5, len(loggerContainer.Env))
assert.Equal(6, len(loggerContainer.Env))

assert.True(envVarsContains(loggerContainer.Env, podNameEnvVar))
assert.True(envVarsContains(loggerContainer.Env, nodeNameEnvVar))
assert.True(envVarsContains(loggerContainer.Env, rackNameEnvVar))
assert.True(envVarsContains(loggerContainer.Env, namespaceEnvVar))
assert.True(envVarsContains(loggerContainer.Env, corev1.EnvVar{Name: "CLUSTER_NAME", Value: dc.Spec.ClusterName}))
assert.True(envVarsContains(loggerContainer.Env, corev1.EnvVar{Name: "DATACENTER_NAME", Value: dc.DatacenterName()}))
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testdata/configs/vector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ data:
if err == null {
.rack = rack
}
namespace, err = get_env_var("NAMESPACE")
if err == null {
.namespace = namespace
}
'''
[sinks.console]
Expand Down

0 comments on commit 34e2ae6

Please sign in to comment.