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

[prism] Support AnyOf in Prism. #33705

Merged
merged 3 commits into from
Jan 22, 2025
Merged

[prism] Support AnyOf in Prism. #33705

merged 3 commits into from
Jan 22, 2025

Conversation

lostluck
Copy link
Contributor

  • Adds basic AnyOf support enables handling for environment selection.
  • Prefers External/Loopback, then Process, then docker, then any others.
  • Could be improved later via a configuration that changes the ranking, or by going with a "fallback" approach in the case of AnyOf environments. (eg. Sorts as presently, tries to make the external worker, if that fails, move to the next version, checks if it can start the process environment, etc._

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@lostluck
Copy link
Contributor Author

R: @robertwb @damondouglas

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

rankA := ranks[a.GetUrn()]
rankB := ranks[b.GetUrn()]

// Reverse the comparison so our favourite is at the front
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively we could give the ranks golf-style scoring, or pick the last one in the list below. If this is the most idiomatic I'm fine with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reversal was partly to have an easier selection for the most choice environment: just the one at 0.

I did consider the golf weighting but I'm also making use of the default zero value for anything in the map. So i biased for the higher weight being priority, vs risk a weird priority inversion if someone puts in negative numbers.

I could avoid the negatives with a uint instead...

As for the idiomatic question: it would be less idiomatic to return the "normal" compare number, then reverse the list. Neither really save lines of code (vs documentation). There is the argument that then the code is self documenting, but we don't really care about the order, just that we picked the "favourite".

Finally, we can always change it later.

@@ -46,16 +47,26 @@ import (

func runEnvironment(ctx context.Context, j *jobservices.Job, env string, wk *worker.W) error {
logger := j.Logger.With(slog.String("envID", wk.Env))
// TODO fix broken abstraction.
// We're starting a worker pool here, because that's the loopback environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this TODO just obsolete? (I'm not seeing a pool started below, changed or not.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's mostly referring to the "one environment, one worker" notion. The "pool" for example could be several "w orkers" all in the same environment.

If we ever decide to make prism distributed and scalable, then this code would need to change anyway, so the TODO is moot.

@@ -83,6 +96,33 @@ func runEnvironment(ctx context.Context, j *jobservices.Job, env string, wk *wor
}
}

func selectAnyOfEnv(ap *pipepb.AnyOfEnvironmentPayload) *pipepb.Environment {
// Prefer external, then process, then docker, unknown environments are 0.
ranks := map[string]int{
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't handle nested AnyOf. Do we care?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe we do. We could, but I think we shouldn't.

I'd say it's to Beam's benefit to not encourage that sort of thing.

@lostluck lostluck changed the title Any env prism [prism] Support AnyOf in Prism. Jan 21, 2025
@lostluck
Copy link
Contributor Author

Thanks for the review!

@lostluck lostluck merged commit 8c4bec8 into apache:master Jan 22, 2025
11 checks passed
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.

2 participants