Limitations of Prometheus Labels

Better Stack Team
Updated on November 29, 2024

Prometheus labels are a powerful feature used to add dimensional data to metrics. However, improper use or lack of understanding of their limitations can lead to inefficiencies, high resource consumption, or incorrect results.

1. High cardinality issues

Labels can significantly increase the number of unique time series (cardinality) in Prometheus. Each unique combination of label values creates a new time series.

Example problem: If a metric has the label user_id with 1,000,000 unique users, it creates 1,000,000 time series.

Impact: - Increased memory usage. - Slower queries. - Higher storage requirements.

Mitigation: - Avoid high-cardinality labels like user IDs or UUIDs. - Use labels with limited and predictable values.

2. Label value limits

Prometheus stores each label value as part of a unique time series identifier. Excessively long label values can lead to storage and performance issues.

Example: A label like error_message="Detailed error log text..." can inflate storage usage unnecessarily.

Mitigation: - Use short, descriptive labels. - Avoid embedding dynamic or verbose data like logs.

3. Label names and values are immutable

Once a time series is created with a specific set of labels, it cannot be changed. If you need to correct a label name or value, you must create a new time series.

Example: If a label region="west" is mistakenly used instead of region="us-west", the incorrect time series will persist until data is aged out.

Mitigation: - Carefully plan label naming conventions. - Validate label values before they are exposed.

4. Query complexity

Labels increase the complexity of PromQL queries, making it harder to retrieve the desired data efficiently.

Example problem: Using many labels in a query can make it challenging to craft precise PromQL expressions, especially when some labels are not required for the analysis.

Mitigation: - Use by() and without() operators to simplify queries. - Avoid over-labeling metrics with unnecessary dimensions.

5. Aggregation challenges

Labels with many possible values can complicate aggregations and percentile calculations, leading to inefficient or misleading results.

Example: A query like sum(rate(http_requests_total[5m])) by (user_id) is inefficient if there are thousands of unique user_id values.

Mitigation: - Aggregate only over essential labels. - Use drop or group functions to reduce dimensionality.

6. No hierarchical relationships

Prometheus labels are flat and do not support hierarchical relationships natively, making it challenging to represent nested data structures (e.g., data center -> region -> country).

Mitigation: - Encode hierarchy in labels with clear conventions, such as region="us-west", datacenter="us-west-1".

7. Label ordering and uniqueness

Prometheus internally treats label order as part of the time series' unique identifier. Even if the same labels are present but in different orders, they are considered distinct.

Example: {label1="a", label2="b"} is different from {label2="b", label1="a"}.

Mitigation: - Always maintain a consistent label ordering in exporters or custom metrics.

Best practices for managing labels

  • Avoid unbounded or high-cardinality labels.
  • Use meaningful, concise label names and values.
  • Validate and sanitize labels before exposing them.
  • Follow consistent naming conventions.
  • Monitor cardinality with tools like prometheus_tsdb_head_series to prevent excessive time series.

Understanding and managing these limitations ensures that Prometheus remains efficient and scalable for your monitoring needs.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github