Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/sentry/seer/signed_seer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import hmac
from random import random
from typing import Any
from urllib.parse import urlparse

from django.conf import settings
from urllib3 import BaseHTTPResponse, HTTPConnectionPool

from sentry import options
from sentry.utils import metrics


def make_signed_seer_api_request(
Expand All @@ -21,13 +23,19 @@ def make_signed_seer_api_request(
if timeout:
timeout_options["timeout"] = timeout

return connection_pool.urlopen(
"POST",
path,
body=body,
headers={"content-type": "application/json;charset=utf-8", **auth_headers},
**timeout_options,
)
with metrics.timer(
"seer.request_to_seer",
sample_rate=1.0,
# Pull off query params, if any
tags={"endpoint": urlparse(path).path},
):
return connection_pool.urlopen(
"POST",
path,
body=body,
headers={"content-type": "application/json;charset=utf-8", **auth_headers},
**timeout_options,
)


def sign_with_seer_secret(url: str, body: bytes):
Expand Down
17 changes: 16 additions & 1 deletion tests/sentry/seer/test_signed_seer_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import Mock
from unittest.mock import MagicMock, Mock, patch

import pytest
from django.test import override_settings
Expand Down Expand Up @@ -67,3 +67,18 @@ def test_uses_shared_secret():
"Authorization": "Rpcsignature rpc0:96f23d5b3df807a9dc91f090078a46c00e17fe8b0bc7ef08c9391fa8b37a66b5",
},
)


@pytest.mark.django_db
@pytest.mark.parametrize("path", [PATH, f"{PATH}?dogs=great"])
@patch("sentry.seer.signed_seer_api.metrics.timer")
def test_times_request(mock_metrics_timer: MagicMock, path: str):
run_test_case(path=path)
mock_metrics_timer.assert_called_with(
"seer.request_to_seer",
sample_rate=1.0,
tags={
# In both cases the path is the same, because query params are stripped
"endpoint": PATH,
},
)