Repository navigation
Wire WorkflowTokenAvailableConstraint into ConstraintCheckerService behind feature flag - #16249
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic constraint injection in ConstraintCheckerService by appending a WorkflowTokenAvailableConstraint to jobs triggered by program status changes when the WORKFLOW_TOKEN_CONSTRAINT feature flag is enabled. Unit tests have been added to verify the trigger inspection and constraint injection logic. Feedback suggests optimizing getEffectiveConstraints to avoid redundant iterable concatenation and object allocation when the feature flag is disabled or the trigger is not a program status trigger.
| Iterable<Constraint> getEffectiveConstraints(Job job) { | ||
| List<? extends Constraint> persistedConstraints = job.getSchedule().getConstraints(); | ||
| if (!workflowTokenConstraintEnabled | ||
| || !containsProgramStatusTrigger(job.getSchedule().getTrigger())) { | ||
| return Iterables.concat(persistedConstraints, ImmutableList.<Constraint>of()); | ||
| } | ||
| return Iterables.concat( | ||
| persistedConstraints, ImmutableList.<Constraint>of(workflowTokenAvailableConstraint)); | ||
| } |
There was a problem hiding this comment.
When the feature flag is disabled or the trigger is not a program status trigger, getEffectiveConstraints unnecessarily wraps the persisted constraints in a concatenated iterable with an empty list using Iterables.concat(persistedConstraints, ImmutableList.<Constraint>of()). Since this method is called for every job check in the polling loop, this redundant concatenation introduces unnecessary object allocation and iterator traversal overhead.
We can optimize this by changing the return type to Iterable<? extends Constraint> and returning persistedConstraints directly when the conditions are not met.
| Iterable<Constraint> getEffectiveConstraints(Job job) { | |
| List<? extends Constraint> persistedConstraints = job.getSchedule().getConstraints(); | |
| if (!workflowTokenConstraintEnabled | |
| || !containsProgramStatusTrigger(job.getSchedule().getTrigger())) { | |
| return Iterables.concat(persistedConstraints, ImmutableList.<Constraint>of()); | |
| } | |
| return Iterables.concat( | |
| persistedConstraints, ImmutableList.<Constraint>of(workflowTokenAvailableConstraint)); | |
| } | |
| Iterable<? extends Constraint> getEffectiveConstraints(Job job) { | |
| List<? extends Constraint> persistedConstraints = job.getSchedule().getConstraints(); | |
| if (!workflowTokenConstraintEnabled | |
| || !containsProgramStatusTrigger(job.getSchedule().getTrigger())) { | |
| return persistedConstraints; | |
| } | |
| return Iterables.concat( | |
| persistedConstraints, ImmutableList.of(workflowTokenAvailableConstraint)); | |
| } |
b44b180 to
ba00b11
Compare
1c567d0 to
52d8d1d
Compare
ba00b11 to
ac55927
Compare
52d8d1d to
2748590
Compare
Summary
Wires
WorkflowTokenAvailableConstraintintoConstraintCheckerServicebehindFeature.WORKFLOW_TOKEN_CONSTRAINT(defaultfalse) for schedules triggered by program status notifications, including composite (AND/OR) triggers.Changes
ConstraintCheckerService:Feature.WORKFLOW_TOKEN_CONSTRAINTviaDefaultFeatureFlagsProvider(cConf)and constructWorkflowTokenAvailableConstraintwith the configured wait timeout, mapping property key, required token key, andMetricsCollectionService.containsProgramStatusTrigger(Trigger)to recursively detectProgramStatusTriggeracrossAbstractSatisfiableCompositeTrigger(AndTriggerandOrTrigger) hierarchies.getEffectiveConstraints(Job)and evaluate it inconstraintsSatisfiedsoWorkflowTokenAvailableConstraintis appended at check time when the feature flag is enabled without persisting it onto schedules.ConstraintCheckerServiceTest.Testing
ConstraintCheckerServiceTest.