Diagnosing high cardinality in Loki before it drives up cost and slows queries
When Loki queries slow down, ingestion starts returning rate limit errors, or storage costs climb faster than log volume, a label with too many values is a common cause. High cardinality in Loki means either a label that can take a very large number of distinct values, such as pod names, user IDs or trace IDs, or a combination of labels that multiplies into a large number of streams. Each unique label set becomes its own stream, so a label that changes with every request or every pod restart can quietly turn a modest cluster into one that is expensive to index and slow to search. Diagnose it when a new service is onboarded, when a team adds a label to a log pipeline, or when stream counts and ingestion errors rise without a matching rise in traffic.
Loki's default limit of 15 index labels is a guardrail, not a target. Teams that reach it usually have a labeling design problem rather than a need for more labels. Treat the limit as a signal to review which labels are indexed, and do not raise it to accommodate new fields. Before changing anything, confirm which label names your Loki version and configuration apply, and check the official Loki cardinality documentation for the current guidance on what counts toward the limit and how combinations of labels are evaluated.
The practical starting point is an inventory: list every label each log source attaches, then count the distinct values each one takes over a representative period in your own environment. Labels whose value counts grow with users, requests or pods are the usual suspects. Move those values out of the index, either into structured metadata or by filtering on the line content at query time, and keep only static, bounded labels such as cluster, namespace and environment as stream selectors. Record the stream count before and after each change so you can show whether the fix worked. The sibling sections on label practice and structured metadata cover how to make those choices.
Which high-cardinality fix fits which value
This table compares four remedies for a high-cardinality value: removing the label, keeping a bounded label, moving the value to structured metadata, or filtering on line content. Read each row against the value you found, then check the query trade-off and the Loki version and schema requirements before you change anything in production.
| Remedy | Best fit | Query trade-off | Confirm before choosing |
|---|---|---|---|
| Remove the label | Values that add no query value, such as a per-request ID that nobody filters on | Queries can no longer select by that value through the index | Which dashboards, alerts and saved queries reference the label |
| Keep a bounded label | Values with a small, stable set of options, such as cluster, namespace or environment | Fast stream selection on these labels with no extra cost | That the value count stays bounded over time and that it is within the default limit of 15 index labels |
| Move to structured metadata | High-cardinality fields people sometimes filter on, such as pod names, user IDs or trace IDs | Filterable at query time without creating streams, but not a stream selector, so queries can be slower than label matches | Your Loki version and schema support structured metadata, and that your index store is TSDB |
| Filter on line content | Values that only appear in the log text, such as an order number inside a message | Flexible and needs no configuration change, but scans matching chunks so it costs more at large volume | Whether the value is common enough in the time range that line filters stay fast enough for your queries |
How to find the labels that explode your stream count
This sequence moves from a full inventory of labels and stream counts to a specific fix for each offending label, with a check after every change so you can confirm the stream count falls and queries still return data.
Inventory label names and value counts per tenant
Start by listing every label name in use and how many distinct values each one carries, tenant by tenant. Run this against the Loki query interface or your Grafana Explore view, and record the results in a sheet your platform team can review. Pull the label list for each tenant separately, because one tenant's noisy label can hide inside a cluster-wide total. The step is done when you have a table of label names, distinct value counts and the tenant each row belongs to. Confirm the inventory against a known workload before you trust it.
Flag labels with unbounded values
Review the inventory and mark any label whose values grow with traffic or with individual users, such as pod names, user IDs, request IDs or trace IDs. Bounded labels like cluster, namespace and environment have a small, fixed set of values and can stay. Treat a label as suspect when its value count keeps rising over time rather than settling. The output is a short list of offenders with a note on why each one is unbounded. Check the list by sampling a few values of each flagged label to confirm they are per-request or per-instance.
Check label combinations that multiply streams
A label can look harmless alone and still create many streams when combined with another. Loki counts each unique set of label values as one stream, so two moderate labels can produce a large product. For each candidate pair or group of labels, estimate the number of unique combinations from your inventory and note the combinations that dominate stream creation. Compare the stream count reported for the tenant against the sum you expect from single labels to spot the multiplier. The step ends with a ranked list of label sets to address, and you know it is done when each high-count combination has an owner in your notes.
Confirm which labels are indexed against the default limit
Loki has a default limit of 15 index labels, so count the labels currently indexed for each stream and compare the total to that limit. Look at the labels your agents and pipelines attach, including labels added automatically from resource attributes or client defaults. Note any tenant where the count is at or near 15, because extra labels either fail or push other labels out depending on your configuration. Confirm the configured limit in your own environment, since a tenant may have overridden it. The step closes with a per-tenant count of indexed labels that you can compare against the offender list.
Choose a fix for each offending label
For each offender, decide whether to drop it, move it into structured metadata, or convert the filter into a line filter in queries. Drop labels that nobody queries. Move per-request or per-instance identifiers that you need for lookups into structured metadata so they stay searchable without adding streams. Use line filters for values that only appear in the log body and are rarely needed as selectors. Record the decision, the owner and the agent or pipeline change required for each label. The output is a change list that a platform engineer can apply without redesigning the whole pipeline.
Apply one change and confirm the stream count drops
Apply the first change in a non-production tenant or a single pipeline, then recheck the stream count for that tenant using the same query you used in the inventory. The count should fall once the label stops being indexed, and the drop should match what the combination analysis predicted. If the count does not move, look for another source still attaching the label, such as a sidecar or a default client setting. Repeat this check for each change, one at a time, so a regression can be traced to a single edit.
Verify queries still return results after each move
After a label is moved into structured metadata or replaced with a line filter, run the queries your teams depend on and confirm they still return the expected lines. Compare result counts for a fixed time window before and after the change, and check that filters referencing the old label were updated. A query that returns nothing usually means a selector still names the old label. Record the queries you tested and their results so the change can be reviewed later. The step is done when every key query returns results that match the pre-change baseline.
Decision path from a noisy label to a fix
Start with a candidate label and ask three questions in order: is the value bounded, does it multiply stream combinations, and is it needed to select logs. A value that is bounded and needed for selection stays a label. An unbounded value that is only needed for lookup moves to structured metadata, and a value you only search for in the text becomes a line filter. Check each answer against the label count and the stream count before you change the configuration.
Three checks decide whether a label stays, moves to structured metadata or becomes a line filter.
Security and operational risks when relabeling logs
Moving fields out of labels changes more than query speed. It can split streams, alter which users can see which logs, and break the dashboards and alerts your teams rely on. The cards below cover the checks to run before and after each change.
Stream splits change history
Adding, removing or renaming an index label creates a different stream identity from that point on. Logs already stored under the old label set stay where they are, so a query that spans the change may return two sets of streams that look like one service. Check how far back your queries need to reach and whether dashboards depend on continuous series. Test the change in a non-production tenant first and confirm how your Loki version handles existing data before you roll it out.
- Default index labels
- 15
Label-based access rules
If your access model selects logs by label, for example a team or environment label, moving or dropping that label can silently widen or narrow what a group can read. A value that was an index label may become structured metadata that your access layer does not evaluate the same way. Before any change, list every access rule, proxy policy and dashboard permission that matches on a label, and verify each one with a test user from each group after the change.
Loki authentication docsBroken dashboards and alerts
A dashboard panel or alert rule that filters on a label you moved or removed will return no data, and the failure often looks like a quiet service rather than an error. Alert rules that count streams or match on a removed label can stop firing without any notice. Inventory the LogQL in dashboards, alert rules and saved queries that reference each affected field, update them in the same change window, and keep a rollback path for the earlier query.
Per-tenant label settings
When multi-tenancy is enabled, each tenant identified by its X-Scope-OrgID header can have its own limits and label behavior, so a change that suits one team can break another. A tenant that sends different label sets from the same source may need a separate review. Record which tenant IDs exist, which overrides each one uses and who owns each tenant, then review every tenant that receives the affected source before the change goes live.
Multi-tenancy docsMasking sensitive values
Moving a user ID or account number from a label to structured metadata does not remove it from storage. The value still lands in logs, stored chunks and any retention or deletion scope you apply later. If a field is sensitive, decide whether it should be masked, hashed or dropped in the shipping pipeline before Loki receives it. Ask your privacy and security teams to classify each field first, and confirm with your collector configuration that masking happens before ingestion.
Staged rollout and monitoring
Label changes take effect on new data as it is ingested, so mistakes spread as soon as the collector config is deployed. Roll changes out one source or tenant at a time, and watch stream counts, ingestion errors and query results for each step. Keep the previous collector configuration available so you can revert quickly. Record who approved each change, when it took effect and which dashboards were verified, so the change history can support later audits.
Limits to confirm in your Loki environment
Is the default limit of 15 index labels still in place in my cluster?
Loki's default limit is 15 index labels, and it applies unless your tenants have changed it. Check the per-tenant limits that your administrators have set, because a value raised for one team does not reach another. Compare the configured limit with the labels your pipelines actually send, including labels added by Alloy, Fluent Bit or the OpenTelemetry promotion rules. The official cardinality guidance explains why a long label list is a symptom to investigate rather than a setting to raise by default. Ask the platform team for the effective limit per tenant, not the value in the base configuration file.
How does stream count behave in my Loki version?
Every unique combination of label values creates a separate stream, so stream count grows with the product of label values, not with the number of labels alone. Confirm how your version counts streams and which limits apply per tenant, including the active stream limit and the per-stream rate limit. Run a query over recent data to list the label combinations that produce the most streams, then check whether the count tracks pod names, user IDs or request IDs. Version-specific behavior should be read in the release notes for your exact build, which you can match against the Loki releases page.
Do I have structured metadata and TSDB on my schema?
Structured metadata depends on the schema and index configuration in use, so confirm both before moving any field out of labels. Check the active schema_config entries in your configuration, the index type and the schema version, and confirm the store is TSDB. Older index stores that the storage documentation lists as deprecated do not give you the same options. If a schema change is needed, it starts a new schema period, so plan it with the upgrade and storage owners. The storage documentation lists the supported index stores for your version.
How will line filters perform on my log volume?
Line filters scan the log content of the chunks selected by the stream selector, so their speed depends on how much data falls inside the time range and label filters. Measure a representative query on your own data with a realistic time window, then compare the bytes scanned and the query duration. If a filter must scan a large share of a day's logs, consider narrowing the stream selector or moving the field to structured metadata. Your query frontend and querier capacity also matter, so review the query statistics in Grafana or the query logs before you decide which fields need indexing.
How do my object store and compactor settings affect label changes?
Changing labels does not rewrite existing data, so old streams remain in object storage under their previous labels until retention removes them. Confirm your object store, how long chunks are kept, and whether the compactor is running with retention_enabled set. Retention is disabled by default, so historical high-cardinality streams can persist indefinitely unless you configure it. Storage cost and index size therefore keep reflecting the old labelling until data expires, so ask the storage owner for current bucket size, growth rate and the retention rules per tenant before estimating the effect of a change.
Can my team make these changes without a partner?
Your own team can make these changes if it has access to the Loki configuration, the Alloy or agent pipeline and the Grafana query tools. Most of the work is inventory and verification: listing labels, measuring stream counts, testing queries and checking retention. The effort depends on how many log sources you run and how many tenants share the cluster, and on who owns each pipeline. If you bring in a partner, the written scope should name the systems covered, the deliverables and the verification steps, and the quote should follow from that scope.
What should I ask for before changing labels in production?
Ask for a written inventory of current labels per tenant, stream counts for the busiest sources, the effective limits in force, the schema and index configuration, and the retention settings. Also ask for a test plan that compares query results and stream counts before and after the change in a non-production cluster. The official Loki documentation describes retention behavior that determines how long old streams stay queryable. Confirm the rollback path, the owner for each pipeline and the window in which old and new labelling run side by side.
What changes for queries and dashboards after the fix
Once a value leaves the index labels, it is no longer a stream selector, so queries must change from {pod="api-7f9c"} style matching to a line filter or a filter on structured metadata. A value moved to structured metadata is filtered after the stream is selected, using the label filter syntax in the query pipeline, and it still returns the same log lines. A value moved into the log line is found with a line filter such as |= "trace_id=..." or a regular expression, which scans more data than a label match. Before you move anything, rewrite your most-used queries against the new form and time them on a representative range, because the query that was fast on an index label may now read more chunks. Confirm the exact syntax for your Loki version in the LogQL documentation before you rely on it.
Dashboards, alert rules and recording rules that select on a removed label will return empty results or stop firing without any error, so inventory them first. Search every Grafana dashboard, alerting rule, ruler rule and saved query for the label name, including template variables that populate from label values, since those variables will go empty after the change. Update each one in a change window, and keep the old and new versions side by side for a short period so you can roll back a single panel. Pay particular attention to alerts, because a silent alert is the most damaging failure. Where a template variable used to list pod names, consider replacing it with a bounded label such as namespace or app that still narrows the view.
Verify the change by comparing results, not by checking that the query runs. Pick a fixed time window before the change and the same window after it, then compare line counts per stream group and the number of matches for a known trace ID or user ID in both periods. Check the active stream count and ingestion errors in the Loki monitoring metrics for the same windows, and confirm that per-tenant limits are not being hit by the new traffic shape. Ask the team that owns each alert to confirm it fires on a known test event. Record the query text, the window and the counts in your change record, so an auditor or a later engineer can see what was checked and when.
Official sources for Loki cardinality
The Loki documentation gives the rules behind label cardinality and the options for data that does not belong in labels. Read them before you change a label set, because the same stream rules apply to every tenant and every query. The cards below cover what to read first and what to check against your own streams.
Loki cardinality guide
This is the primary reference for how Loki counts streams. It explains that high cardinality comes from labels with many possible values and from combinations of labels that multiply into many streams. Read it before you audit your label set, so you measure the right thing. Check whether any label you rely on can take an unbounded number of values, such as pod names generated by autoscaling or user identifiers.
- Default index labels
- 15
Index label guidance
Use the labels documentation to decide which keys belong in the index. Labels should be static and bounded, such as cluster, namespace and environment. Compare each candidate label against the cardinality guide and confirm that its values stay within a predictable set. Any key that changes with every request or deployment is a candidate for structured metadata or line content instead.
Labels docsStructured metadata reference
Structured metadata lets you attach high-cardinality fields, such as trace IDs or pod names, to log lines without indexing them as stream labels. Before you move a field there, confirm that your Loki version and schema support it, and that your queries will filter on it correctly. Test the query cost on a copy of real traffic, since structured metadata is read differently from labels.
Per-tenant limits
Stream and label limits are enforced per tenant, so a single noisy workload can affect other teams sharing a cluster. Review the limits configuration to see which thresholds protect your cluster and whether they reject or throttle new streams. Confirm with your own tenant layout which limits you need to tune before you change any label scheme.
Multi-tenancy docsMulti-tenant identification
When auth is enabled, every request carries an X-Scope-OrgID header that identifies the tenant. Stream counts and label limits are tracked against that tenant, so mismatched headers can make one team's cardinality look like another's. Check that your agents and Alloy pipelines set the header consistently before you compare stream counts across environments.
Tenant docsHow DeployOpen scopes and delivers Loki cardinality work
DeployOpen approaches high-cardinality diagnosis as a scoped engagement inside your own infrastructure. We start from the streams your Loki cluster actually holds, find the labels driving the growth, and agree in writing which labels move to structured metadata or line filters before any change is made.
How we scope
- Review the label set and stream count of your existing Loki cluster before agreeing any changes.
- Agree in writing which labels are in scope, such as pod names, user IDs or trace IDs.
- Confirm the number of index labels in use against the default limit of 15 index labels.
- Define the tenants, log sources and query patterns that the label changes must keep working.
- Set deliverables, timelines and acceptance checks in a fixed-scope written agreement.
How we build
- Identify labels with many possible values and label combinations that create excess streams.
- Map each high-cardinality field to structured metadata, a line filter or removal from the pipeline.
- Update Grafana Alloy or other shipper configuration so the changed labels are applied consistently.
- Test LogQL queries against a non-production copy to confirm results match the original behavior.
- Check stream counts and ingestion behavior after each change, with results recorded for review.
How we hand over
- Document the final label schema, including which fields are indexed and why.
- Provide a runbook for spotting new high-cardinality labels before they reach production.
- Walk your platform and observability teams through the configuration and the verification steps.
- Deliver the configuration files and change records in your own repositories.
- Agree the handover criteria and the open items to confirm in your environment at sign-off.
How we support
- Ongoing support, upgrades and continuous review are available as a retainer.
- Retainers can cover periodic stream reviews as new services and log sources are added.
- Revisit the label schema when Loki versions or shipper configurations change.
- Confirm with your team which support hours and response expectations apply in the written scope.

