Skip to content
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

Handle empty values for task and datasource conditions in pod template selector #17400

Conversation

kirangadhave-imply
Copy link
Contributor

@kirangadhave-imply kirangadhave-imply commented Oct 22, 2024

Description

The condition based selector that evaluates tasks based on specified criteria failed to handle empty values for task type or datasource. If the condition is empty or null it can be matched to any task, but previous logic checked for task type or task datasource in the empty set resulting in skipping of that selector. Expected behavior is to treat empty sets the same as null.
Fixed the evaluate method in Selector to check if the task type or datasource conditions are null or empty instead of just a null check.

Release note

Fixed: You can now pass empty arrays to type and dataSource keys in selector based pod template selection strategy


This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.

@kirangadhave-imply kirangadhave-imply marked this pull request as ready for review October 22, 2024 22:14
Copy link
Contributor

@suneet-s suneet-s left a comment

Choose a reason for hiding this comment

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

Thanks for your first patch @kirangadhave-imply ! In addition to a few more tests, can you please update the docs https://github.com/apache/druid/blob/master/docs/development/extensions-contrib/k8s-jobs.md#select-based-on-one-or-more-conditions to indicate what null is expected to mean aka match anything.

I agree with your comment in the description of this issue that if a user passes in null as a selector to either the task type or datasource - they most likely meant to match any task type or any datasource, since it is not possible to have a task without a type or a datasource. Let's make this explicit in the docs.

"TestSelector",
cxtTagsConditions,
Sets.newHashSet(NoopTask.TYPE),
new HashSet<>()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add another test for passing in null for the datasource selector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

existing tests already cover null value

Selector selector = new Selector(
"TestSelector",
cxtTagsConditions,
new HashSet<>(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add another test for passing in null for the task type selector


Selector selector = new Selector(
"TestSelector",
cxtTagsConditions,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add another test for passing in null for the tags condition

@kirangadhave-imply
Copy link
Contributor Author

@suneet-s The evaluate method has 100% test coverage. Passing null was already being tested by the existing tests. So we should be good to go from the testing perspective

Copy link
Contributor

@suneet-s suneet-s left a comment

Choose a reason for hiding this comment

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

Thanks for this fix @kirangadhave-imply ! And congrats on your first contribution to the repo!

I will take care of merging this once CI passes. Can you please do a follow up patch to update the docs to explicitly call out the differences between an empty set being used for datasources or task type and an empty set being used in the tag selector.

The only reason I'm suggesting doing the docs change in a follow up patch is to reduce the CI time, since a docs only change goes through much fewer tests.

@suneet-s suneet-s merged commit 5fcf420 into apache:master Oct 31, 2024
56 checks passed
@kirangadhave-imply kirangadhave-imply deleted the fix-pod-template-selector-empty-conditions branch November 4, 2024 19:28
jtuglu-netflix pushed a commit to jtuglu-netflix/druid that referenced this pull request Nov 20, 2024
…e selector (apache#17400)

* handling empty sets for dataSourceCondition and taskTypeCondition

* using new HashSet<>() to fix forbidden api error in testCheck

* fixing style issues
@adarshsanjeev adarshsanjeev added this to the 32.0.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants