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

[IA-4295] [IA-4327] Add Sam client to Leonardo, populate workspace ID #4757

Merged
merged 18 commits into from
Aug 28, 2024

Conversation

rtitle
Copy link
Collaborator

@rtitle rtitle commented Aug 20, 2024

https://broadworkbench.atlassian.net/browse/IA-4327
https://broadworkbench.atlassian.net/browse/IA-4295

Summary of changes

This PR does a few things:

  • Populates workspaceId going forward for v1 runtimes, disks, and apps
  • Adds the sam-client dependency to Leonardo
  • Adds SamApiClientProvider and SamService classes for interacting with Sam using the generated client. Deprecated [Http]SamDAO and [Leo|Sam]AuthProvider.
  • Ports functionality from PetClusterServiceAccountProvider over to SamService as a POC (read: logic for retrieving pets, proxy groups).

Note: access control logic is not touched as part of this PR -- that will be a separate pull request.

Testing these changes

What to test

  • Unit tests written for new functionality
  • Automation tests
  • BEE manual testing: create GCP and Azure runtimes/disks/apps of each type, verify workspaceId is always populated
  • Test in a BEE: create GCP and Azure runtimes/disks/apps of each type, verify workspaceId is always populated
  • Test in RWB: verify runtimes, disks, and apps have workspaceId populated
  • Verify logs and metrics for the above

Who tested and where

  • This change is covered by automated tests
    • NB: Rerun automation tests on this PR by commenting jenkins retest or jenkins multi-test.
  • I validated this change
  • Primary reviewer validated this change
  • I validated this change in the dev environment

@rtitle rtitle changed the title Populate parent workspace ID for v1 runtimes, disks, and apps Populate workspace ID for v1 runtimes, disks, and apps Aug 20, 2024
@rtitle rtitle changed the title Populate workspace ID for v1 runtimes, disks, and apps [IA-4327] Populate workspace ID for v1 runtimes, disks, and apps Aug 20, 2024
@@ -42,7 +42,8 @@ final case class ListPersistentDiskResponse(id: DiskId,
size: DiskSize,
diskType: DiskType,
blockSize: BlockSize,
labels: LabelMap
labels: LabelMap,
workspaceId: Option[WorkspaceId]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added optional workspaceId to the v1 getDisk and listDisks API responses.

(It was already there for runtimes and apps)

* @param ev trace id
* @return optional workspace ID
*/
override def lookupWorkspaceParentForGoogleProject(userInfo: UserInfo, googleProject: GoogleProject)(implicit
Copy link
Collaborator Author

@rtitle rtitle Aug 20, 2024

Choose a reason for hiding this comment

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

Here is where it looks up the workspaceId from Sam. This code is shared for runtimes, disks, and apps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha, so for GCP, Rawls creates the workspace and then calls Sam to create the corresponding resource? So we are more or less guaranteed that the Sam resource has been created by the time Leo makes this call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup that's correct, there should always be a workspace Sam resource for any Terra workspace in use today. Even so I tried to make this code handle errors and emit logs/metrics, just in case something goes wrong -- we don't want this code to cause runtime creation failures.

)
)
_ <- authProvider
.notifyResourceCreated(samResource, userInfo.userEmail, googleProject)
.handleErrorWith { t =>
log.error(t)(
s"[${ctx.traceId}] Failed to notify the AuthProvider for creation of persistent disk ${disk.projectNameString}"
) >> F.raiseError(t)
) >> F.raiseError[Unit](t)
Copy link
Collaborator Author

@rtitle rtitle Aug 20, 2024

Choose a reason for hiding this comment

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

I don't know if it's just me, but my Intellij flags this as a compile error -- adding the Unit type param fixed
it. (Made similar changes in a couple other places.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh interesting, my IntelliJ never yelled at me for that, but it can't hurt, thanks for fixing :)

lastUsedApp,
petSA,
nodepool.id,
req.workspaceId,
Copy link
Collaborator Author

@rtitle rtitle Aug 20, 2024

Choose a reason for hiding this comment

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

Note v1 apps actually have workspaceId as an optional field in the request json. However not all clients are sending it (seems like AoU "allowed" apps are populating it, but not Galaxy). Also Leo does not validate this field, so theoretically a caller could provide any workspace ID at app creation time. For those reasons I'm switching it to the workspace ID retrieved from Sam from the google project (which is validated).

Copy link

codecov bot commented Aug 20, 2024

Codecov Report

Attention: Patch coverage is 82.48175% with 24 lines in your changes missing coverage. Please review.

Project coverage is 74.22%. Comparing base (54c8a19) to head (f14f67a).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...kbench/leonardo/dao/sam/SamApiClientProvider.scala 0.00% 9 Missing ⚠️
...ch/leonardo/http/BaselineDependenciesBuilder.scala 0.00% 4 Missing ⚠️
...te/dsde/workbench/leonardo/util/BucketHelper.scala 55.55% 4 Missing ⚠️
.../workbench/leonardo/dao/sam/SamServiceInterp.scala 96.00% 2 Missing ⚠️
...h/leonardo/http/service/RuntimeServiceInterp.scala 86.66% 2 Missing ⚠️
...rkbench/leonardo/auth/CloudAuthTokenProvider.scala 0.00% 1 Missing ⚠️
...rkbench/leonardo/http/GcpDependenciesBuilder.scala 85.71% 1 Missing ⚠️
...ench/leonardo/http/service/DiskServiceInterp.scala 83.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4757      +/-   ##
===========================================
+ Coverage    74.17%   74.22%   +0.05%     
===========================================
  Files          161      164       +3     
  Lines        14941    14981      +40     
  Branches      1226     1243      +17     
===========================================
+ Hits         11082    11120      +38     
- Misses        3859     3861       +2     
Files with missing lines Coverage Δ
...sde/workbench/leonardo/http/diskRoutesModels.scala 0.00% <ø> (ø)
...ench/leonardo/auth/GcpCloudAuthTokenProvider.scala 0.00% <ø> (ø)
...dsde/workbench/leonardo/auth/SamAuthProvider.scala 58.77% <ø> (+0.44%) ⬆️
...titute/dsde/workbench/leonardo/config/Config.scala 97.76% <ø> (-0.03%) ⬇️
...itute/dsde/workbench/leonardo/dao/HttpSamDAO.scala 18.78% <ø> (ø)
...institute/dsde/workbench/leonardo/dao/SamDAO.scala 0.00% <ø> (ø)
...dsde/workbench/leonardo/dao/sam/SamException.scala 100.00% <100.00%> (ø)
...e/dsde/workbench/leonardo/dao/sam/SamService.scala 100.00% <100.00%> (ø)
...e/workbench/leonardo/db/DiskServiceDbQueries.scala 100.00% <ø> (ø)
...bench/leonardo/http/AzureDependenciesBuilder.scala 97.36% <100.00%> (ø)
... and 12 more

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54c8a19...f14f67a. Read the comment docs.

@rtitle rtitle requested a review from LizBaldo August 20, 2024 15:51
Copy link
Collaborator

@LizBaldo LizBaldo left a comment

Choose a reason for hiding this comment

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

LGTM, my main comment is around switching to the Sam client instead of the DAO if possible.

* @param ev trace id
* @return optional workspace ID
*/
override def lookupWorkspaceParentForGoogleProject(userInfo: UserInfo, googleProject: GoogleProject)(implicit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha, so for GCP, Rawls creates the workspace and then calls Sam to create the corresponding resource? So we are more or less guaranteed that the Sam resource has been created by the time Leo makes this call?

)
)
_ <- authProvider
.notifyResourceCreated(samResource, userInfo.userEmail, googleProject)
.handleErrorWith { t =>
log.error(t)(
s"[${ctx.traceId}] Failed to notify the AuthProvider for creation of persistent disk ${disk.projectNameString}"
) >> F.raiseError(t)
) >> F.raiseError[Unit](t)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh interesting, my IntelliJ never yelled at me for that, but it can't hurt, thanks for fixing :)

@jdcanas jdcanas self-requested a review August 22, 2024 15:41
@rtitle rtitle marked this pull request as ready for review August 23, 2024 19:10
@rtitle
Copy link
Collaborator Author

rtitle commented Aug 23, 2024

Updated the description -- added the generated Sam client to Leo and started using it for certain things (though not access control decisions yet). Unit tests are all passing, will do more manual testing as a next step.

@rtitle rtitle changed the title [IA-4327] Populate workspace ID for v1 runtimes, disks, and apps [IA-4327] Add Sam client to Leonardo, populate workspace ID Aug 27, 2024
project/Dependencies.scala Outdated Show resolved Hide resolved
@rtitle rtitle changed the title [IA-4327] Add Sam client to Leonardo, populate workspace ID [IA-4295] [IA-4327] Add Sam client to Leonardo, populate workspace ID Aug 27, 2024
@rtitle
Copy link
Collaborator Author

rtitle commented Aug 27, 2024

@LizBaldo no rush but I applied PR feedback, think it's ready for another look. Thanks!

Copy link
Collaborator

@LizBaldo LizBaldo left a comment

Choose a reason for hiding this comment

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

Looks great, so much cleaner. Thanks for addressing all of my comments!

*/
private def extractMessage(messagePrefix: String, apiException: ApiException): String = {
// The generated ApiException class unfortunately formats getMessage(), and includes
// the entire response body. We want to extract the actual message from that.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch 😨

@rtitle
Copy link
Collaborator Author

rtitle commented Aug 28, 2024

Did some more smoke testing on a BEE (different runtime/app operations, cloud environments screen, jupyter/rstudio/galaxy). It looks good. Will merge this and keep an eye on things

@rtitle rtitle merged commit 0f2a5a0 into develop Aug 28, 2024
23 of 24 checks passed
@rtitle rtitle deleted the rt-ia-4327 branch August 28, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants