Skip to content

Conversation

@jhuttana
Copy link
Contributor

@jhuttana jhuttana commented Oct 3, 2025

At present ART is requested manually to take a look at drop-bugs MR. This PR aims to automate the same.

@jhuttana jhuttana requested a review from rioliu-rh October 3, 2025 05:46
@openshift-ci openshift-ci bot requested a review from LuboTerifaj October 3, 2025 05:46
@openshift-ci
Copy link

openshift-ci bot commented Oct 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign tomasdavidorg for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jhuttana jhuttana requested a review from tomasdavidorg October 3, 2025 05:46
Copy link
Contributor

@LuboTerifaj LuboTerifaj left a comment

Choose a reason for hiding this comment

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

Hello @jhuttana ,

please have a look at my comments.

Thanks!

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
Copy link
Contributor

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.

# cache existing MR url for notification
try:
self._last_drop_bugs_mr_url = mr.get_web_url()
except Exception:
Copy link
Contributor

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.

# cache new MR url for notification
try:
self._last_drop_bugs_mr_url = new_mr.get_web_url()
except Exception:
Copy link
Contributor

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.

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()
Copy link
Contributor

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?

Copy link
Contributor Author

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

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()."""
Copy link
Contributor

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.

Copy link
Contributor Author

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

self._mh = MessageHelper(self.cs)
return self._mh

def _get_channel(self, contact_key: str) -> str:
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

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.

Comment on lines 55 to 57
ch = self.cs.get_slack_channel_from_contact(contact_key)
self._channel_cache[contact_key] = ch
return ch
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

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))
Copy link
Contributor

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

Suggested change
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))

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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:
Copy link
Contributor

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.

@jhuttana jhuttana force-pushed the drop-bugs-mr-notify branch from 516b65a to bac158f Compare October 14, 2025 06:48
@rioliu-rh
Copy link
Contributor

/hold

Let's hold this PR, if find-bugs cli changes from ART works well, cmd drop-bugs will be eliminated.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 14, 2025
@jhuttana
Copy link
Contributor Author

/hold

Let's hold this PR, if find-bugs cli changes from ART works well, cmd drop-bugs will be eliminated.

@rioliu-rh Sure

@openshift-ci
Copy link

openshift-ci bot commented Oct 14, 2025

@jhuttana: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants