Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harry671003
Copy link
Contributor

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

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]


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/).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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]))
Copy link
Member

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.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

@CharlieTLe
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants