-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix: mixin generation when cluster label is changed #12613
Conversation
c92564a
to
eb1a6e4
Compare
The diff after generation can be seen here https://github.com/QuentinBisson/loki-upstream/pull/1/files#diff-7691b03fc1df22118e5c4440a69f2f0420ae833be78dbfd8fee564ce1df510e0 |
@MichelHollands could you take a look at this? |
Signed-off-by: QuentinBisson <[email protected]>
f4ca44b
to
e858975
Compare
@JStickler Do you know who could help review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's enough changes here that we would want to test deploying these dashboards ourselves with your changes to check that nothing is broken, I don't have time to do that myself this week but I know @shantanualsi has been doing some dashboard work so maybe he can test them out?
message: std.strReplace(||| | ||
{{ $labels.cluster }} {{ $labels.namespace }} has had {{ printf "%.0f" $value }} compactors running for more than 5m. Only one compactor should run at a time. | ||
|||, | ||
|||, 'cluster', $._config.per_cluster_label), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will work as written, it will look specifically for cluster
in the string when in reality the values for the labels would be something like prod-<region>
and loki-prod-#
, so we would have prod-<region> loki-prod-# has had <some value> compactors running for more than 5m
as the message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my tests here, it actually replaces the label correctly in the rule https://github.com/QuentinBisson/loki-upstream/pull/1/files#diff-147d57f875c8b29ffd1bfb7026b4d16da82db9df6b9a2d7dfb1cb82d18fa50a4R36.
I tried to use the % syntax with %s but it did not work due to the printf "%.0f" $value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, the jsonnet strReplace
is happening earlier than I thought
is that still not incorrect though? in your code within config.libsonnet
the cluster_label
is still cluster
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only regenerated the ssd mixins so I changed this file https://github.com/QuentinBisson/loki-upstream/pull/1/files#diff-58c1308d64904785b992854f36800a299e22dbdab03edc9181729b506ad8a3c3R9 :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah okay! looks correct then
// Replace the recording rules cluster label with the per-cluster label | ||
then std.strReplace( | ||
// Replace the cluster label for equality matchers with the per-cluster label | ||
std.strReplace( | ||
// Replace the cluster label for regex matchers with the per-cluster label | ||
std.strReplace( | ||
expr, | ||
'cluster=~"$cluster"', | ||
$._config.per_cluster_label + '=~"$cluster"' | ||
), | ||
'cluster="$cluster"', | ||
$._config.per_cluster_label + '="$cluster"' | ||
), | ||
'cluster_', | ||
$._config.per_cluster_label + '_' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just noting that having to do something like this is yet another reason for us to try and get rid of these giant copy/paste json dashboards at some point
@@ -9,10 +9,9 @@ local utils = import 'mixin-utils/utils.libsonnet'; | |||
local cfg = self, | |||
|
|||
showMultiCluster:: true, | |||
clusterLabel:: $._config.per_cluster_label, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we removing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because it is unused
@@ -31,10 +31,9 @@ local utils = import 'mixin-utils/utils.libsonnet'; | |||
local cfg = self, | |||
|
|||
showMultiCluster:: true, | |||
clusterLabel:: $._config.per_cluster_label, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here and others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, I did not see it being used
Also @cstyan and @shantanualsi this #12567 might be easier to review as it only fixes the compactor pod matcher which is currently broken |
And thanks for the review :) |
for: 5m | ||
labels: | ||
severity: warning | ||
- name: loki_alerts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these indentation changes intentional or from your editor? can you please keep the original indentation so as to keep this diff clean? thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those happen when we generate the alerts from the mixins so I can realign them sure but they probably hsould not have been indented at all :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you want me to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the confusion here was caused by differences in jsonnet
versions that were generating the compiled mixin, that's my fault. I added the github action to check the jsonnet linting and compiled mixins, which is using a different version of jsonnet
within the build image. So unfortunately make loki-mixin
and make BUILD_IN_CONTAINER=false loki-mixin
will get you different results at the moment. I'm working on resolving that today.
@QuentinBisson I'll try and spend some time testing these changes today on our dashboards. Meanwhile, when you get some time, can you resolve the conflicts on this PR? |
@shantanualsi thanks for reviewing those :) I fixed the conflicts and the list of changes is a lot less :D |
Had a chance to test this out locally, no obvious breakages so lets merge and we can deal with any issues via follow up PRs |
Thank you for the merge :) |
What this PR does / why we need it:
This PR fixes mixin generation when the per_cluster_label value is changed
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Checklist
CONTRIBUTING.md
guide (required)docs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PRdeprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR