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 first pact verification for WDS integration. #1511

Merged
merged 6 commits into from
Nov 7, 2023

Conversation

jladieu
Copy link
Contributor

@jladieu jladieu commented Oct 25, 2023

This pairs with DataBiosphere/terra-workspace-data-service#372 to establish a contract between WDS and WSM, initially focused on ReferencedGcpResourceController.

I tested this running a local pact-broker by following the steps in this doc and using the displayed IntelliJ run configuration:
image

@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch from 85c0a99 to 4ad26d4 Compare October 25, 2023 19:51
@jladieu jladieu requested a review from a team October 30, 2023 14:39
@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch 3 times, most recently from ef3a1fb to 23c1d25 Compare October 30, 2023 23:23
@@ -35,6 +34,8 @@
@Tag("pact-test")
@ExtendWith(PactConsumerTestExt.class)
public class TpsApiTest {
private static final String UUID_REGEX =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As part of upgrading the pactjvm dep, we lost access to the UUID_REGEX which was buried in an inaccessible kotlin companion object. This is just an inline of the String previously referenced.

@@ -322,6 +322,8 @@ landingzone:
- [email protected]
- [email protected]
- [email protected]
pactbroker:
Copy link
Contributor Author

@jladieu jladieu Oct 30, 2023

Choose a reason for hiding this comment

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

This doesn't actually work to provide a local override -- the pactbroker.url defined in application-test.yml ends up taking precedence, which is why to actually run locally I provided a screenshot of the runconfig needed to set the value via environment variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

if this doesn't work, then can you delete it? If it needs to be present for some reason, add a code comment explaining it doesn't have any effect.

Comment on lines 222 to 224
// TODO: do the correct/idiomatic thing here with config values, help needed for WSM specifics, desired behavior:
// default: use the dsp-eng-tools version
// allow optional local-override for local pactbroker
Copy link
Contributor

@nawatts nawatts Oct 31, 2023

Choose a reason for hiding this comment

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

@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch from 23c1d25 to 4871397 Compare October 31, 2023 13:57
@jladieu jladieu changed the title Add WdsContractVerificationTest Add first pact verification for WDS integration. Oct 31, 2023
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is copied from DataBiosphere/jade-data-repo#1528, I'll annotate the lines which are WSM-specific.

@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch from 4871397 to 742f618 Compare October 31, 2023 14:01
@@ -0,0 +1,203 @@
name: Verify consumer pacts
# The purpose of this workflow is to verify ANY consumer contract(s) dependent on workspacemanager provider using Pact
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment adjusted to include workspacemanager pacticipant name, which must match the helmchart name.

# - PACT_BROKER_USERNAME - the Pact Broker username
# - PACT_BROKER_PASSWORD - the Pact Broker password
# They are managed by Atlantis and were added to Terraform here:
# https://github.com/broadinstitute/terraform-ap-deployments/pull/1086
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included link to PR where wsm's creds were introduced.

# https://github.com/broadinstitute/terraform-ap-deployments/pull/1086
env:
PACT_BROKER_URL: pact-broker.dsp-eng-tools.broadinstitute.org
spring_profiles_active: human-readable-logging
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added spring_profiles_active to get human friendly logs, which are important to interpreting pact verification failures.

@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch 2 times, most recently from 958eba3 to d1dbe5d Compare October 31, 2023 14:04
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ secrets.BROADBOT_TOKEN }} # github token for access to kick off a job in the private repo
inputs: '{ "pacticipant": "workspacemanager", "version": "${{ needs.verify-consumer-pact.outputs.provider-sha }}" }'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted pacticipant name to workspacemanager

Copy link

sonarcloud bot commented Oct 31, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch 2 times, most recently from 2975f37 to b3e06b4 Compare October 31, 2023 18:24
@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch 2 times, most recently from d1dbe5d to 6fa0e93 Compare November 1, 2023 15:36
@jladieu jladieu changed the base branch from main to rename-wsm-pacticipants November 1, 2023 15:38
@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch 3 times, most recently from a4d3630 to 83e7061 Compare November 1, 2023 21:15
@jladieu jladieu force-pushed the rename-wsm-pacticipants branch 2 times, most recently from 0fea0b2 to 0e115d9 Compare November 2, 2023 21:14
Base automatically changed from rename-wsm-pacticipants to main November 2, 2023 22:02
This pairs with
DataBiosphere/terra-workspace-data-service#372
to establish a contract between WDS and WSM, initially focused on
`ReferencedGcpResourceController`.
REVERT: Attempt to upload results of pact

Debug level logging to troubleshoot pact
@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch from e417090 to c743aba Compare November 3, 2023 12:39
jladieu added a commit to DataBiosphere/terra-billing-profile-manager that referenced this pull request Nov 3, 2023
Prefer helmchart name as the pacticipant identifier:
* `bpm-provider` -> `bpm`
* `bpm-consumer` -> `bpm`
* `sam-provider` -> `sam`
* See [thread](https://broadinstitute.slack.com/archives/C043YJ40719/p1698068076950019) discussing the `-consumer` and `-provider` suffix anti-pattern.
* See [thread](https://broadinstitute.slack.com/archives/C043YJ40719/p1698241095600099) discussing the recommendation to use the helm chart name.

Unblocks:
* broadinstitute/rawls#2610
* DataBiosphere/terra-workspace-manager#1511
* broadinstitute/sam#1234
@jladieu
Copy link
Contributor Author

jladieu commented Nov 3, 2023

Discussed offline with @blakery, a couple things to incorporate into this PR for next round:

  • Don't need to worry about the cautionary advice about @MockBeans in the README.md for this test, which is its own test runtime and doesn't need to be subject to those considerations. 🎉
  • Try to mock one layer lower (DAO level instead of service level) -- this will allow the @State to better track stateful behavior, and hopefully prevent future collision/disagreement between stateful setups that will happen when mocking at the service level (as currently implemented.

@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch 2 times, most recently from 03effa5 to 49705f6 Compare November 6, 2023 15:49
This will allow the `@State` to better track stateful behavior, and
hopefully prevent future collision/disagreement between stateful setups
that might happen when mocking at the service level.
@jladieu jladieu force-pushed the AJ-1235-provider-pacts-for-wds branch from 49705f6 to 00b1917 Compare November 6, 2023 16:49
@jladieu jladieu requested a review from blakery November 6, 2023 16:50
@Tag("pact-verification")
@Provider("workspacemanager") // should match the terra chart name
@PactBroker()
public class WdsContractVerificationTest extends BaseUnitTestMocks {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really surprised by how well pushing the mocks lower worked!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed...I was pleasantly surprised that extending from BaseUnitTestMocks seemed to strike the right balance of dependencies that I didn't have to @MockBean out everything into oblivion.

@jladieu jladieu requested a review from a team November 7, 2023 18:40
Copy link
Contributor

@davidangb davidangb left a comment

Choose a reason for hiding this comment

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

A few comments inline, nothing big. Thanks for doing this!

I did not test any of this myself, but I see the checks passing.

.github/workflows/verify_consumer_pacts.yaml Outdated Show resolved Hide resolved
.github/workflows/verify_consumer_pacts.yaml Outdated Show resolved Hide resolved
.github/workflows/verify_consumer_pacts.yaml Outdated Show resolved Hide resolved
@@ -322,6 +322,8 @@ landingzone:
- [email protected]
- [email protected]
- [email protected]
pactbroker:
Copy link
Contributor

Choose a reason for hiding this comment

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

if this doesn't work, then can you delete it? If it needs to be present for some reason, add a code comment explaining it doesn't have any effect.

# This workflow is triggered when
#
# 1. Consumer makes a change that results in a new pact published to Pact Broker (will verify ONLY the changed pact and publish the verification results back to the broker)
# 2. Provider makes a change (runs verification tests against ALL DEPLOYED consumer pact versions and publishes corresponding verification results)
Copy link
Contributor

Choose a reason for hiding this comment

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

ALL DEPLOYED consumer pact versions

doesn't this require some configuration/integration with beehive or sherlock? Is this already set up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I'm not sure...this file is the result of a blatant copypaste. I did check in https://beehive.dsp-devops.broadinstitute.org/charts/workspacemanager/contract-testing and confirmed that for workspacemanager contract testing is enabled:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll get to exercise some of the provider side again after this merges by integrating another couple pact verifications...hopefully I'll have more of a clue after that process.

Copy link

sonarcloud bot commented Nov 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jladieu jladieu merged commit 1a29c32 into main Nov 7, 2023
14 checks passed
@jladieu jladieu deleted the AJ-1235-provider-pacts-for-wds branch November 7, 2023 21:45
jladieu added a commit that referenced this pull request Nov 17, 2023
This is followup after:
#1511

That PR (and associated changes) introduced the first WDS <-> WSM pact
verification to WSM, but inadvertently broke the `verify_consumer_pacts`
GitHub action in the process.  This PR fixes that, while also adopting
semantic versioning for reporting verification to Pact Broker.

Various relevant threads:
* https://broadinstitute.slack.com/archives/C043YJ40719/p1699888771297559
* https://broadinstitute.slack.com/archives/C043YJ40719/p1700155493619189
* https://broadinstitute.slack.com/archives/C043YJ40719/p1700154543175189

GitHub Actions logic copied from:
DataBiosphere/terra-billing-profile-manager#324
jladieu added a commit that referenced this pull request Nov 17, 2023
This is followup after:
#1511

That PR (and associated changes) introduced the first WDS <-> WSM pact
verification to WSM, but inadvertently broke the `verify_consumer_pacts`
GitHub action in the process.  This PR fixes that, while also adopting
semantic versioning for reporting verification to Pact Broker.

Various relevant threads:
* https://broadinstitute.slack.com/archives/C043YJ40719/p1699888771297559
* https://broadinstitute.slack.com/archives/C043YJ40719/p1700155493619189
* https://broadinstitute.slack.com/archives/C043YJ40719/p1700154543175189

GitHub Actions logic copied from:
DataBiosphere/terra-billing-profile-manager#324
jladieu added a commit that referenced this pull request Dec 1, 2023
* Fix `verify_consumer_pacts` GitHub action.

This is followup after:
#1511

That PR (and associated changes) introduced the first WDS <-> WSM pact
verification to WSM, but inadvertently broke the `verify_consumer_pacts`
GitHub action in the process.  This PR fixes that, while also adopting
semantic versioning for reporting verification to Pact Broker.

Various relevant threads:
* https://broadinstitute.slack.com/archives/C043YJ40719/p1699888771297559
* https://broadinstitute.slack.com/archives/C043YJ40719/p1700155493619189
* https://broadinstitute.slack.com/archives/C043YJ40719/p1700154543175189

GitHub Actions logic copied from:
DataBiosphere/terra-billing-profile-manager#324

Also enable pending pacts.  See:
https://docs.pact.io/pact_broker/advanced_topics/pending_pacts
---------

Co-authored-by: Ivan <[email protected]>
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.

5 participants