Skip to content

feat(backend): also publish webhooks to operators if primary recipient is tenant #3368

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

Merged
merged 26 commits into from
May 1, 2025

Conversation

njlie
Copy link
Contributor

@njlie njlie commented Apr 2, 2025

Changes proposed in this pull request

  • Publishes a second webhook to the operator's webhook URL if primary recipient is a tenant of the Rafiki instance.

Context

Fixes #3283.

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. type: source Changes business logic labels Apr 2, 2025
@njlie njlie force-pushed the nl/3121/tenanted-webhooks branch from 7cfa385 to 14fe53f Compare April 2, 2025 22:28
@njlie njlie force-pushed the nl/3283/operator-webhooks branch 2 times, most recently from a5ce199 to 98b1291 Compare April 8, 2025 17:59
@njlie njlie force-pushed the nl/3121/tenanted-webhooks branch from 4260036 to 5c51d6d Compare April 8, 2025 18:45
@njlie njlie force-pushed the nl/3283/operator-webhooks branch from 98b1291 to 64973e7 Compare April 8, 2025 20:20
Base automatically changed from nl/3121/tenanted-webhooks to 2893/multi-tenancy-v1 April 15, 2025 23:13
@github-actions github-actions bot added pkg: frontend Changes in the frontend package. pkg: mock-account-service-lib labels Apr 17, 2025
@njlie njlie force-pushed the nl/3283/operator-webhooks branch from 1950deb to d241f0f Compare April 17, 2025 21:54
@njlie njlie marked this pull request as ready for review April 18, 2025 20:26
@njlie njlie force-pushed the nl/3283/operator-webhooks branch from 886bdac to 38510de Compare April 24, 2025 22:41
Copy link

github-actions bot commented Apr 24, 2025

🚀 Performance Test Results

Performance test summary not found.

📜 Logs

> [email protected] run-tests:testenv /home/runner/work/rafiki/rafiki/test/performance
> ./scripts/run-tests.sh -e test "-k" "-q" "--vus" "4" "--duration" "1m"

Cloud Nine GraphQL API is up: http://localhost:3101/graphql
Cloud Nine Wallet Address is up: http://localhost:3100/
Happy Life Bank Address is up: http://localhost:4100/
cloud-nine-wallet-test-backend already set
cloud-nine-wallet-test-auth already set
happy-life-bank-test-backend already set
happy-life-bank-test-auth already set


  █ TOTAL RESULTS 

    HTTP
    http_req_duration....................: avg=1.5ms min=1.5ms med=1.5ms max=1.5ms p(90)=1.5ms p(95)=1.5ms
    http_req_failed......................: 100.00% 1 out of 1
    http_reqs............................: 1       366.819961/s

    NETWORK
    data_received........................: 232 B   85 kB/s
    data_sent............................: 505 B   185 kB/s



/home/runner/work/rafiki/rafiki/test/performance:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  [email protected] run-tests:testenv: `./scripts/run-tests.sh -e test "-k" "-q" "--vus" "4" "--duration" "1m"`
Exit status 107

Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

Looks good, some minor comments.

Also, I think it would be good to enable this feature under an environment variable eg (SEND_ALL_WEBHOOKS_TO_OPERATOR). Can do it separately after this is merged in

Also some tests are failing

@@ -50,6 +51,7 @@ export const listWebhooks = async (
`,
variables: args
})
console.log('response.data.webhookEvents=', response.data.webhookEvents)
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
console.log('response.data.webhookEvents=', response.data.webhookEvents)

@@ -32,6 +33,7 @@ interface GetPageOptions {

export interface WebhookService {
getEvent(id: string): Promise<WebhookEvent | undefined>
getWebhook(id: string): Promise<Webhook | undefined>
Copy link
Contributor

Choose a reason for hiding this comment

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

is getWebhook used?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like its used for testing

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 managed to rewrite the tests such that it's not necessary anymore. So it can be removed.

@@ -379,12 +379,13 @@ async function getOrPollByUrl(
const existingWalletAddress = await getWalletAddressByUrl(deps, url)
if (existingWalletAddress) return existingWalletAddress

await WalletAddressEvent.query(deps.knex).insert({
await WalletAddressEvent.query(deps.knex).insertGraph({
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can make an nice-to-have issue for this:
We should check the path/prefix of the wallet address, and if it matches a particular tenant, we send that to them instead of the operator tenant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Captured in #3414

@njlie njlie force-pushed the nl/3283/operator-webhooks branch from 38510de to 3324c3b Compare April 29, 2025 19:02
)
const formattedSettings = formatSettings(settings)

await sendWebhookEvent(deps, webhook, formattedSettings)
Copy link
Contributor

@BlairCurrey BlairCurrey Apr 30, 2025

Choose a reason for hiding this comment

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

do we need to pass operatorSettings into sendWebhookEvent? Otherwise i dont think we ever do the duplicate publish to operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So sendWebhookEvent does not actually distinguish between if a webhook is for an operator or a tenant. Rather, webhooks for tenants and the operator are all occupying the same queue that sendWebhookEvent processes. So each time another service determines that a webhook event has occurred, it will create 1-2 webhooks depending on if the recipient is the operator or not.

This does conflict with the concept I'm introducing in this PR which is the distinction between webhooks and webhook events. This would probably make more sense if it were renamed to processWebhook instead of processWebhookEvent.

Copy link
Contributor

@BlairCurrey BlairCurrey May 1, 2025

Choose a reason for hiding this comment

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

as discussed in slack, it looks like the optional operatorSettings just needs to be removed from sendWebhookEvent args then

@njlie njlie requested a review from BlairCurrey May 1, 2025 17:39
@njlie njlie merged commit 800935b into 2893/multi-tenancy-v1 May 1, 2025
38 checks passed
@njlie njlie deleted the nl/3283/operator-webhooks branch May 1, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. pkg: mock-account-service-lib pkg: mock-ase type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants