From 34abbaf2acbc35d8886f3e8b59169e6cc35e0286 Mon Sep 17 00:00:00 2001 From: Adam Ling Date: Wed, 7 Aug 2024 13:41:51 -0700 Subject: [PATCH] SNOW-1563453: remove oob telemetry usage in connector (#2014) --- src/snowflake/connector/connection.py | 8 --- src/snowflake/connector/errors.py | 6 --- src/snowflake/connector/network.py | 64 ----------------------- src/snowflake/connector/ocsp_snowflake.py | 11 ---- 4 files changed, 89 deletions(-) diff --git a/src/snowflake/connector/connection.py b/src/snowflake/connector/connection.py index 4bedc3039..b581bcfe7 100644 --- a/src/snowflake/connector/connection.py +++ b/src/snowflake/connector/connection.py @@ -61,7 +61,6 @@ PARAMETER_CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY, PARAMETER_CLIENT_STORE_TEMPORARY_CREDENTIAL, PARAMETER_CLIENT_TELEMETRY_ENABLED, - PARAMETER_CLIENT_TELEMETRY_OOB_ENABLED, PARAMETER_CLIENT_VALIDATE_DEFAULT_PARAMETERS, PARAMETER_ENABLE_STAGE_S3_PRIVATELINK_FOR_US_EAST_1, PARAMETER_QUERY_CONTEXT_CACHE_SIZE, @@ -106,7 +105,6 @@ ) from .sqlstate import SQLSTATE_CONNECTION_NOT_EXISTS, SQLSTATE_FEATURE_NOT_SUPPORTED from .telemetry import TelemetryClient, TelemetryData, TelemetryField -from .telemetry_oob import TelemetryService from .time_util import HeartBeatTimer, get_time_millis from .url_util import extract_top_level_domain_from_hostname from .util_text import construct_hostname, parse_account, split_statements @@ -720,7 +718,6 @@ def connect(self, **kwargs) -> None: logger.debug("connect") if len(kwargs) > 0: self.__config(**kwargs) - TelemetryService.get_instance().update_context(kwargs) if self.enable_connection_diag: exceptions_dict = {} @@ -1718,11 +1715,6 @@ def _update_parameters( self._session_parameters[name] = value if PARAMETER_CLIENT_TELEMETRY_ENABLED == name: self.telemetry_enabled = value - elif PARAMETER_CLIENT_TELEMETRY_OOB_ENABLED == name: - if value: - TelemetryService.get_instance().enable() - else: - TelemetryService.get_instance().disable() elif PARAMETER_CLIENT_SESSION_KEEP_ALIVE == name: # Only set if the local config is None. # Always give preference to user config. diff --git a/src/snowflake/connector/errors.py b/src/snowflake/connector/errors.py index 8a0600546..9c262cc4b 100644 --- a/src/snowflake/connector/errors.py +++ b/src/snowflake/connector/errors.py @@ -15,7 +15,6 @@ from .compat import BASE_EXCEPTION_CLASS from .secret_detector import SecretDetector from .telemetry import TelemetryData, TelemetryField -from .telemetry_oob import TelemetryService from .time_util import get_time_millis if TYPE_CHECKING: # pragma: no cover @@ -167,11 +166,6 @@ def send_exception_telemetry( ) except AttributeError: logger.debug("Cursor failed to log to telemetry.", exc_info=True) - elif connection is None: - # Send with out-of-band telemetry - - telemetry_oob = TelemetryService.get_instance() - telemetry_oob.log_general_exception(self.__class__.__name__, telemetry_data) def exception_telemetry( self, diff --git a/src/snowflake/connector/network.py b/src/snowflake/connector/network.py index f6fef6594..81fe6d29c 100644 --- a/src/snowflake/connector/network.py +++ b/src/snowflake/connector/network.py @@ -13,7 +13,6 @@ import logging import re import time -import traceback import uuid from collections import OrderedDict from threading import Lock @@ -92,9 +91,7 @@ SQLSTATE_CONNECTION_NOT_EXISTS, SQLSTATE_CONNECTION_REJECTED, SQLSTATE_CONNECTION_WAS_NOT_ESTABLISHED, - SQLSTATE_IO_ERROR, ) -from .telemetry_oob import TelemetryService from .time_util import ( DEFAULT_MASTER_VALIDITY_IN_SECONDS, TimeoutBackoffCtx, @@ -230,14 +227,6 @@ def raise_failed_request_error( method: str, response: Response, ) -> None: - TelemetryService.get_instance().log_http_request_error( - f"HttpError{response.status_code}", - url, - method, - SQLSTATE_CONNECTION_WAS_NOT_ESTABLISHED, - ER_FAILED_TO_REQUEST, - response=response, - ) Error.errorhandler_wrapper( connection, None, @@ -902,32 +891,8 @@ def _request_exec_wrapper( if return_object is not None: return return_object self._handle_unknown_error(method, full_url, headers, data, conn) - TelemetryService.get_instance().log_http_request_error( - "HttpRequestUnknownError", - full_url, - method, - SQLSTATE_IO_ERROR, - ER_FAILED_TO_REQUEST, - retry_timeout=retry_ctx.timeout, - retry_count=retry_ctx.current_retry_count, - ) return {} except RetryRequest as e: - if ( - retry_ctx.current_retry_count - == TelemetryService.get_instance().num_of_retry_to_trigger_telemetry - ): - TelemetryService.get_instance().log_http_request_error( - "HttpRequestRetry%dTimes" % retry_ctx.current_retry_count, - full_url, - method, - SQLSTATE_IO_ERROR, - ER_FAILED_TO_REQUEST, - retry_timeout=retry_ctx.timeout, - retry_count=retry_ctx.current_retry_count, - exception=str(e), - stack_trace=traceback.format_exc(), - ) cause = e.args[0] if no_retry: self.log_and_handle_http_error_with_cause( @@ -1001,17 +966,6 @@ def log_and_handle_http_error_with_cause( ) -> None: cause = e.args[0] logger.error(cause, exc_info=True) - TelemetryService.get_instance().log_http_request_error( - "HttpRequestRetryTimeout" if timed_out else f"HttpRequestError: {cause}", - full_url, - method, - SQLSTATE_IO_ERROR, - ER_FAILED_TO_REQUEST, - retry_timeout=retry_timeout, - retry_count=retry_count, - exception=str(e), - stack_trace=traceback.format_exc(), - ) if isinstance(cause, Error): Error.errorhandler_wrapper_from_cause(conn, cause) else: @@ -1149,15 +1103,6 @@ def _request_exec( raw_ret.close() # ensure response is closed except SSLError as se: logger.debug("Hit non-retryable SSL error, %s", str(se)) - TelemetryService.get_instance().log_http_request_error( - "CertificateException%s" % str(se), - full_url, - method, - SQLSTATE_CONNECTION_WAS_NOT_ESTABLISHED, - ER_FAILED_TO_REQUEST, - exception=se, - stack_trace=traceback.format_exc(), - ) except ( BadStatusLine, @@ -1190,15 +1135,6 @@ def _request_exec( ) raise RetryRequest(err) except Exception as err: - TelemetryService.get_instance().log_http_request_error( - "HttpException%s" % str(err), - full_url, - method, - SQLSTATE_CONNECTION_WAS_NOT_ESTABLISHED, - ER_FAILED_TO_REQUEST, - exception=err, - stack_trace=traceback.format_exc(), - ) raise err def make_requests_session(self) -> Session: diff --git a/src/snowflake/connector/ocsp_snowflake.py b/src/snowflake/connector/ocsp_snowflake.py index caddf2bb5..253e15ab9 100644 --- a/src/snowflake/connector/ocsp_snowflake.py +++ b/src/snowflake/connector/ocsp_snowflake.py @@ -13,7 +13,6 @@ import sys import tempfile import time -import traceback from base64 import b64decode, b64encode from datetime import datetime, timezone from logging import getLogger @@ -56,7 +55,6 @@ ) from snowflake.connector.errors import RevocationCheckError from snowflake.connector.network import PYTHON_CONNECTOR_USER_AGENT -from snowflake.connector.telemetry_oob import TelemetryService from . import constants from .backoff_policies import exponential_backoff @@ -250,15 +248,6 @@ def generate_telemetry_data( is_oob_telemetry=True, ) - telemetry_client = TelemetryService.get_instance() - telemetry_client.log_ocsp_exception( - event_type, - telemetry_data, - exception=str(exception), - stack_trace=traceback.format_exc(), - urgent=urgent, - ) - return telemetry_data # To be updated once Python Driver has out of band telemetry. # telemetry_client = TelemetryClient()