-
Notifications
You must be signed in to change notification settings - Fork 816
Blog: Optimizing promql queries #6697
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
base: master
Are you sure you want to change the base?
Conversation
|
||
This guide explains how Cortex evaluates PromQL queries, details how time series data is stored and retrieved, and offers strategies to write performant queries—particularly in high-cardinality environments. | ||
|
||
Note: If you are new to PromQL, it is recommended to with the [Querying basics documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/). |
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.
Note: If you are new to PromQL, it is recommended to with the [Querying basics documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/). | |
Note: If you are new to PromQL, it is recommended to first read the [Querying basics documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/). |
Label matchers define the selection criteria for time series within the TSDB. Consider the following PromQL expression: | ||
|
||
``` | ||
sum(rate(http_requests_total{cluster="prod", job="envoy"}[5m])) |
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.
We can simplify to just the essential bits needed for the example.
sum(rate(http_requests_total{cluster="prod", job="envoy"}[5m])) | |
http_requests_total{cluster="prod", job="envoy"} |
|
||
Cortex uses Prometheus's Time Series Database (TSDB) for storing time series data. The Prometheus TSDB is time partitioned into blocks. Each TSDB block is made up of the following files: | ||
|
||
* `ID` - ID of the block (ULID) |
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.
* `ID` - ID of the block (ULID) | |
* `ID` - ID of the block ([ULID](https://github.com/ulid/spec)) |
* `ID` - ID of the block (ULID) | ||
* `meta.json` - Contains the metadata of the block | ||
* `index` - A binary file that contains the index | ||
* `chunks` - Directory containing the chunk segment files. |
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.
* `chunks` - Directory containing the chunk segment files. | |
* `chunks` - Directory containing the chunk segment files |
* `index` - A binary file that contains the index | ||
* `chunks` - Directory containing the chunk segment files. | ||
|
||
More details: [TSDB format docs](https://github.com/prometheus/prometheus/blob/main/tsdb/docs/format/README.md) |
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.
More details: [TSDB format docs](https://github.com/prometheus/prometheus/blob/main/tsdb/docs/format/README.md) | |
More details: [TSDB format docs](https://github.com/prometheus/prometheus/blob/5630a3906ace8f2ecd16e7af7fb184e4f4dd853d/tsdb/docs/format/README.md) |
It's better to use a permalink in case files get moved around.
Hi @harry671003, could you move docs/blog/optimizing-promql-queries.md under /website/content/en/blog/2025 after rebasing from the master branch? I've set up the blog with #6725. |
What this PR does:
There has been some talk about creating a blog in Cortex.
#6471
This is my attempt at writing a blog post on optimizing PromQL queries with the audience being new users or Prometheus and Cortex.
Which issue(s) this PR fixes:
Fixes #
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]