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

Add namespace label on metrics #574

Merged
merged 3 commits into from
Oct 2, 2023
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
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
Loading