Skip to content

CMR-10393: Allow only one sqs client queue to subscribe to one collection for NRT (ingest) subscriptions#2216

Merged
jmaeng72 merged 29 commits intomasterfrom
CMR-10393-2
Feb 19, 2025
Merged

CMR-10393: Allow only one sqs client queue to subscribe to one collection for NRT (ingest) subscriptions#2216
jmaeng72 merged 29 commits intomasterfrom
CMR-10393-2

Conversation

@jmaeng72
Copy link
Copy Markdown
Contributor

@jmaeng72 jmaeng72 commented Feb 13, 2025

Overview

What is the feature/fix?

Problem: The ingest (NRT) subscriptions has a bug where if User1 creates a subscription to Coll1 and then User2 creates a different subscription to the same Coll1 for the same queue, it will overwrite the first subscription in the backend SNS subscription filter for that queue.

What is the Solution?

Add a verify check to make sure this does not happen

What areas of the application does this impact?

Ingest subscription

Checklist

  • I have updated/added unit and int tests that prove my fix is effective or that my feature works
  • New and existing unit and int tests pass locally and remotely
  • clj-kondo has been run locally and all errors corrected
  • I have removed unnecessary/dead code and imports in files I have changed
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • refactored to reduce number of system state resets by updating fixtures (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

@jmaeng72 jmaeng72 self-assigned this Feb 13, 2025
NOTE: The same SQS endpoint cannot be used for the same collection more than once.
For example if you, USER 1, create a subscriptioon with an SQS queue: SQS1 endpoint to filter UPDATE granule events from Collection 1, another user, USER 2, cannot create a new subscription with the same SQS1 queue endpoint to filter granules from Collection 1 again.
Ultimately, only ONE user can perform CRUD operations on the specific SQS endpoint used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hope this makes sense... please double check during your reviews if this is clear

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Its clear to me.

@jmaeng72 jmaeng72 marked this pull request as draft February 13, 2025 21:45
@jmaeng72 jmaeng72 removed the request for review from jceaser February 13, 2025 21:45
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 79.62963% with 11 lines in your changes missing coverage. Please review.

Project coverage is 58.25%. Comparing base (0733700) to head (77d5029).

Files with missing lines Patch % Lines
ingest-app/src/cmr/ingest/api/subscriptions.clj 71.42% 1 Missing and 5 partials ⚠️
...a-db-app/src/cmr/metadata_db/api/subscriptions.clj 0.00% 3 Missing ⚠️
ingest-app/src/cmr/ingest/config.clj 66.66% 0 Missing and 1 partial ⚠️
transmit-lib/src/cmr/transmit/metadata_db2.clj 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2216      +/-   ##
==========================================
+ Coverage   58.23%   58.25%   +0.01%     
==========================================
  Files        1056     1056              
  Lines       71134    71185      +51     
  Branches     2063     2068       +5     
==========================================
+ Hits        41428    41467      +39     
- Misses      27780    27784       +4     
- Partials     1926     1934       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

(let [curr-endpoint (:EndPoint subscription-concept)]
(if (and (= "ingest" (:Method subscription-concept))
(or (some? (re-matches #"arn:aws:sqs:.*" curr-endpoint))
(some? (re-matches #"http://localhost:9324.*" curr-endpoint))))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we matching this specific URL? I though the issue was only with SQS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is the local dev SQS ARN (which doesn't start with arn:aws:sqs, but I still wanted to capture it and have it act like it was an sqs arn subscription concept endpoint)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not directed at this specific PR, but are there/do we need guards against localhost subscription URLs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

can you explain further? You mean, do we need to distinguish between localhost URL and localhost SQS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

or are you saying that we might not need line 104 because we don't care about distinguishing between local sqs and local http endpoint?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nah, like when someone sends in a subscription with url endpoint, do we block them/do we even need to block them from sending in a subscription that is for localhost (since that would point to our subscription processor). Again, not aimed directly at this PR, just occurred to me while looking at the localhost there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ooo I see what you are saying. I think we could. It doesn't hurt to just limit them to non-local URLs for http endpoints

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated with new blocker for this

(or (some? (re-matches #"arn:aws:sqs:.*" curr-endpoint))
(some? (re-matches #"http://localhost:9324.*" curr-endpoint))))
(let [collection-concept-id (:CollectionConceptId subscription-concept)
cache-content (metadata-db2/get-subscription-cache-content context collection-concept-id)]
Copy link
Copy Markdown
Contributor

@eereiter eereiter Feb 14, 2025

Choose a reason for hiding this comment

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

I am wondering why you created an API call into metadata-db, instead of just reading the cache directly?

Not asking you to change anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the cache funcs are in the metadata-db app which is typically accessed from the transmit lib that acts like a middle-man. Which is why I created a metadata-db API

@jmaeng72 jmaeng72 marked this pull request as ready for review February 14, 2025 14:35
Copy link
Copy Markdown
Contributor

@jceaser jceaser left a comment

Choose a reason for hiding this comment

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

I had very minor comments, must fix that one new line where the variable is below the let.

Copy link
Copy Markdown
Contributor

@TylerHeald1 TylerHeald1 left a comment

Choose a reason for hiding this comment

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

Just need to make sure the defconfig value is properly added to each environment

@jmaeng72
Copy link
Copy Markdown
Contributor Author

Yep. Just checked each env and it has the parameter with the correct env var

@jmaeng72 jmaeng72 merged commit f17c748 into master Feb 19, 2025
6 checks passed
@jmaeng72 jmaeng72 deleted the CMR-10393-2 branch February 19, 2025 19:44
@jmaeng72 jmaeng72 restored the CMR-10393-2 branch February 20, 2025 19:17
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