Skip to content

Commit

Permalink
Merge branch 'master' into aci/m62-views
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Jan 9, 2025
2 parents e665d9c + 90ee2e9 commit ad952f4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,7 @@ tests/sentry/api/endpoints/test_organization_dashboard_widget_details.py @ge
# Tempest
/src/sentry/tempest/ @getsentry/gdx
/tests/sentry/tempest/ @getsentry/gdx

# Workflow engine
/src/sentry/workflow_engine/ @getsentry/alerts-create-issues
/tests/sentry/workflow_engine/ @getsentry/alerts-create-issues
2 changes: 1 addition & 1 deletion src/sentry/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def authenticate_token(self, request: Request, token: str) -> tuple[Any, Any]:
scope.set_tag("api_token_type", self.token_name)
scope.set_tag("api_project_key", key.id)

return (AnonymousUser(), key)
return (AnonymousUser(), AuthenticatedToken.from_token(key))


@AuthenticationSiloLimit(SiloMode.REGION)
Expand Down
7 changes: 3 additions & 4 deletions src/sentry/api/endpoints/project_user_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from sentry.feedback.usecases.create_feedback import FeedbackCreationSource
from sentry.ingest.userreport import Conflict, save_userreport
from sentry.models.environment import Environment
from sentry.models.projectkey import ProjectKey
from sentry.models.userreport import UserReport
from sentry.utils.dates import epoch

Expand Down Expand Up @@ -55,7 +54,7 @@ def get(self, request: Request, project) -> Response:
:auth: required
"""
# we don't allow read permission with DSNs
if isinstance(request.auth, ProjectKey):
if request.auth is not None and request.auth.kind == "project_key": # type: ignore[union-attr]
return self.respond(status=401)

paginate_kwargs: _PaginateKwargs = {}
Expand Down Expand Up @@ -119,7 +118,7 @@ def post(self, request: Request, project) -> Response:
:param string email: user's email address
:param string comments: comments supplied by user
"""
if hasattr(request.auth, "project_id") and project.id != request.auth.project_id:
if request.auth is not None and project.id != request.auth.project_id: # type: ignore[union-attr] # TODO: real .auth typing
return self.respond(status=401)

serializer = UserReportSerializer(data=request.data)
Expand All @@ -134,7 +133,7 @@ def post(self, request: Request, project) -> Response:
except Conflict as e:
return self.respond({"detail": str(e)}, status=409)

if isinstance(request.auth, ProjectKey):
if request.auth is not None and request.auth.kind == "project_key": # type: ignore[union-attr]
return self.respond(status=200)

return self.respond(
Expand Down
4 changes: 4 additions & 0 deletions src/sentry/auth/services/auth/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AuthenticatedToken(RpcModel):
user_id: int | None = None # only relevant for ApiToken
organization_id: int | None = None
application_id: int | None = None # only relevant for ApiToken
project_id: int | None = None # only relevant for ProjectKey

def token_has_org_access(self, organization_id: int) -> bool:
return self.kind == "api_token" and self.organization_id == organization_id
Expand All @@ -73,12 +74,14 @@ def kinds(cls) -> Mapping[str, Collection[type[Any]]]:
from sentry.models.apikey import ApiKey
from sentry.models.apitoken import ApiToken
from sentry.models.orgauthtoken import OrgAuthToken
from sentry.models.projectkey import ProjectKey

return {
"system": frozenset([SystemToken]),
"api_token": frozenset([ApiToken, ApiTokenReplica]),
"org_auth_token": frozenset([OrgAuthToken, OrgAuthTokenReplica]),
"api_key": frozenset([ApiKey, ApiKeyReplica]),
"project_key": frozenset((ProjectKey,)),
}

@classmethod
Expand Down Expand Up @@ -109,6 +112,7 @@ def from_token(cls, token: Any) -> Optional["AuthenticatedToken"]:
user_id=getattr(token, "user_id", None),
organization_id=getattr(token, "organization_id", None),
application_id=getattr(token, "application_id", None),
project_id=getattr(token, "project_id", None),
)

def get_audit_log_data(self) -> Mapping[str, Any]:
Expand Down
3 changes: 1 addition & 2 deletions src/sentry/monitors/endpoints/base_monitor_checkin_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from sentry.api.paginator import OffsetPaginator
from sentry.api.serializers import serialize
from sentry.api.utils import get_date_range_from_params
from sentry.models.projectkey import ProjectKey
from sentry.monitors.models import MonitorCheckIn
from sentry.monitors.serializers import MonitorCheckInSerializer

Expand All @@ -20,7 +19,7 @@ def get_monitor_checkins(self, request: Request, project, monitor) -> Response:
Retrieve a list of check-ins for a monitor
"""
# we don't allow read permission with DSNs
if isinstance(request.auth, ProjectKey):
if request.auth is not None and request.auth.kind == "project_key": # type: ignore[union-attr]
return self.respond(status=401)

start, end = get_date_range_from_params(request.GET)
Expand Down
6 changes: 0 additions & 6 deletions src/sentry/snuba/metrics/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,6 @@ def should_use_on_demand_metrics(
metrics.incr("on_demand_metrics.should_use_on_demand_metrics.cache_hit")
return cached_result
else:
logger.info(
"should_use_on_demand_metrics.cache_miss",
extra={
"cache_key": local_cache_key,
},
)
result = _should_use_on_demand_metrics(
dataset=dataset,
aggregate=aggregate,
Expand Down
42 changes: 21 additions & 21 deletions static/app/views/explore/hooks/useAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useEffect} from 'react';

import type {Confidence, Organization} from 'sentry/types/organization';
import {trackAnalytics} from 'sentry/utils/analytics';
// import {trackAnalytics} from 'sentry/utils/analytics';
import type {DiscoverDatasets} from 'sentry/utils/discover/types';
import type {UseApiQueryResult} from 'sentry/utils/queryClient';
import type RequestError from 'sentry/utils/requestError/requestError';
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
// import {MutableSearch} from 'sentry/utils/tokenizeSearch';
import type {Visualize} from 'sentry/views/explore/contexts/pageParamsContext/visualizes';
import {usePerformanceSubscriptionDetails} from 'sentry/views/performance/newTraceDetails/traceTypeWarnings/usePerformanceSubscriptionDetails';

Expand Down Expand Up @@ -44,26 +44,26 @@ export function useAnalytics({
return;
}

const search = new MutableSearch(userQuery);
const params = {
organization,
columns,
columns_count: columns.filter(Boolean).length,
confidences,
dataset,
query_status: resultStatus,
result_length: resultLength || 0,
result_missing_root: resultMissingRoot || 0,
result_mode: resultMode,
user_queries: search.formatString(),
user_queries_count: search.tokens.length,
visualizes,
visualizes_count: visualizes.length,
title,
has_exceeded_performance_usage_limit: hasExceededPerformanceUsageLimit,
};
// const search = new MutableSearch(userQuery);
// const params = {
// organization,
// columns,
// columns_count: columns.filter(Boolean).length,
// confidences,
// dataset,
// query_status: resultStatus,
// result_length: resultLength || 0,
// result_missing_root: resultMissingRoot || 0,
// result_mode: resultMode,
// user_queries: search.formatString(),
// user_queries_count: search.tokens.length,
// visualizes,
// visualizes_count: visualizes.length,
// title,
// has_exceeded_performance_usage_limit: hasExceededPerformanceUsageLimit,
// };

trackAnalytics('trace.explorer.metadata', params);
// trackAnalytics('trace.explorer.metadata', params);
}, [
organization,
resultLength,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/api/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_authenticate(self):

user, auth = result
assert user.is_anonymous
assert auth == self.project_key
assert auth == AuthenticatedToken.from_token(self.project_key)

def test_inactive_key(self):
self.project_key.update(status=ProjectKeyStatus.INACTIVE)
Expand Down

0 comments on commit ad952f4

Please sign in to comment.