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

Alerting: Fix ambiguous handling of equals in labels when bucketing Loki state history streams #65013

Merged
merged 2 commits into from
Mar 21, 2023

Conversation

alexweav
Copy link
Contributor

What is this feature?

grafana-plugin-sdk's data.Labels type is the canonical dataframe type for handling labels.

Its LabelsFromString() and String() methods break on labels containing =. The format it uses is ambiguous.

We also can't use prometheus Labels format, its repr is also ambiguous around equals. Grafana's labels are a superset of Prometheus labels.

With this PR, we use a stable representation.

Why do we need this feature?

Allow equals to be used without issues.

Which issue(s) does this PR fix?:

Fixes #65012

Special notes for your reviewer:

@alexweav alexweav added this to the 9.4.8 milestone Mar 19, 2023
@alexweav alexweav requested a review from a team March 19, 2023 22:08
@@ -248,7 +248,12 @@ func statesToStreams(rule history_model.RuleMeta, states []state.StateTransition
labels[RuleUIDLabel] = fmt.Sprint(rule.UID)
labels[GroupLabel] = fmt.Sprint(rule.Group)
labels[FolderUIDLabel] = fmt.Sprint(rule.NamespaceUID)
repr := labels.String()
lblJsn, err := json.Marshal(labels)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Choice of JSON as a stable representation was somewhat arbitrary.

  • Hash of labels also works and is more compact. But, we're also relying on the labels being parseable later on, so we'd need to store the labels again separately, which undoes any memory savings.
  • data.LabelsFromString(...) already understands JSON, so no code changes needed on parse side.

Copy link
Member

@JohnnyQQQQ JohnnyQQQQ left a comment

Choose a reason for hiding this comment

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

LGTM

@alexweav alexweav merged commit cc7e5ce into main Mar 21, 2023
@alexweav alexweav deleted the alexweav/handle-equals branch March 21, 2023 17:33
@grafanabot
Copy link
Contributor

The backport to v9.4.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-65013-to-v9.4.x origin/v9.4.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x cc7e5ce62e314af09d59260ec385f531e88bf353
# Push it to GitHub
git push --set-upstream origin backport-65013-to-v9.4.x
git switch main
# Remove the local backport branch
git branch -D backport-65013-to-v9.4.x

Then, create a pull request where the base branch is v9.4.x and the compare/head branch is backport-65013-to-v9.4.x.

@grafanabot grafanabot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Mar 21, 2023
alexweav added a commit that referenced this pull request Mar 21, 2023
…oki state history streams (#65013)

* Use JSON instead of data.Labels string format as label repr

* Drop debug log line

(cherry picked from commit cc7e5ce)
alexweav added a commit that referenced this pull request Mar 21, 2023
…oki state history streams (#65135)

Alerting: Fix ambiguous handling of equals in labels when bucketing Loki state history streams (#65013)

* Use JSON instead of data.Labels string format as label repr

* Drop debug log line

(cherry picked from commit cc7e5ce)
@zerok zerok modified the milestones: 9.4.x, 9.4.8, 9.5.0 Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/alerting Grafana Alerting area/backend backport v9.4.x Mark PR for automatic backport to v9.4.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. kata:state-history type/bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Alerting: Loki state history doesn't handle entries with equals signs in labels
5 participants