1818@pytest .mark .django_db (databases = {"default" , "timeseries" })
1919def test_upload_bundle_analysis_success (db , client , mocker , mock_redis ):
2020 upload = mocker .patch .object (TaskService , "upload" )
21- mock_metrics = mocker .patch (
22- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels "
21+ mock_sentry_metrics = mocker .patch (
22+ "upload.views.bundle_analysis.sentry_metrics.incr "
2323 )
2424 create_presigned_put = mocker .patch (
2525 "services.archive.StorageService.create_presigned_put" ,
@@ -89,8 +89,9 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
8989 report_code = None ,
9090 report_type = "bundle_analysis" ,
9191 )
92- mock_metrics .assert_called_with (
93- ** {
92+ mock_sentry_metrics .assert_called_with (
93+ "upload" ,
94+ tags = {
9495 "agent" : "cli" ,
9596 "version" : "0.4.7" ,
9697 "action" : "bundle_analysis" ,
@@ -106,8 +107,8 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
106107@override_settings (SHELTER_SHARED_SECRET = "shelter-shared-secret" )
107108def test_upload_bundle_analysis_success_shelter (db , client , mocker , mock_redis ):
108109 upload = mocker .patch .object (TaskService , "upload" )
109- mock_metrics = mocker .patch (
110- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels "
110+ mock_sentry_metrics = mocker .patch (
111+ "upload.views.bundle_analysis.sentry_metrics.incr "
111112 )
112113 create_presigned_put = mocker .patch (
113114 "services.archive.StorageService.create_presigned_put" ,
@@ -179,8 +180,9 @@ def test_upload_bundle_analysis_success_shelter(db, client, mocker, mock_redis):
179180 report_code = None ,
180181 report_type = "bundle_analysis" ,
181182 )
182- mock_metrics .assert_called_with (
183- ** {
183+ mock_sentry_metrics .assert_called_with (
184+ "upload" ,
185+ tags = {
184186 "agent" : "cli" ,
185187 "version" : "0.4.7" ,
186188 "action" : "bundle_analysis" ,
@@ -199,9 +201,6 @@ def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis):
199201 "services.archive.StorageService.create_presigned_put" ,
200202 return_value = "test-presigned-put" ,
201203 )
202- mock_metrics = mocker .patch (
203- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
204- )
205204
206205 repository = RepositoryFactory .create ()
207206 org_token = OrganizationLevelTokenFactory .create (owner = repository .author )
@@ -218,17 +217,6 @@ def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis):
218217 format = "json" ,
219218 )
220219 assert res .status_code == 201
221- mock_metrics .assert_called_with (
222- ** {
223- "agent" : "unknown-user-agent" ,
224- "version" : "unknown-user-agent" ,
225- "action" : "bundle_analysis" ,
226- "endpoint" : "bundle_analysis" ,
227- "repo_visibility" : "private" ,
228- "is_using_shelter" : "no" ,
229- "position" : "end" ,
230- },
231- )
232220
233221
234222@pytest .mark .django_db (databases = {"default" , "timeseries" })
@@ -238,9 +226,6 @@ def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis):
238226 "services.archive.StorageService.create_presigned_put" ,
239227 return_value = "test-presigned-put" ,
240228 )
241- mock_metrics = mocker .patch (
242- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
243- )
244229
245230 repository = RepositoryFactory .create ()
246231 commit = CommitFactory .create (repository = repository )
@@ -265,17 +250,6 @@ def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis):
265250 report_code = None ,
266251 report_type = "bundle_analysis" ,
267252 )
268- mock_metrics .assert_called_with (
269- ** {
270- "agent" : "unknown-user-agent" ,
271- "version" : "unknown-user-agent" ,
272- "action" : "bundle_analysis" ,
273- "endpoint" : "bundle_analysis" ,
274- "repo_visibility" : "private" ,
275- "is_using_shelter" : "no" ,
276- "position" : "end" ,
277- },
278- )
279253
280254
281255def test_upload_bundle_analysis_missing_args (db , client , mocker , mock_redis ):
@@ -284,9 +258,6 @@ def test_upload_bundle_analysis_missing_args(db, client, mocker, mock_redis):
284258 "services.archive.StorageService.create_presigned_put" ,
285259 return_value = "test-presigned-put" ,
286260 )
287- mock_metrics = mocker .patch (
288- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
289- )
290261
291262 repository = RepositoryFactory .create ()
292263 commit = CommitFactory .create (repository = repository )
@@ -315,16 +286,6 @@ def test_upload_bundle_analysis_missing_args(db, client, mocker, mock_redis):
315286 assert res .status_code == 400
316287 assert res .json () == {"commit" : ["This field is required." ]}
317288 assert not upload .called
318- mock_metrics .assert_called_with (
319- ** {
320- "agent" : "unknown-user-agent" ,
321- "version" : "unknown-user-agent" ,
322- "action" : "bundle_analysis" ,
323- "endpoint" : "bundle_analysis" ,
324- "is_using_shelter" : "no" ,
325- "position" : "start" ,
326- },
327- )
328289
329290
330291def test_upload_bundle_analysis_invalid_token (db , client , mocker , mock_redis ):
@@ -363,9 +324,6 @@ def test_upload_bundle_analysis_github_oidc_auth(
363324 "services.archive.StorageService.create_presigned_put" ,
364325 return_value = "test-presigned-put" ,
365326 )
366- mock_metrics = mocker .patch (
367- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
368- )
369327 repository = RepositoryFactory ()
370328 mock_jwt_decode .return_value = {
371329 "repository" : f"url/{ repository .name } " ,
@@ -386,31 +344,18 @@ def test_upload_bundle_analysis_github_oidc_auth(
386344 format = "json" ,
387345 )
388346 assert res .status_code == 201
389- mock_metrics .assert_called_with (
390- ** {
391- "agent" : "unknown-user-agent" ,
392- "version" : "unknown-user-agent" ,
393- "action" : "bundle_analysis" ,
394- "endpoint" : "bundle_analysis" ,
395- "repo_visibility" : "private" ,
396- "is_using_shelter" : "no" ,
397- "position" : "end" ,
398- },
399- )
400347
401348
402349@pytest .mark .django_db (databases = {"default" , "timeseries" })
403350def test_upload_bundle_analysis_measurement_datasets_created (
404351 db , client , mocker , mock_redis
405352):
406353 mocker .patch .object (TaskService , "upload" )
354+ mocker .patch ("upload.views.bundle_analysis.sentry_metrics.incr" )
407355 mocker .patch (
408356 "services.archive.StorageService.create_presigned_put" ,
409357 return_value = "test-presigned-put" ,
410358 )
411- mock_metrics = mocker .patch (
412- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
413- )
414359
415360 repository = RepositoryFactory .create ()
416361 commit_sha = "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef"
@@ -447,32 +392,18 @@ def test_upload_bundle_analysis_measurement_datasets_created(
447392 repository_id = repository .pk ,
448393 ).exists ()
449394
450- mock_metrics .assert_called_with (
451- ** {
452- "agent" : "cli" ,
453- "version" : "0.4.7" ,
454- "action" : "bundle_analysis" ,
455- "endpoint" : "bundle_analysis" ,
456- "repo_visibility" : "private" ,
457- "is_using_shelter" : "no" ,
458- "position" : "end" ,
459- },
460- )
461-
462395
463396@override_settings (TIMESERIES_ENABLED = False )
464397@pytest .mark .django_db (databases = {"default" , "timeseries" })
465398def test_upload_bundle_analysis_measurement_timeseries_disabled (
466399 db , client , mocker , mock_redis
467400):
468401 mocker .patch .object (TaskService , "upload" )
402+ mocker .patch ("upload.views.bundle_analysis.sentry_metrics.incr" )
469403 mocker .patch (
470404 "services.archive.StorageService.create_presigned_put" ,
471405 return_value = "test-presigned-put" ,
472406 )
473- mock_metrics = mocker .patch (
474- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
475- )
476407
477408 repository = RepositoryFactory .create ()
478409 commit_sha = "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef"
@@ -509,18 +440,6 @@ def test_upload_bundle_analysis_measurement_timeseries_disabled(
509440 repository_id = repository .pk ,
510441 ).exists ()
511442
512- mock_metrics .assert_called_with (
513- ** {
514- "agent" : "cli" ,
515- "version" : "0.4.7" ,
516- "action" : "bundle_analysis" ,
517- "endpoint" : "bundle_analysis" ,
518- "repo_visibility" : "private" ,
519- "is_using_shelter" : "no" ,
520- "position" : "end" ,
521- },
522- )
523-
524443
525444@pytest .mark .django_db (databases = {"default" , "timeseries" })
526445def test_upload_bundle_analysis_no_repo (db , client , mocker , mock_redis ):
@@ -530,9 +449,6 @@ def test_upload_bundle_analysis_no_repo(db, client, mocker, mock_redis):
530449 "services.archive.StorageService.create_presigned_put" ,
531450 return_value = "test-presigned-put" ,
532451 )
533- mock_metrics = mocker .patch (
534- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
535- )
536452
537453 repository = RepositoryFactory .create ()
538454 org_token = OrganizationLevelTokenFactory .create (owner = repository .author )
@@ -552,24 +468,10 @@ def test_upload_bundle_analysis_no_repo(db, client, mocker, mock_redis):
552468 assert res .json () == {"detail" : "Repository not found." }
553469 assert not upload .called
554470
555- mock_metrics .assert_called_with (
556- ** {
557- "agent" : "unknown-user-agent" ,
558- "version" : "unknown-user-agent" ,
559- "action" : "bundle_analysis" ,
560- "endpoint" : "bundle_analysis" ,
561- "is_using_shelter" : "no" ,
562- "position" : "start" ,
563- },
564- )
565-
566471
567472@pytest .mark .django_db (databases = {"default" , "timeseries" })
568473def test_upload_bundle_analysis_tokenless_success (db , client , mocker , mock_redis ):
569474 upload = mocker .patch .object (TaskService , "upload" )
570- mock_metrics = mocker .patch (
571- "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels"
572- )
573475
574476 create_presigned_put = mocker .patch (
575477 "services.archive.StorageService.create_presigned_put" ,
@@ -606,18 +508,6 @@ def test_upload_bundle_analysis_tokenless_success(db, client, mocker, mock_redis
606508 assert upload .called
607509 create_presigned_put .assert_called_once_with ("bundle-analysis" , ANY , 30 )
608510
609- mock_metrics .assert_called_with (
610- ** {
611- "agent" : "cli" ,
612- "version" : "0.4.7" ,
613- "action" : "bundle_analysis" ,
614- "endpoint" : "bundle_analysis" ,
615- "repo_visibility" : "public" ,
616- "is_using_shelter" : "no" ,
617- "position" : "end" ,
618- },
619- )
620-
621511
622512@pytest .mark .django_db (databases = {"default" , "timeseries" })
623513def test_upload_bundle_analysis_tokenless_no_repo (db , client , mocker , mock_redis ):
0 commit comments