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

feat(api)!: Fail log queries when executed on instant query endpoint #13421

Merged
merged 6 commits into from
Jul 5, 2024

Conversation

chaudum
Copy link
Contributor

@chaudum chaudum commented Jul 4, 2024

What this PR does / why we need it

Background

A log selector expression is a LogQL expression that returns logs, in contrast to a sample expressions, which returns metrics (samples). The simplest form of log selector expressions are label matchers, e.g. {env="prod"}.

Change

This PR changes the behaviour of Loki so that the instant query endpoint /api/v1/query does not allow sending a log selector expression as query any more. Instead, it returns a status code 400 (Bad Request) with the error message "log queries are not supported as an instant query type, please change you query to a range query type".

Why
Previously this API endpoint allowed these types of log queries, but returned inconsistent results, which where a major cause for confusion. Returning a concise error helps the user understand that they likely selected the wrong query type in Grafana when executing the query.

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

A log selector expression is a LogQL expression for returning logs, in
contrast to sample expressions, which return metrics. The simplest form
of log selector expressions are label matchers, e.g. `{env="prod"}`.

This PR changes the behaviour of Loki so it does not allow using a log
selector expression when the instant query endpoint `/api/v1/query` is
queried.

Previously this endpoint allowed these types of log queries, but returns
inconsistent results, which where a major cause for confusion. Returning
a concise error helps the user understand that they likely selected the
wrong query type in Grafana when executing the query.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
@chaudum chaudum requested a review from a team as a code owner July 4, 2024 21:00
chaudum added 3 commits July 4, 2024 23:07
…tant query

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
… as instant query

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
@chaudum chaudum changed the title feat: Fail request when log selector expression is used as instant query breaking(api): Fail log queries when executed on instant query endpoint Jul 4, 2024
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
@chaudum chaudum changed the title breaking(api): Fail log queries when executed on instant query endpoint feat(api)!: Fail log queries when executed on instant query endpoint Jul 4, 2024
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Jul 5, 2024
Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

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

🎉 ❤️ (Not super familiar with these parts of Loki yet, so a second pair of eyes would be nice)

Copy link
Collaborator

@slim-bean slim-bean left a comment

Choose a reason for hiding this comment

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

LGTM, with one request:

Please add some details to the upgrade guide for this, I don't think it would be commonly used but if it was, the workaround here would be to do a range query with limit 30

@chaudum
Copy link
Contributor Author

chaudum commented Jul 5, 2024

Please add some details to the upgrade guide for this, I don't think it would be commonly used but if it was, the workaround here would be to do a range query with limit 30

Ok, will do that in a follow up PR.

My reason for not putting anything into the UPGRADE guide was, that I thought the upgrade notes were for operational changes.

But I agree, it note would be helpful.

@chaudum chaudum merged commit ce71f1c into main Jul 5, 2024
61 checks passed
@chaudum chaudum deleted the chaudum/fail-logselectorexpr-for-instant-queries branch July 5, 2024 20:18
chaudum added a commit that referenced this pull request Jul 8, 2024
Follow up to #13421

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants