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

Replace slash and period with underscore for label names #237

Merged
merged 1 commit into from
Aug 5, 2021

Conversation

jackatbancast
Copy link
Contributor

This change replaces all occurences of . and / in label
keys. Occasionally a kubernetes label will take the form of a url,
e.g. app.kubernetes.io/instance. In this case we would output that
key prefixed by our given parameter.

This can cause issues with systems such as ElasticSearch where it will
see the . as an object path separator and attempt to build the
object from the labels. This may work but is likely unintended
behaviour and can be surprising.

This issue is compounded if you have a matching key to the first
segment of the domain-prefixed key, e.g. app in our case. This would
conflict with the object that is being created by app.kubernetes.io
and potentially cause errors to occur.

By reducing the label key to a form similar to snake case we can
avoid this issue and provide dependant systems with a label form that
doesn't conflict. Additionaly we can provide more consistent behaviour.

@jackatbancast jackatbancast force-pushed the snake-case-console-label-keys branch from fb9490a to 8900ec0 Compare August 4, 2021 03:07
@jackatbancast jackatbancast marked this pull request as ready for review August 4, 2021 03:12
@VSpike VSpike changed the title Replace slash and period with underscope for label names Replace slash and period with underscore for label names Aug 4, 2021
VSpike
VSpike previously approved these changes Aug 4, 2021
benwh
benwh previously approved these changes Aug 4, 2021
Copy link
Contributor

@benwh benwh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// app_kubernetes_io_instance
func linearLabelKey(labelKey string) string {
labelKey = strings.ReplaceAll(labelKey, "/", "_")
labelKey = strings.ReplaceAll(labelKey, ".", "_")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered if we should be doing the same for dashes

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

But actually it seems like ES would be fine with these, so no issue there

pkg/logging/labels.go Outdated Show resolved Hide resolved
This change replaces all occurences of `.` and `/` in label
keys. Occasionally a kubernetes label will take the form of a url,
e.g. `app.kubernetes.io/instance`. In this case we would output that
key prefixed by our given parameter.

This can cause issues with systems such as ElasticSearch where it will
see the `.` as an object path separator and attempt to build the
object from the labels. This may work but is likely unintended
behaviour and can be surprising.

This issue is compounded if you have a matching key to the first
segment of the domain-prefixed key, e.g. `app` in our case. This would
conflict with the object that is being created by `app.kubernetes.io`
and potentially cause errors to occur.

By reducing the label key to a form similar to snake case we can
avoid this issue and provide dependant systems with a label form that
doesn't conflict. Additionaly we can provide more consistent behaviour.

---

This change additionally includes some changes to the console
integration tests to increase the amount of time we wait for a short
duration. I've not confirmed this yet, but it appears that the amount
of time it takes to run tests in kubebuilder's envtest has increased,
leading to some flaky tests. Increasing the short timeout appears to
fix this issue, which can also be seen on the `master` branch.
@jackatbancast jackatbancast dismissed stale reviews from benwh and VSpike via 16c6dac August 4, 2021 16:24
@jackatbancast jackatbancast force-pushed the snake-case-console-label-keys branch from 8900ec0 to 16c6dac Compare August 4, 2021 16:24
@theobarberbany theobarberbany merged commit 0d87336 into master Aug 5, 2021
@theobarberbany theobarberbany deleted the snake-case-console-label-keys branch August 5, 2021 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants