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

Add publisher to ActionAlias #5763

Merged
merged 10 commits into from
Feb 7, 2023

Conversation

ubaumann
Copy link
Contributor

@ubaumann ubaumann commented Oct 6, 2022

Add publisher to ActionAlias to get events for CUD Action Aliases.
This change enables DroidStorm (and other systems) to subscribe the events and get informed when a new Alias is created, updated or deleted.

Manual tested:

  • Start st2 (./tools/launchdev.sh startclean)
  • Start queue_consumer
  • Create and delete action-alias

Created and deleted action-alias

(virtualenv) ins@ubuntu:~/st2$ st2 action-alias create contrib/hello_st2/aliases/alias1.yaml
+----------------------+------------------------------+
| Property             | Value                        |
+----------------------+------------------------------+
| id                   | 633f3ceb2735066974631da4     |
| name                 | greet                        |
| pack                 | hello_st2                    |
| description          | Greet StackStorm             |
| ack                  |                              |
| action_ref           | hello_st2.greet              |
| enabled              | True                         |
| extra                |                              |
| formats              | [                            |
|                      |     "greet {{greeting}}"     |
|                      | ]                            |
| immutable_parameters |                              |
| metadata_file        |                              |
| ref                  | hello_st2.greet              |
| result               |                              |
| uid                  | action_alias:hello_st2:greet |
+----------------------+------------------------------+
(virtualenv) ins@ubuntu:~/st2$ st2 action-alias delete greet
Resource with id "greet" has been successfully deleted.

Queu consumer

(virtualenv) ins@ubuntu:~/st2$ ST2_CONFIG_PATH=conf/st2.dev.conf python tools/queue_consumer.py --exchange st2.actionalias
===================================================
Received message
message.properties:
{'application_headers': {},
 'content_encoding': 'binary',
 'content_type': 'application/x-python-serialize',
 'delivery_mode': 2,
 'priority': 0}
message.delivery_info:
{'consumer_tag': 'None1',
 'delivery_tag': 1,
 'exchange': 'st2.actionalias',
 'redelivered': False,
 'routing_key': 'create'}
body:
<ActionAliasDB: ActionAliasDB(ack={}, action_ref="hello_st2.greet", description="Greet StackStorm", enabled=True, extra={}, formats=['greet {{greeting}}'], id=633f3ceb2735066974631da4, immutable_parameters={}, metadata_file="", name="greet", pack="hello_st2", ref="hello_st2.greet", result={}, uid="action_alias:hello_st2:greet")>
===================================================
===================================================
Received message
message.properties:
{'application_headers': {},
 'content_encoding': 'binary',
 'content_type': 'application/x-python-serialize',
 'delivery_mode': 2,
 'priority': 0}
message.delivery_info:
{'consumer_tag': 'None1',
 'delivery_tag': 2,
 'exchange': 'st2.actionalias',
 'redelivered': False,
 'routing_key': 'delete'}
body:
<ActionAliasDB: ActionAliasDB(ack={}, action_ref="hello_st2.greet", description="Greet StackStorm", enabled=True, extra={}, formats=['greet {{greeting}}'], id=633f3ceb2735066974631da4, immutable_parameters={}, metadata_file="", name="greet", pack="hello_st2", ref="hello_st2.greet", result={}, uid="action_alias:hello_st2:greet")>
===================================================

Unitest are covering already testing the generic functions. There are no test testing the object specific events. Should I add some test?

Looking forward to the review and please let me know how I can improve the PR.

Pinging @cognifloyd because we talked already in Slack about the PR.

@pull-request-size pull-request-size bot added the size/M PR that changes 30-99 lines. Good size to review. label Oct 6, 2022
@CLAassistant
Copy link

CLAassistant commented Oct 6, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

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

Awesome! I just found one more file we need to edit to make these events available in the event stream.

Would you please add the ActionAlias queue to this list:

return [
consumer(
queues=[STREAM_ANNOUNCEMENT_WORK_QUEUE],
accept=["pickle"],
callbacks=[self.processor()],
),
consumer(
queues=[STREAM_EXECUTION_ALL_WORK_QUEUE],
accept=["pickle"],
callbacks=[self.processor(ActionExecutionAPI)],
),
consumer(
queues=[STREAM_LIVEACTION_WORK_QUEUE],
accept=["pickle"],
callbacks=[self.processor(LiveActionAPI)],
),
consumer(
queues=[STREAM_EXECUTION_OUTPUT_QUEUE],
accept=["pickle"],
callbacks=[self.processor(ActionExecutionOutputAPI)],
),
]

Also, just a couple nitpicks.

Thank you so much for working on this!

We might have to wait a bit before merging this as I'm not sure if it can go in the 3.8 release.

st2common/st2common/transport/actionalias.py Outdated Show resolved Hide resolved
CHANGELOG.rst Outdated Show resolved Hide resolved
@ubaumann
Copy link
Contributor Author

Awesome! I just found one more file we need to edit to make these events available in the event stream.

Would you please add the ActionAlias queue to this list:

return [
consumer(
queues=[STREAM_ANNOUNCEMENT_WORK_QUEUE],
accept=["pickle"],
callbacks=[self.processor()],
),
consumer(
queues=[STREAM_EXECUTION_ALL_WORK_QUEUE],
accept=["pickle"],
callbacks=[self.processor(ActionExecutionAPI)],
),
consumer(
queues=[STREAM_LIVEACTION_WORK_QUEUE],
accept=["pickle"],
callbacks=[self.processor(LiveActionAPI)],
),
consumer(
queues=[STREAM_EXECUTION_OUTPUT_QUEUE],
accept=["pickle"],
callbacks=[self.processor(ActionExecutionOutputAPI)],
),
]

Thank you very much for finding this place. I totally missed it.

Also, just a couple nitpicks.

Thank you for reviewing the PR

We might have to wait a bit before merging this as I'm not sure if it can go in the 3.8 release.

That's totally fine. I was lately a little busy but it was really nice to work on ST2 and I am planning to keep sticking around. So just let me know if I should rebase the branch or anything else.

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

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

Woohoo! Awesome. Thanks for working on this.

This needs 1 more approval, and @nzlosh needs to decide if it can land in 3.8 or if it needs to wait till after we finish cutting that release.

@cognifloyd cognifloyd requested review from nzlosh, m4dcoder and a team October 14, 2022 22:58
@cognifloyd cognifloyd changed the title Add publischer to ActionAlias Add publisher to ActionAlias Oct 14, 2022
@cognifloyd cognifloyd requested a review from winem November 3, 2022 05:08
@cognifloyd cognifloyd added this to the 3.9.0 milestone Nov 3, 2022
Copy link
Contributor

@amanda11 amanda11 left a comment

Choose a reason for hiding this comment

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

Minor comment on changelog, and I'm wondering if its possible to add some unit-tests for the changes.

CHANGELOG.rst Outdated Show resolved Hide resolved
@cognifloyd
Copy link
Member

cognifloyd commented Dec 4, 2022

I just went through a bunch of tests to see which tests deal somehow with publishing messages on the queue. In most cases, it is mocking or ignoring the message queue publishing.

Based on that, I think we could add some tests in st2common/tests/unit/test_transport.py. The new test(s) can use the QueueConsumer class similar to how TransportUtilsTestCase.test_publish_compression() does it to test that messages get published to the right queue. Instead of using the dummy Exchange+Queue+PoolPublisher, we would use:

  • st2common.transport.actionalias.ACTIONALIAS_XCHG
  • st2common.transport.actionalias.get_queue()
    I think all we need to use this safely (safe for parallel tests that touch RabbitMQ)
    is a test-specific queue_name, and then:
    get_queue(name=queue_name, routing_key="#", exclusive=True, auto_delete=True)
  • st2common.transport.actionalias.ActionAliasPublisher().

I don't see how we can test this without effectively testing kombu+RabbitMQ, since much of the added code added in this PR deals with wiring up the exchange+queue, setting it up for publishing.

We could also add a db test similar to the test_db_*.py files that mocks ActionAliasPublisher and makes sure that publish() gets called when we create/update/delete (but not read) with ActionAliasDB.

@amanda11 Does that sound like what you'd like to see? Would tests like this have value?


Here are my raw notes:

mock publishers in:

@rush-skills
Copy link
Member

@cognifloyd @ubaumann Is this still WIP?

@cognifloyd
Copy link
Member

I would love to see this merged. I'm satisfied with this without the tests. But, @amanda11 mentioned adding tests, so I tried to figure out what tests we could add. @rush-skills wdyt? Does this need tests?

Copy link
Contributor

@amanda11 amanda11 left a comment

Choose a reason for hiding this comment

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

I'm happy to merge as is, without the extra tests. I'd rather it be in, than wait months for tests...

@cognifloyd cognifloyd merged commit 70a8637 into StackStorm:master Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action aliases chatops feature hacktoberfest-accepted size/M PR that changes 30-99 lines. Good size to review.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants