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

feat: Only send status checks when payload has changed #74

Merged
merged 4 commits into from
Aug 29, 2023

Conversation

scott-codecov
Copy link
Contributor

Resolves codecov/engineering-team#350

Only send status notifications when the payload has changed from the last time we sent the same notification.

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #74 (348d638) into main (aca010e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #74   +/-   ##
=======================================
  Coverage   98.59%   98.59%           
=======================================
  Files         359      359           
  Lines       26284    26322   +38     
=======================================
+ Hits        25914    25952   +38     
  Misses        370      370           
Flag Coverage Δ
integration 98.56% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 98.56% <100.00%> (+<0.01%) ⬆️
onlysomelabels 98.59% <100.00%> (+<0.01%) ⬆️
unit 98.56% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 97.30% <100.00%> (+<0.01%) ⬆️
OutsideTasks 98.34% <100.00%> (+<0.01%) ⬆️
Files Changed Coverage Δ
services/notification/notifiers/status/base.py 98.67% <100.00%> (+0.10%) ⬆️
...s/notification/notifiers/tests/unit/test_status.py 100.00% <100.00%> (ø)
Related Entrypoints
run/app.tasks.notify.Notify

Copy link
Contributor

@giovanni-guidini giovanni-guidini 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, left a comment about the cache key tho

)

last_payload = cache.get_backend().get(cache_key)
if last_payload is NO_VALUE or last_payload != payload:
Copy link
Contributor

Choose a reason for hiding this comment

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

if the payload is JSON serializable (not sure if it is), can we use the payload as the key?
It would save us the last_payload != payload check... if the payload is there (as a key) we know we sent that before (in the last TTL seconds)

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'm not sure that would work as expected. Imagine the following sequence of events...

  1. notify with payload X -> hashes to ABC (not in cache so we send notification)
  2. notify with payload X -> hashes to ABC (already cached, skip notification)
  3. notify with payload Y -> hashes to DEF (not in cache so we send notification)
  4. notify with payload X -> hashes to ABC (already in cache, skip notification)

We need to make sure that the last item there actually DOES send a notification.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see... Then indeed my understanding was incorrect.
I thought that case 4 there would indicate a task that got delayed for whatever reason (had to retry for example) and was "stale" data (because something more recent, in this case payload Y) was already delivered.

But indeed I see that case 4 would skip notification and it's not what we want.
Thanks for taking the time to explain.

@scott-codecov scott-codecov merged commit 569d4ee into main Aug 29, 2023
12 checks passed
@scott-codecov scott-codecov deleted the scott/status-caching branch August 29, 2023 12:54
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.

Implement GH Check Caching
2 participants