feat: add trigger weight for load distribution#3893
Open
yugannkt wants to merge 3 commits intoargoproj:masterfrom
Open
feat: add trigger weight for load distribution#3893yugannkt wants to merge 3 commits intoargoproj:masterfrom
yugannkt wants to merge 3 commits intoargoproj:masterfrom
Conversation
This adds a weight field to triggers that enables distributing events across multiple triggers based on configured weights. Key features: - Weight field (0-100) on Trigger struct - Hash-based routing using event ID for deterministic distribution - Weighted triggers are mutually exclusive (one executes per event) - Non-weighted triggers (weight=0) always execute - Works correctly with multiple sensor replicas Use cases: - A/B testing trigger implementations - Canary deployments - Load distribution across backends Fixes argoproj#3800 Signed-off-by: Yugan <yugannkt@gmail.com>
eduardodbr
reviewed
Feb 10, 2026
| // Returns true if the trigger should execute, false otherwise. | ||
| // The second return value indicates if weight-based routing is enabled for this trigger. | ||
| func shouldExecuteByWeight(trigger v1alpha1.Trigger, allTriggers []v1alpha1.Trigger, eventHash uint64) (bool, bool) { | ||
| // If weight is 0 or not set, weight-based routing is disabled for this trigger |
Member
There was a problem hiding this comment.
I think shouldExecuteByWeight doesn't need to return two bool.
When weightEnabled=false, shouldExecute is always true (the function returns (true, false) in those cases). So the condition weightEnabled && !shouldExecute is functionally equivalent to just !shouldExecute.
| weightedTriggers = append(weightedTriggers, TriggerWeightRange{ | ||
| TriggerName: t.Template.Name, | ||
| StartRange: totalWeight, | ||
| EndRange: totalWeight + t.Weight, |
| // Find if this trigger's range contains the calculated position | ||
| for _, wr := range weightedTriggers { | ||
| if wr.TriggerName == trigger.Template.Name { | ||
| if position >= wr.StartRange && position < wr.EndRange { |
Member
There was a problem hiding this comment.
here also, can trigger.Template be `nil´ ?
| for _, c := range id { | ||
| hash ^= uint64(c) | ||
| hash *= 1099511628211 | ||
| } |
Member
There was a problem hiding this comment.
why use all of this? the standard lib has hash/fnv lib.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title
feat: add trigger weight for load distribution (#3800)
Description
This PR adds a
weightfield to triggers that enables distributing events across multiple triggers based on configured weights. This addresses the feature request in #3800.Problem
Users want to route events to different triggers based on percentages - for example, send 30% of events to one trigger and 70% to another. This enables use cases like A/B testing, canary deployments, and load distribution.
Solution
Added a
weightfield (0-100) to theTriggerstruct that uses hash-based routing for deterministic event distribution.Example usage:
Key Features
weight: 0or omitted = trigger always executes (existing behavior)Testing
shouldExecuteByWeight()functionhashEventIDs()functionFixes #3800