Skip to content

Commit

Permalink
[Feat] Add metric to track if org performed an upload (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov authored Jun 24, 2024
1 parent 5cf046c commit 0e4a72f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions django_scaffold/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"shared.django_apps.pg_telemetry",
"shared.django_apps.rollouts",
"shared.django_apps.user_measurements",
"shared.django_apps.codecov_metrics",
"psqlextra",
# Needed to install legacy migrations
"django.contrib.admin",
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ requests==2.32.3
respx==0.20.2
# via -r requirements.in
rfc3986[idna2008]==1.4.0
# via httpx
# via
# httpx
# rfc3986
rsa==4.7.2
# via google-auth
s3transfer==0.10.1
Expand Down
22 changes: 21 additions & 1 deletion tasks/tests/unit/test_upload_task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from datetime import datetime, timedelta
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import MagicMock, call

import mock
import pytest
Expand Down Expand Up @@ -213,6 +213,9 @@ def test_upload_task_call_bundle_analysis(
celery_app,
):
chain = mocker.patch("tasks.upload.chain")
mocker.patch(
"shared.django_apps.codecov_metrics.service.codecov_metrics.UserOnboardingMetricsService.create_user_onboarding_metric"
)
storage_path = (
"v1/repos/testing/ed1bdd67-8fd2-4cdb-ac9e-39b99e4a3892/bundle_report.sqlite"
)
Expand Down Expand Up @@ -281,6 +284,9 @@ def test_upload_task_call_test_results(
celery_app,
):
chord = mocker.patch("tasks.upload.chord")
mocker.patch(
"shared.django_apps.codecov_metrics.service.codecov_metrics.UserOnboardingMetricsService.create_user_onboarding_metric"
)
storage_path = "v4/raw/2019-05-22/C3C4715CA57C910D11D5EB899FC86A7E/4c4e4654ac25037ae869caeb3619d485970b6304/a84d445c-9c1e-434f-8275-f18f1f320f81.txt"
redis_queue = [{"url": storage_path, "build_code": "some_random_build"}]
jsonified_redis_queue = [json.dumps(x) for x in redis_queue]
Expand Down Expand Up @@ -667,9 +673,20 @@ def test_upload_task_proper_parent(
mock_redis.lists[f"uploads/{commit.repoid}/{commit.commitid}"] = (
jsonified_redis_queue
)
mock_create_user_onboarding_metric = mocker.patch(
"shared.django_apps.codecov_metrics.service.codecov_metrics.UserOnboardingMetricsService.create_user_onboarding_metric"
)

result = UploadTask().run_impl(dbsession, commit.repoid, commit.commitid)
expected_result = {"was_setup": False, "was_updated": True}
assert expected_result == result
expected_call = call(
org_id=owner.ownerid,
event="COMPLETED_UPLOAD",
payload={},
)
assert mock_create_user_onboarding_metric.call_args_list == [expected_call]

assert commit.message == "dsidsahdsahdsa"
assert commit.parent_commit_id == "c5b67303452bbff57cc1f49984339cde39eb1db5"
assert not mocked_1.called
Expand Down Expand Up @@ -876,6 +893,9 @@ def test_upload_task_upload_already_created(
mock_storage,
):
mocked_schedule_task = mocker.patch.object(UploadTask, "schedule_task")
mocker.patch(
"shared.django_apps.codecov_metrics.service.codecov_metrics.UserOnboardingMetricsService.create_user_onboarding_metric"
)
mock_possibly_update_commit_from_provider_info = mocker.patch(
"tasks.upload.possibly_update_commit_from_provider_info", return_value=True
)
Expand Down
8 changes: 8 additions & 0 deletions tasks/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from redis.exceptions import LockError
from shared.celery_config import upload_task_name
from shared.config import get_config
from shared.django_apps.codecov_metrics.service.codecov_metrics import (
UserOnboardingMetricsService,
)
from shared.torngit.exceptions import (
TorngitClientError,
TorngitRepoNotFoundError,
Expand Down Expand Up @@ -510,6 +513,11 @@ def run_impl_within_lock(
)
upload_context.prepare_kwargs_for_retry(kwargs)
self.retry(countdown=60, kwargs=kwargs)

UserOnboardingMetricsService.create_user_onboarding_metric(
org_id=repository.ownerid, event="COMPLETED_UPLOAD", payload={}
)

argument_list = []

for arguments in upload_context.arguments_list():
Expand Down

0 comments on commit 0e4a72f

Please sign in to comment.