Skip to content

Conversation

salvacorts
Copy link
Contributor

@salvacorts salvacorts commented Oct 7, 2025

What this PR does / why we need it:

This is a followup for #18994. Here we update the new limits service to support the policy-overridable stream limits.

We modified the tenantUsage to add a new map of policies so we can track the number of streams per policy independently. This way, the stream of a policy with a stream limit override does not account for the global stream limit and vice-versa.

Special notes for reviewer:

I see two ways to get the policy for each stream on the stream service:

Option 1 - What's implemented in this PR:

Update: @grobinson-grafana and I agreed on this approach

We resolve the policy for each stream on the distributor, and pass the policy (if any) on the proto.StreamMetadata that is part of the proto.ExceedsLimitsRequest distributor sends to the limits frontend and this to the limits service.

Resolving the policies for a stream can be somewhat expensive as we need to check the stream matchers from the mappings against the stream labels. This way we only resolve the policies once on the distributors which is already done anyways.

Option 2

Resolve the policies again on the limits service. This would make a bit of more work, but will reduce the request size. Plus we can decide to only resolve the policy for those policies that are overriding the stream limits.

We are considering allowing to set the policy via a header on the gateway, so this option may end up being a bit more complicated since we'd need to pass the header from the distributors down to the limits service.


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
  • 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

@salvacorts salvacorts force-pushed the salvacorts/per-policy-stream-limits-on-limits-service branch from 7c5cd05 to 40895ee Compare October 8, 2025 10:17
@salvacorts salvacorts force-pushed the salvacorts/per-policy-stream-limits-on-limits-service branch from 40895ee to 5f1990f Compare October 8, 2025 10:30
@salvacorts
Copy link
Contributor Author

I tested it in dev and works fine

Given these tenant overrides
image

I pushed 5k streams for source=app, and 1k for source=synthetic-monitoring. I modified the endpoint on the limits-service to return the per policy streams and as can be seen, the sum of total streams is indeed over the configured max_global_streams_per_user: 5000, but the no-poliocy bucket is below 5k and the synthetic-monitoring policy bucket is also below 1k.

image

@salvacorts salvacorts marked this pull request as ready for review October 10, 2025 09:37
@salvacorts salvacorts requested a review from a team as a code owner October 10, 2025 09:37
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.

1 participant