Skip to content

Wire WorkflowTokenAvailableConstraint into ConstraintCheckerService behind feature flag - #16249

Open
deepika-lalwani123 wants to merge 1 commit into
pr4-workflow-token-constraint-metricsfrom
pr5-workflow-token-constraint-wiring
Open

deepika-lalwani123 wants to merge 1 commit into
pr4-workflow-token-constraint-metricsfrom
pr5-workflow-token-constraint-wiring

Conversation

@deepika-lalwani123

Copy link
Copy Markdown

Summary

Wires WorkflowTokenAvailableConstraint into ConstraintCheckerService behind Feature.WORKFLOW_TOKEN_CONSTRAINT (default false) for schedules triggered by program status notifications, including composite (AND/OR) triggers.

Changes

  • Update ConstraintCheckerService:
    • Read Feature.WORKFLOW_TOKEN_CONSTRAINT via DefaultFeatureFlagsProvider(cConf) and construct WorkflowTokenAvailableConstraint with the configured wait timeout, mapping property key, required token key, and MetricsCollectionService.
    • Add containsProgramStatusTrigger(Trigger) to recursively detect ProgramStatusTrigger across AbstractSatisfiableCompositeTrigger (AndTrigger and OrTrigger) hierarchies.
    • Add getEffectiveConstraints(Job) and evaluate it in constraintsSatisfied so WorkflowTokenAvailableConstraint is appended at check time when the feature flag is enabled without persisting it onto schedules.
  • Add unit tests in ConstraintCheckerServiceTest.

Testing

  • Unit tests in ConstraintCheckerServiceTest.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +121 to +129
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));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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));
}

@deepika-lalwani123
deepika-lalwani123 force-pushed the pr5-workflow-token-constraint-wiring branch 2 times, most recently from b44b180 to ba00b11 Compare October 13, 2026 07:34
@deepika-lalwani123
deepika-lalwani123 force-pushed the pr4-workflow-token-constraint-metrics branch from 1c567d0 to 52d8d1d Compare October 13, 2026 07:34
@deepika-lalwani123
deepika-lalwani123 force-pushed the pr5-workflow-token-constraint-wiring branch from ba00b11 to ac55927 Compare October 15, 2026 08:09
@deepika-lalwani123
deepika-lalwani123 force-pushed the pr4-workflow-token-constraint-metrics branch from 52d8d1d to 2748590 Compare October 15, 2026 08:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant