-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Update pants-plugins/uses_services
to support checking for rabbitmq
#5884
Merged
Conversation
This file contains 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
amanda11
reviewed
Feb 3, 2023
cognifloyd
commented
Feb 6, 2023
Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>
amanda11
approved these changes
Feb 7, 2023
rush-skills
approved these changes
Feb 7, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This was referenced Feb 7, 2023
This was referenced Nov 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
infrastructure: ci/cd
pantsbuild
rabbitmq
size/L
PR that changes 100-499 lines. Requires some effort to review.
tests
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.
Background
This is another part of introducing pants, as discussed in various TSC meetings.
Related PRs can be found in:
Overview of this PR
This PR builds on #5864 to further improve the DX (developer experience) by failing as early as possible if the development (or CI) environment does not have the required services.
This PR adds checks for
rabbitmq
, like #5864 addedmongo
checks. I also have draft branch to addredis
checks.Please see #5864 for a more detailed description of
pants-plugins/uses_services
.is_rabbitmq_running.py
script and the rule that runs itis_rabbitmq_running.py
is the part that checks to see if rabbitmq is running.The pants plugin cannot import anything from our other
st2*
code, sois_rabbitmq_running.py
is a minimal self-contained script that mirrors how st2 connects to rabbitmq. It should be as minimal as possible so that keeping it up-to-date with the core st2 code is not onerous.The
is_rabbitmq_running.py
rule gets opened and run in a pex with the same rule logic asis_mongo_running.py
andinspect_platform.py
(see #5864).Rabbitmq embeds all auth stuff in the connection url. So, there are not as many settings to worry about as there were with mongo. For now, this only supports the url hard-coded in the tests. Here is where the rule defines the default url:
st2/pants-plugins/uses_services/rabbitmq_rules.py
Lines 47 to 65 in adb9c4b
Here is the definition of the rule that runs
is_rabbitmq_running.py
:st2/pants-plugins/uses_services/rabbitmq_rules.py
Lines 99 to 101 in adb9c4b
So, when another rule Gets
RabbitMQIsRunning
with aUsesRabbitMQRequest
, pants will also run the rule that generatesPlatform
(described in #5864), and then it will run thisis_rabbitmq_running
rule.The
is_rabbbitmq_running
rule either returnsRabbitMQIsRunning()
if it is running, or raisesServiceMissingError
if it is not. By raising an error, this actually breaks a convention for pants rules. Exceptions stop everything and get shown to the user right away, and for most goals, pants wants to see some dataclass returned that has something like asucceeded
boolean instead. But, we want to error as early as possible, so this breaks that convention on purpose.wiring up the
test
goal so it runsis_rabbitmq_running
whenpytest
runs on a target with theuses
field.The last piece that ties this all together is a rule that makes sure the
is_rabbitmq_running
rule runs beforepytest
runs (if pants is running it on a target with theuses
field). Here is the definition of therabbitmq_is_running_for_pytest
rule:st2/pants-plugins/uses_services/rabbitmq_rules.py
Lines 86 to 88 in adb9c4b
This rule is very simple. It just triggers running the
is_rabbitmq_running
rule:st2/pants-plugins/uses_services/rabbitmq_rules.py
Lines 89 to 92 in adb9c4b
This rule needs the
PytestUsesRabbitMQRequest
which selects targets that have theuses
field.st2/pants-plugins/uses_services/rabbitmq_rules.py
Lines 73 to 79 in adb9c4b
This request will be made by the pants-internal pytest rules thanks to this
UnionRule
, which is a way to declare that our class "implements" thePytestPluginSetupRequest
:st2/pants-plugins/uses_services/rabbitmq_rules.py
Line 176 in adb9c4b
If we need to add
uses
support to other targets, we will need to find similar UnionRules where we can inject our rule logic. For now, I've only wired this up so ouruses
rules will run for pytest.