Skip to content

Commit d823d63

Browse files
authored
Ingester: convert global limits to local using actual ring ownership (#7954)
* ring: add ZonalOwnership to report per-zone write ownership Add (*Ring).ZonalOwnership(op), which returns the fraction of its zone's hash space each instance receives for writes made with op. Tokens of instances that op skips and replaces with the next instance (for example JOINING/LEAVING with Write, READONLY with either write op) are left out, so their ranges fall to the next remaining token in the zone, matching Ring.Get. The result is cached per operation and invalidated when tokens or instance states change, including state refreshes of cached shuffle-shard subrings. This is a building block for computing per-ingester local limits from actual ring ownership instead of assuming an evenly balanced ring. Signed-off-by: Alan Protasio <alanprot@gmail.com> * ingester: convert global limits using the ingester's ring ownership Add the experimental -ingester.use-ring-ownership-for-limits flag. With zone-aware replication, global series and metadata limits are converted to local limits as global * share, where share is the fraction of the tenant's hash space (or shuffle shard) this ingester owns within its zone. The current conversion assumes every ingester owns an equal share, so on an unevenly balanced ring tenants are throttled on the ingesters with the largest share well before they reach their global limit. The ownership is computed from a ring fed by the ingester's own heartbeats (the Lifecycler already reads the full ring on every CAS), so no KV store watch or traffic is added. Shares are refreshed every 10s off the push path. Until the first refresh, for tenants whose shard does not include this ingester, and without zone awareness, the existing conversion is used. The write operation used for ownership follows -distributor.extend-writes so the shares describe where the distributor actually sends series. Signed-off-by: Alan Protasio <alanprot@gmail.com> * ingester: require RF == zones for ownership-based limits Zonal shares assume each zone holds one copy of every key. Reject -ingester.use-ring-ownership-for-limits without zone-aware replication, and fall back to the equal-share conversion while the number of zones in the ring differs from the replication factor (for example when a zone is excluded or scaled to zero, and Get places a second copy in another zone). Signed-off-by: Alan Protasio <alanprot@gmail.com> * Add PR number to CHANGELOG Signed-off-by: Alan Protasio <alanprot@gmail.com> * ingester: add an integration test for ownership-based limits Add TestIngesterRingOwnershipLimits: six ingesters across three zones with a replication factor of 3, two per zone with tokens pinned through a tokens file so the first of each pair owns 3/4 of its zone's hash space, shuffle sharding, and a real distributor routing the writes. A tenant pushing 1600 series against a global limit of 2000: equal share (today) 1300 of 1600 accepted, the 3/4-share ingesters pinned at the equal share of 1000 ring ownership 1600 of 1600 accepted, 1174 and 426 per zone A second tenant with a 3-instance shard (one ingester per zone, so each owns all of that tenant's hash space) reaches the same global limit on every arm, and the test asserts its series are held by exactly three ingesters: with the shares read from the full ring instead of the tenant's subring, the small-token ingester in its shard would reject most of them. Expose cortex_ingester_ring_ownership_share{user}, so the share in use is visible to operators and the test can wait for it rather than sleeping. The series use random label values, not a sequential run: the FNV-1a hash Cortex shards series with is skewed enough over "0".."1599" that only 57% of them fall in the first 3/4 of the token space, which hides the effect. Publish the e2e framework's container ports on 127.0.0.1 rather than every interface. The tests already reach services through 127.0.0.1, so a bare host port only widened who could reach an unauthenticated Cortex on the machine running them. Signed-off-by: Alan Protasio <alanprot@gmail.com> * Fix lint - maps.Copy instead of a copy loop (modernize). - go.uber.org/atomic instead of sync/atomic, which faillint blocks. Signed-off-by: Alan Protasio <alanprot@gmail.com> * ingester: widen the ownership limits integration test to nine ingesters Three ingesters per zone instead of two, with tokens pinned so that within its zone the first owns 1/2 of the hash space and the other two 1/4 each. The second tenant's shard is now six of the nine, two per zone, so it is a real subset and ShuffleShard builds an actual subring. Its name is chosen so the shard is the 1/2-share and one 1/4-share ingester of every zone, which own 3/4 and 1/4 of that tenant's hash space: shares that exist only in the subring, where the whole ring would give the first 1/2. Both tenants now assert both arms, and the expected shares are derived from a ring built from the same instances rather than hardcoded. A tenant pushing 3200 series against a global limit of 4000: equal share whole ring: 2800 accepted, the 1/2-share ingesters pinned at the equal share of 1333 6-instance shard: 2600 accepted, the 3/4-share ingesters pinned at their equal share of 2000 ring ownership both: 3200 accepted, 1571/805/824 and 2370/830 Doubled the series count and the limit: at half this scale the margin between an ingester's load and its limit was about two standard deviations of how unevenly the series hash over the token space, close enough that the noise could decide the verdict. Signed-off-by: Alan Protasio <alanprot@gmail.com> * ingester: push the whole global limit in the ownership limits test Each tenant now pushes 4000 series against a global limit of 4000, so every ingester of its shard ends up at its own limit and the test measures how much of the limit the tenant can actually use, rather than whether a load comfortably inside it is rejected. equal share whole ring 3327/4000 (83.2%), 1/2-share ingesters pinned at the equal share of 1333 6-instance shard 3021/4000 (75.5%), 3/4-share ingesters pinned at their equal share of 2000 ring ownership whole ring 3991/4000 (99.8%), 6-shard 3979 (99.5%) The test asserts at least 95% with ownership-based limits and at most 90% without. Not 100%: the series do not hash perfectly evenly over the token space, so an ingester landing marginally over its own limit rejects a few. Both figures are deterministic, since the label values come from a fixed seed, and match a calculation over the same hash to within one series. How much was stored is now read from the ingesters per zone rather than counted from accepted requests: a request is rejected as a whole even when some of its series were written, so counting requests understates it. Signed-off-by: Alan Protasio <alanprot@gmail.com> --------- Signed-off-by: Alan Protasio <alanprot@gmail.com>
1 parent d292d56 commit d823d63

16 files changed

Lines changed: 1494 additions & 3 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [FEATURE] Storage: Add support for Alibaba Cloud OSS as a backend for blocks, ruler, and alertmanager storage. Configured via `-<prefix>.oss.*` flags with `backend: oss`. #7907
99
* [ENHANCEMENT] Compactor: Add `-compactor.block-ranges-compaction-delay` to configure the compaction group graceful period per `-compactor.block-ranges` entry, matched by position. A larger block range can now be held back until its sub-ranges have settled, instead of every range sharing one period derived from `-compactor.cleanup-interval`. Leaving it empty, and any range without an entry, keeps the current behaviour of twice `-compactor.cleanup-interval`. The delay is a lower bound: groups only become eligible on a compaction run, so the effective wait can be up to `-compactor.compaction-interval` longer. Only used by the partitioning compaction strategy. #7916
1010
* [ENHANCEMENT] Ring: Add the `cortex_ring_member_zonal_ownership_percent{name, member, zone}` metric, reporting the fraction of its own zone's token space owned by each ring member. With zone-aware replication a write is routed within a single zone, so the existing `cortex_ring_member_ownership_percent`, which is computed over the merged token list of all zones, does not reflect the hash range a member actually serves. Reported when ring detailed metrics and zone awareness are both enabled. #7910
11+
* [ENHANCEMENT] Ingester: Add experimental `-ingester.use-ring-ownership-for-limits`. With zone-aware replication, global series and metadata limits are converted to per-ingester limits using the share of each tenant's hash space (or shuffle shard) the ingester owns within its zone, instead of assuming every ingester owns an equal share. Requires zone-aware replication; while the number of zones in the ring differs from the replication factor, the equal-share conversion is used. On an unevenly balanced ring the equal-share assumption throttles tenants on the ingesters with the largest share well before they reach their global limit. The ring is read from the ingester's own heartbeats, so no KV store traffic is added. The share in use is exposed as `cortex_ingester_ring_ownership_share{user}`. #7954
1112
* [ENHANCEMENT] Distributor: Support partial write for Prometheus Remote Write 2.0 requests. Invalid series are now skipped and reported together in the `400` response instead of rejecting the whole batch, the valid ones are written, and the `X-Prometheus-Remote-Write-*-Written` response headers are set even when a `400` is returned. #7761
1213
* [ENHANCEMENT] Ruler: Add rule information to query parameters sent to the Query Frontend when `-ruler.frontend-address` is configured, so the Query Frontend query stats logs (`-frontend.enabled-ruler-query-stats`) can identify the evaluated rule. In this mode, the Ruler query stats log (`-ruler.query-stats-enabled`) omits the fetched statistics fields, which are always zero. #6539
1314
* [ENHANCEMENT] gRPC: When `-auth.enabled=true`, a gRPC request without the `X-Scope-OrgID` metadata is now rejected with the `UNAUTHENTICATED` status code instead of `UNKNOWN`. #7873

‎docs/configuration/config-file-reference.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,6 +4252,15 @@ lifecycler:
42524252
# CLI flag: -ingester.upload-compacted-blocks-enabled
42534253
[upload_compacted_blocks_enabled: <boolean> | default = true]
42544254
4255+
# Experimental: Convert global series and metadata limits to local ones using
4256+
# the share of each tenant's hash space this ingester owns within its zone,
4257+
# instead of assuming every ingester owns an equal share. Requires zone-aware
4258+
# replication. While the number of zones in the ring differs from the
4259+
# replication factor, the equal-share conversion is used. Applies only to the
4260+
# limits that are divided across ingesters.
4261+
# CLI flag: -ingester.use-ring-ownership-for-limits
4262+
[use_ring_ownership_for_limits: <boolean> | default = false]
4263+
42554264
instance_limits:
42564265
# Max ingestion rate (samples/sec) that ingester will accept. This limit is
42574266
# per-ingester, not per-tenant. Additional push requests will be rejected.

‎docs/configuration/v1-guarantees.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ Currently experimental features are:
152152
- `-blocks-storage.expanded_postings_cache.head.lazy-matcher-max-cardinality` (int) CLI flag
153153
- `-blocks-storage.expanded_postings_cache.head.lazy-matcher-simple-cost-ratio` (int) CLI flag
154154
- `-blocks-storage.expanded_postings_cache.head.lazy-matcher-complex-cost-ratio` (int) CLI flag
155+
- Ingester: Ring ownership for limits
156+
- `-ingester.use-ring-ownership-for-limits` (boolean) CLI flag
155157
- Ingester: Head Queried Series Metrics
156158
- Enable on Ingester via `-ingester.head-queried-series-metrics-enabled=true`
157159
- Tracks unique series queried from head only (not blocks) using HLL

‎integration/e2e/service.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,11 @@ func (s *ConcreteService) buildDockerRunArgs(networkName, sharedDir string) []st
355355
args = append(args, "--workdir", s.workDir)
356356
}
357357

358-
// Published ports
358+
// Published ports. Published to loopback only: tests reach services through
359+
// 127.0.0.1 (see Endpoint), and a bare host port would publish them on every
360+
// interface of the machine running the tests.
359361
for _, port := range s.networkPorts {
360-
args = append(args, "-p", strconv.Itoa(port))
362+
args = append(args, "-p", "127.0.0.1::"+strconv.Itoa(port))
361363
}
362364

363365
// Disable entrypoint if required

0 commit comments

Comments
 (0)