-
Notifications
You must be signed in to change notification settings - Fork 39
[OCPERT-163] Send drop-bug MR notification to ART team on slack #698
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
base: master
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
LuboTerifaj
left a comment
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.
oar/cli/cmd_drop_bugs.py
Outdated
| nm.share_dropped_bugs(dropped_bugs) | ||
| # Notify ART using MR url directly from ShipmentData cache (no extra GitLab lookup) | ||
| try: | ||
| from oar.core.shipment import ShipmentData |
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.
I think it would be better to move the import to the imports section at the beginning of the file.
oar/core/shipment.py
Outdated
| # cache existing MR url for notification | ||
| try: | ||
| self._last_drop_bugs_mr_url = mr.get_web_url() | ||
| except Exception: |
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.
We should handle the exception and log the error, and not just ignore it.
oar/core/shipment.py
Outdated
| # cache new MR url for notification | ||
| try: | ||
| self._last_drop_bugs_mr_url = new_mr.get_web_url() | ||
| except Exception: |
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.
We should handle the exception and log the error, and not just ignore it.
oar/core/shipment.py
Outdated
| gh.configure_remotes("origin", f"https://group_143087_bot_e4ed5153eb7e7dfa7eb3d7901a95a6a7:{self._cs.get_gitlab_token()}@gitlab.cee.redhat.com/rioliu/ocp-shipment-data.git") | ||
| # cache existing MR url for notification | ||
| try: | ||
| self._last_drop_bugs_mr_url = mr.get_web_url() |
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.
Why are you setting the shipment merge request as a drop bugs mr?
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.
Good catch! I will make the suitable changes
oar/core/shipment.py
Outdated
| return self._mr | ||
|
|
||
| def get_last_drop_bugs_mr_url(self) -> str | None: | ||
| """Return the last drop-bugs MR URL detected/created during drop_bugs().""" |
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.
I would suggest to use the same docstring style as used in other methods in this file.
In addition, I think the current description may be a little bit confusing. I would change it to clarify what the "last" means, and what is the "drop_bugs()" to something like: Returns the URL of the latest drop-bugs Merge Request (MR) that was either detected or created during the drop_bugs() execution.
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.
Will correct it in the next commit
oar/core/notification.py
Outdated
| self._mh = MessageHelper(self.cs) | ||
| return self._mh | ||
|
|
||
| def _get_channel(self, contact_key: str) -> str: |
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.
docstring would be useful for this method.
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.
What is your motivation for caching? Did you stumble on any issues without it?
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.
Optimized performance by reducing repeated lookups on hot paths and keeping future costs bounded. The _get_channel method eventually invokes ConfigStore.get_slack_channel_from_contact(...), which, although lightweight today, is called multiple times across various notification methods within a single command. By introducing caching, each contact key is now resolved only once per NotificationManager instance, improving efficiency and reducing redundant lookups.
There is zero behavioral change for the existing notifications; just avoids repeated calls.
Happy to remove it if you want to keep the class minimal, or switch to “compute-once” fields for the 2–3 known keys we use.
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.
I don’t think caching is necessary here, since the values are already loaded into memory when calling
release-tests/oar/core/configstore.py
Line 43 in 4cd7f3a
| self._local_conf = json.loads(jwe.decrypt(f.read(), jwk)) |
If you would like to add caching, it should be implemented in the ConfigStore class to preserve proper encapsulation.
oar/core/notification.py
Outdated
| ch = self.cs.get_slack_channel_from_contact(contact_key) | ||
| self._channel_cache[contact_key] = ch | ||
| return ch |
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.
| ch = self.cs.get_slack_channel_from_contact(contact_key) | |
| self._channel_cache[contact_key] = ch | |
| return ch | |
| channel = self.cs.get_slack_channel_from_contact(contact_key) | |
| self._channel_cache[contact_key] = channel | |
| return channel |
oar/cli/cmd_drop_bugs.py
Outdated
| sd = ShipmentData(cs) | ||
| mr_url = sd.get_last_drop_bugs_mr_url() | ||
| if mr_url: | ||
| nm.share_drop_bugs_mr_for_approval(mr_url, dropped_count=len(dropped_bugs)) |
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.
dropped_count is never used
| nm.share_drop_bugs_mr_for_approval(mr_url, dropped_count=len(dropped_bugs)) | |
| nm.share_drop_bugs_mr_for_approval(mr_url, len(dropped_bugs)) |
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.
It is used in notification.py in the slack message.
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.
I meant that you can omit dropped_count and keep just len(dropped_bugs) as positional argument.
This is probably more about your preference and code style.
oar/core/notification.py
Outdated
| except Exception as e: | ||
| raise NotificationException("share shipment MR and AD info failed") from e | ||
|
|
||
| def share_drop_bugs_mr_for_approval(self, mr_url: str, dropped_count: int = 0): |
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.
Is there any reason why dropped_count is optional? Do we want to send two types of notifications?
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.
We’re not aiming for two different notifications; it’s the same message with an optional “(dropped N bugs)” suffix. It is just to enrich the message.
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.
If we always want to include information about the number of bugs being dropped, consider making this parameter non-optional.
tests/test_notification.py
Outdated
| def test_lazy_init_and_channel_cache(self): | ||
| """Validate Slack client lazy init and channel caching reduce repeated lookups""" | ||
| # Prepare NotificationManager with a fake MessageHelper to avoid external calls | ||
| class _FakeMH: |
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.
Please consider to use Mocks also here instead of substitute class.
516b65a to
bac158f
Compare
|
/hold Let's hold this PR, if find-bugs cli changes from ART works well, cmd |
@rioliu-rh Sure |
|
@jhuttana: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
At present ART is requested manually to take a look at drop-bugs MR. This PR aims to automate the same.