-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
src/sentry/tempest/tasks.py
Outdated
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
tests/sentry/tempest/test_tempest.py
Outdated
|
||
@patch("sentry.tempest.tasks.fetch_latest_id_from_tempest") | ||
def test_fetch_latest_item_id_task(self, mock_fetch): | ||
mock_fetch.return_value = "20001" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🤔
tests/sentry/tempest/test_tempest.py
Outdated
|
||
@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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Fixes: https://github.com/getsentry/team-gdx/issues/31