-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Allow a custom label for sharding. #6437
Comments
I thought we already had an issue about this but I can't find it but definitely 👍 for the idea of zone sharding. |
The main issue here is that zones are cloud provider specific and not all scraping configs support the same set of labels. My idea (for our case) is that we have re-labeling rules for different cases which generate a unified label. That would only work though if dropping happens after these rules have been evaluated. For pod based metrics the idea was to use Kyverno (or some other suitable controller) to add a label on each pod containing the zone. A rule for this case could look like this: - source_labels: [__meta_kubernetes_pod_label_zone] # generated by us, same for all shards
separator: ;
regex: (.+)
target_label: zone
replacement: ${1}
action: replace
# ... more rewrite rules creating zone from other labels
- source_labels: [zone] # generated by operator per shard
separator: ;
regex: (.*)
modulus: 1
target_label: __tmp_hash
replacement: $1
action: hashmod
- source_labels: [__tmp_hash]
separator: ;
regex: "0"
replacement: $1
action: keep That would still be a bit fiddly, as the shards need to be placed in the correct zone based on the output of the hash. If we have an "equality" match for the zone label, this would make the placement simpler. - source_labels: [__meta_kubernetes_pod_label_zone] # generated by us, same for all shards
separator: ;
regex: (.+)
target_label: zone
replacement: ${1}
action: replace
# ... more rewrite rules creating zone from other labels
- source_labels: [zone] # generated by operator per shard
separator: ;
regex: "0"
replacement: $1
action: keep From the Prometheus/Prometheus agent CRD I'd expect to set the following shardingOn: "zone"
shardingByHash: false Now for the "helm could totally generate the equality check", you could add something like this shardValues:
- europe-west4-a
- europe-west4-b
- europe-west4-c When generating the per-shard rewrite rule, you could do something like |
My two cents! |
I think we would need to create the new field, get a hold of it in each of the config generating functions (for ServiceMonitor, PodMonitors) and pass the custom ShardingOn value in place of What do you think? @simonpasquier |
Let me try to summarize the requirements:
I could see something like:
In the case of @arnecls it would turn into
Open questions
|
I believe we want to deprecate |
I am not sure I follow what you are trying to say. __param_target label is used to pass the targets as parameters, and so we would not want the user to write something to that label. Are you referring to that? How is sharding on this label a problem, it would be, if we are writing to this label but that is not the case here IIUC. |
Probe targets are sharded differently from "regular" targets. How will it work in case of custom sharding? prometheus-operator/pkg/prometheus/promcfg.go Lines 1628 to 1630 in db27c61
prometheus-operator/pkg/prometheus/promcfg.go Lines 1280 to 1281 in db27c61
|
That's actually a good point. This could be solved via something like this (based on the previous suggestion) spec:
shardingStrategy:
perShardNodeAffinity:
label: 'topology.kubernetes.io/zone'
values:
- europe-west4-a
- europe-west4-b
# ... The value of the given label could then be calucluated via affinityValues := spec.shardingStrategy.perShardNodeAffinity.values
labelValue := affinityValues[shardNumber % len(affinityValues)] |
We've discussed this feature request during today's office hours and the general consensus was that we'd need a design proposal to move forward (https://prometheus-operator.dev/docs/prologue/contributing/#proposal-process). |
@simonpasquier if I understand that link (and the repository structure) correctly, a proposal requires a PR with a single file in As I initiated this issue, shall I write this doc? How do we collaborate on this? Is there a deadline/timeframe? |
Component(s)
Prometheus
What is missing? Please describe.
Currently the recording rule assigning endpoint to shards is hardcoded to
__address__
.prometheus-operator/pkg/prometheus/promcfg.go
Line 1613 in d87710b
We would like to be able to change the label and/or the method to, for example, allow zone aware sharding.
If all endpoints expose a certain label, let's say
zone
, either directly or through a rewrite rules, one could use this label instead of__address__
. This would allow more control over how endpoints are distributed amongst the available shards.In addition to this it would be nice to switch from hash based sharding to "value based sharding" where each shard is reacting to a specific value. This could be used to, for example, assign a specific shard to a specific zone, removing the need to find out which shard is scraping which zone after hashing.
Describe alternatives you've considered.
We're not aware of any alternative method to inject a "per-shard" rewrite rule to all metrics handled by a specific shard.
Environment Information.
Environment
Kubernetes Version: -
Prometheus-Operator Version: 0.72.0
The text was updated successfully, but these errors were encountered: