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

Reduce logs in webapp container (depends on blackduck-common release, do not merge) #1390

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zahidblackduck
Copy link
Collaborator

JIRA Ticket
IDETECT-4209

Description
This update aims to reduce excessive logs in hub webapp container when a non-sysadmin user tries to access registration key calling the endpoint /api/registration during detect startup and phone-homing.

Detect can determine the current user’s roles during startup by communicating with blackduck-common. By checking if the user has sysadmin privileges, we can pass this status to BlackDuckRegistrationService#getBlackDuckServerData(isAdmin), reducing unnecessary calls.

Solution Approach

  • Overload getBlackDuckServerData() to accept an isAdmin flag and pass it from determineConnectivity().
  • Skip getRegistrationId() if isAdmin is false to avoid redundant requests.
  • Optimizes performance by storing the user’s admin status upfront.

This fix depends on the release of blackduck-common library containing the following code updates.
blackducksoftware/blackduck-common#453

@zahidblackduck zahidblackduck marked this pull request as draft March 17, 2025 20:18
@zahidblackduck zahidblackduck self-assigned this Mar 17, 2025
@zahidblackduck zahidblackduck changed the title Resolve issue with detect causing excessive warning logs in webapp container (depends on blackduck-common release, do not merge) Fix excessive warning logs in webapp container (depends on blackduck-common release) Mar 17, 2025
@zahidblackduck zahidblackduck changed the title Fix excessive warning logs in webapp container (depends on blackduck-common release) Resolve excessive warning logs in webapp container (depends on blackduck-common release) Mar 17, 2025
@zahidblackduck zahidblackduck changed the title Resolve excessive warning logs in webapp container (depends on blackduck-common release) Reduce excessive logs in webapp container (depends on blackduck-common release, do not merge) Mar 17, 2025
@zahidblackduck zahidblackduck changed the title Reduce excessive logs in webapp container (depends on blackduck-common release, do not merge) Reduce logs in webapp container (depends on blackduck-common release, do not merge) Mar 17, 2025
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService();
List<RoleAssignmentView> roles = userGroupService.getServerRolesForUser(userView);
boolean isAdmin = checkIsAdmin(roles);
version = blackDuckRegistrationService.getBlackDuckServerData(isAdmin).getVersion();
Copy link
Contributor

@andrian-sevastyanov andrian-sevastyanov Mar 18, 2025

Choose a reason for hiding this comment

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

As discussed on a call, the greater intention of passing in isAdmin here is not clear.
To someone working with this code in the future it may look like the only thing this code cares about here is the version.
That could lead a developer down a path of refactoring, not realizing the importance of the side effect, and all of a sudden we will start making extra calls in other places again.

I think Ideally we would:

  1. Determine user roles once
  2. Fetch BlackDuckServerData based on it once
  3. Pass around this data to wherever its needed, including phone home

This is more work but I believe is more reliable and would minimize the number of API calls needed,.

version = blackDuckRegistrationService.getBlackDuckServerData().getVersion();
UserView userView = userService.findCurrentUser();
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService();
List<RoleAssignmentView> roles = userGroupService.getServerRolesForUser(userView);
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing to be careful about here is pagination.
I'm not sure what the maximum number of roles is, but it may be greater than the default page size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants