Skip to content

Commit

Permalink
error code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Chen authored and Rachel Chen committed Jan 31, 2025
1 parent e55a1a2 commit 7266cc6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions snuba/querylog/query_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def get_request_status(cause: Exception | None = None) -> Status:
slo_status = RequestStatus.RATE_LIMITED
elif isinstance(cause, ClickhouseError):
slo_status = ERROR_CODE_MAPPINGS.get(cause.code, RequestStatus.ERROR)
print("slo_statussss", slo_status)
elif isinstance(cause, TimeoutError):
slo_status = RequestStatus.QUERY_TIMEOUT
elif isinstance(cause, ExecutionTimeoutError):
Expand All @@ -149,6 +150,7 @@ def get_request_status(cause: Exception | None = None) -> Status:
slo_status = RequestStatus.INVALID_REQUEST
else:
slo_status = RequestStatus.ERROR
print("slo_statussss", slo_status)

return Status(slo_status)

Expand Down Expand Up @@ -338,6 +340,7 @@ def request_status(self) -> RequestStatus:
# If we do not have any recorded query and we did not specifically log
# invalid_query, we assume there was an error somewhere.
if not self.query_list:
print("whatisthis")
return RequestStatus.ERROR

for query in self.query_list:
Expand Down
1 change: 1 addition & 0 deletions snuba/state/cache/redis/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __get_value_with_simple_readthrough(
if timer is not None:
timer.mark("cache_set")
except Exception as e:
print("kdjflsdkf", e)
metrics.increment("execute_error", tags=metric_tags)
raise e
return value
Expand Down
3 changes: 2 additions & 1 deletion snuba/web/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Mapping, TypedDict, cast
from typing import Any, Mapping, NotRequired, TypedDict, cast

from snuba.reader import Column, Result, Row, transform_rows
from snuba.utils.serializable_exception import JsonSerializable, SerializableException
Expand All @@ -11,6 +11,7 @@ class QueryExtraData(TypedDict):
stats: Mapping[str, Any]
sql: str
experiments: Mapping[str, Any]
code: NotRequired[int]


class QueryException(SerializableException):
Expand Down
11 changes: 11 additions & 0 deletions snuba/web/db_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,17 @@ def _raw_query(
error_code=error_code,
triggered_rate_limiter=str(trigger_rate_limiter),
)
if error_code == 241:
raise QueryException.from_args(
cause.__class__.__name__,
str(cause),
{
"stats": stats,
"sql": sql,
"experiments": clickhouse_query.get_experiments(),
"code": 241,
},
) from cause
raise QueryException.from_args(
# This exception needs to have the message of the cause in it for sentry
# to pick it up properly
Expand Down
7 changes: 5 additions & 2 deletions snuba/web/rpc/v1/endpoint_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from snuba import environment
from snuba.utils.metrics.wrapper import MetricsWrapper
from snuba.web import QueryException
from snuba.web.rpc import RPCEndpoint, TraceItemDataResolver
from snuba.web.rpc.common.exceptions import BadSnubaRPCRequestException
from snuba.web.rpc.v1.resolvers import ResolverTimeSeries
Expand Down Expand Up @@ -112,8 +113,10 @@ def _execute(self, in_msg: TimeSeriesRequest) -> TimeSeriesResponse:
resolver = self.get_resolver(in_msg.meta.trace_item_type)
try:
return resolver.resolve(in_msg)
except Exception as e:
if "DB::Exception: Memory limit (for query) exceeded" in str(e):
except QueryException as e:
if e.extra[
"code"
] == 241 or "DB::Exception: Memory limit (for query) exceeded" in str(e):
metrics.increment("endpoint_trace_item_table_OOM")
sentry_sdk.capture_exception(e)
raise BadSnubaRPCRequestException(str(e))
7 changes: 5 additions & 2 deletions snuba/web/rpc/v1/endpoint_trace_item_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from snuba import environment
from snuba.utils.metrics.wrapper import MetricsWrapper
from snuba.web import QueryException
from snuba.web.rpc import RPCEndpoint, TraceItemDataResolver
from snuba.web.rpc.common.exceptions import BadSnubaRPCRequestException
from snuba.web.rpc.v1.resolvers import ResolverTraceItemTable
Expand Down Expand Up @@ -111,8 +112,10 @@ def _execute(self, in_msg: TraceItemTableRequest) -> TraceItemTableResponse:
resolver = self.get_resolver(in_msg.meta.trace_item_type)
try:
return resolver.resolve(in_msg)
except Exception as e:
if "DB::Exception: Memory limit (for query) exceeded" in str(e):
except QueryException as e:
if e.extra[
"code"
] == 241 or "DB::Exception: Memory limit (for query) exceeded" in str(e):
metrics.increment("endpoint_trace_item_table_OOM")
sentry_sdk.capture_exception(e)
raise BadSnubaRPCRequestException(str(e))

0 comments on commit 7266cc6

Please sign in to comment.