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(tempest): Add cron job and tasks #82454

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tobias-wilfert
Copy link
Member

@tobias-wilfert tobias-wilfert commented Dec 20, 2024

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 20, 2024
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 88.57143% with 8 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/tempest/tasks.py 87.69% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #82454       +/-   ##
===========================================
+ Coverage   59.35%   80.51%   +21.16%     
===========================================
  Files        7015     7323      +308     
  Lines      306414   322093    +15679     
  Branches    21016    21016               
===========================================
+ Hits       181857   259343    +77486     
+ Misses     124151    62344    -61807     
  Partials      406      406               

@@ -72,6 +72,8 @@ class UseCase(enum.Enum):
PROFILING = "profiling"
""" An internal project key for submitting escalating issues metrics."""
ESCALATING_ISSUES = "escalating_issues"
""" An internal project key for submitting events from tempest."""
TEMPEST = "tempest"
Copy link
Member

@vgrozdanic vgrozdanic Dec 23, 2024

Choose a reason for hiding this comment

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

you will need to create a django migration for this: https://develop.sentry.dev/backend/application-domains/database-migrations/

Django saves all these changes in migrations, although this will be no-op SQL. I suggest doing this in a separate PR, which will only contain this change and a migrations files created by django, as it will be easier to review it for owners-migrations team.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean just put the Migration in a separate PR or also this change itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

So tried to make a migration for this with @shellmayr and got No changes detected ... one can make an empty migration but not sure what the point of that would be?

serializer.save(created_by_id=request.user.id, project=project)
credentials = serializer.save(created_by_id=request.user.id, project=project)
# Make initial call to determine the latest item ID
fetch_latest_item_id.delay(credentials.id)
Copy link
Member

Choose a reason for hiding this comment

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

how exepensive is fetching of the latest item? It might happen that we manually call this task, and in the next few milliseconds periodic task collects this credentials, see that there is no last item and calls this task again.

Will we have problem if that happens? Or is it ok if we fetch that twice in a short period of time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fetching this twice in a short period of time should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

If this turns out to unexpectedly cause issues we can always remove this and just defer the work to the actual task (than they would just need to do this on the first iteration).

Comment on lines 91 to 95
dsn=ProjectKey.objects.get_or_create(
use_case=UseCase.TEMPEST, project=credentials.project
)[
0
].get_dsn(), # This does generate a dsn not sure if it will work in the grand scheme of things though.
Copy link
Member

Choose a reason for hiding this comment

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

nit: for a better code readability, i would extract this into a variable outside of this function call, and then just pass dsn as the variable. It will make function call and all the args easier to read

Copy link
Member

Choose a reason for hiding this comment

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

Also, how and when are we going to create this ProjectKey for Tempest related things?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what you mean with the second comment.


@patch("sentry.tempest.tasks.fetch_latest_id_from_tempest")
def test_fetch_latest_item_id_task(self, mock_fetch):
mock_fetch.return_value = "20001"
Copy link
Member

Choose a reason for hiding this comment

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

Should this return a json object:

{
  "latest_id": "20001"
}

Inside fetch_latest_item_id we access this field?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently it just returns the number (no json) but that might be something we want to change 🤔


@patch("sentry.tempest.tasks.fetch_latest_id_from_tempest")
def test_fetch_latest_item_id_error(self, mock_fetch):
mock_fetch.return_value = "Invalid credentials"
Copy link
Member

Choose a reason for hiding this comment

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

I don't know how response from tempest look like, but maybe it's better if we always return JSON objects, with key "error" if something bad happened:

{
  "error": "Invalid credentials"
}

That way we can always expect JSON response and just read the keys we need

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that might be nicer.

@tobias-wilfert tobias-wilfert changed the title WIP: feat(tempest) Add cron job and tasks WIP: feat(tempest): Add cron job and tasks Jan 8, 2025
@tobias-wilfert tobias-wilfert changed the title WIP: feat(tempest): Add cron job and tasks feat(tempest): Add cron job and tasks Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants