Copilot commented on code in PR #42089:
URL: https://github.com/apache/superset/pull/42089#discussion_r3693812192
##########
superset/utils/decorators.py:
##########
@@ -36,7 +36,21 @@
from superset.stats_logger import BaseStatsLogger
-def statsd_gauge(metric_prefix: str | None = None) -> Callable[..., Any]:
+def record_statsd_gauge_failure(metric_prefix: str, ex: Exception) -> None:
+ """Record a warning or error gauge using the shared exception contract."""
+ suffix = (
+ "warning"
+ if hasattr(ex, "status") and ex.status < 500 # pylint:
disable=no-member
+ else "error"
+ )
+ app.config["STATS_LOGGER"].gauge(f"{metric_prefix}.{suffix}", 1)
Review Comment:
`record_statsd_gauge_failure` assumes `ex.status` is an int. If an exception
defines a non-int `status` (or a property with unexpected behavior), the `<
500` comparison can raise and mask the original failure while also skipping
metric emission. Use `getattr` + `isinstance(..., int)` to make this safe.
##########
superset/reports/notifications/slack_transport.py:
##########
@@ -0,0 +1,310 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import math
+import time
+from collections.abc import Callable
+from functools import partial
+from typing import TypeVar
+from urllib.error import HTTPError
+
+import backoff
+from flask import current_app as app
+from slack_sdk import WebClient
+from slack_sdk.errors import SlackApiError, SlackRequestError
+
+from superset.reports.notifications.exceptions import (
+ NotificationTransientError,
+ NotificationUnprocessableException,
+)
+from superset.utils.slack import (
+ get_slack_api_error_code,
+ get_slack_api_status_code,
+ is_retryable_slack_transport_error,
+ is_transient_slack_api_error,
+ is_transient_slack_transport_error,
+ SLACK_TRANSIENT_TRANSPORT_ERRORS,
+)
+
+SLACK_API_TIMEOUT_MARGIN = 1
+
+_SlackApiResult = TypeVar("_SlackApiResult")
+
+_SLACK_RETRY_DEADLINE_MESSAGE = (
+ "Slack send retry deadline exceeded; increase SLACK_SEND_RETRY_MAX_TIME "
+ "for slow Slack workspaces or large-file reports"
+)
+
+
+class SlackRetryDeadlineError(Exception):
+ """A Slack operation was skipped because the shared send budget expired."""
+
+ def __init__(self) -> None:
+ super().__init__(_SLACK_RETRY_DEADLINE_MESSAGE)
+
+
+class SlackChannelResponseError(SlackRequestError):
+ """Slack returned malformed channel-specific data before a terminal
write."""
+
+
+_SLACK_RETRY_ERRORS = (SlackApiError, *SLACK_TRANSIENT_TRANSPORT_ERRORS)
Review Comment:
`HTTPError` raised by the external upload step (and by `call_slack_api`’s
429 loop) is not included in `_SLACK_RETRY_ERRORS` / `_SLACK_CHANNEL_FAILURES`,
so a non-429 upload HTTP error (e.g. 5xx) won’t be retried/aggregated and can
escape as a raw exception, bypassing the `_send` SupersetException handling and
stopping later recipients. Include `HTTPError` in the retry/failure tuples so
it’s classified and handled consistently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]