Skip to content

Commit edf2314

Browse files
authored
Chore: Revamp anonymous usage stats (#62)
1 parent d1d12d6 commit edf2314

File tree

17 files changed

+620
-299
lines changed

17 files changed

+620
-299
lines changed

airbyte/_executor.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from airbyte import exceptions as exc
1616
from airbyte.registry import ConnectorMetadata
17-
from airbyte.telemetry import SourceTelemetryInfo, SourceType
1817

1918

2019
if TYPE_CHECKING:
@@ -64,10 +63,6 @@ def ensure_installation(self, *, auto_fix: bool = True) -> None:
6463
def install(self) -> None:
6564
pass
6665

67-
@abstractmethod
68-
def _get_telemetry_info(self) -> SourceTelemetryInfo:
69-
pass
70-
7166
@abstractmethod
7267
def uninstall(self) -> None:
7368
pass
@@ -388,13 +383,6 @@ def execute(self, args: list[str]) -> Iterator[str]:
388383
with _stream_from_subprocess([str(connector_path), *args]) as stream:
389384
yield from stream
390385

391-
def _get_telemetry_info(self) -> SourceTelemetryInfo:
392-
return SourceTelemetryInfo(
393-
name=self.name,
394-
type=SourceType.VENV,
395-
version=self.reported_version,
396-
)
397-
398386

399387
class PathExecutor(Executor):
400388
def __init__(
@@ -448,10 +436,3 @@ def uninstall(self) -> NoReturn:
448436
def execute(self, args: list[str]) -> Iterator[str]:
449437
with _stream_from_subprocess([str(self.path), *args]) as stream:
450438
yield from stream
451-
452-
def _get_telemetry_info(self) -> SourceTelemetryInfo:
453-
return SourceTelemetryInfo(
454-
str(self.name),
455-
SourceType.LOCAL_INSTALL,
456-
version=self.reported_version,
457-
)

airbyte/_processors/sql/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from __future__ import annotations
55

6-
import abc
76
import enum
87
from contextlib import contextmanager
98
from functools import cached_property
@@ -53,7 +52,6 @@
5352
)
5453

5554
from airbyte.caches.base import CacheBase
56-
from airbyte.telemetry import CacheTelemetryInfo
5755

5856

5957
DEBUG_MODE = False # Set to True to enable additional debug logging.
@@ -908,7 +906,3 @@ def _table_exists(
908906
Subclasses may override this method to provide a more efficient implementation.
909907
"""
910908
return table_name in self._get_tables_list()
911-
912-
@abc.abstractmethod
913-
def _get_telemetry_info(self) -> CacheTelemetryInfo:
914-
pass

airbyte/_processors/sql/bigquery.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from airbyte import exceptions as exc
1616
from airbyte._processors.file.jsonl import JsonlWriter
1717
from airbyte._processors.sql.base import SqlProcessorBase
18-
from airbyte.telemetry import CacheTelemetryInfo
1918
from airbyte.types import SQLTypeConverter
2019

2120

@@ -79,11 +78,6 @@ def _quote_identifier(self, identifier: str) -> str:
7978
"""Return the identifier name as is. BigQuery does not require quoting identifiers"""
8079
return f"{identifier}"
8180

82-
@final
83-
@overrides
84-
def _get_telemetry_info(self) -> CacheTelemetryInfo:
85-
return CacheTelemetryInfo("bigquery")
86-
8781
def _write_files_to_new_table(
8882
self,
8983
files: list[Path],

airbyte/_processors/sql/duckdb.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from airbyte._processors.file import JsonlWriter
1414
from airbyte._processors.sql.base import SqlProcessorBase
15-
from airbyte.telemetry import CacheTelemetryInfo
1615

1716

1817
if TYPE_CHECKING:
@@ -123,7 +122,3 @@ def _write_files_to_new_table(
123122
)
124123
self._execute_sql(insert_statement)
125124
return temp_table_name
126-
127-
@overrides
128-
def _get_telemetry_info(self) -> CacheTelemetryInfo:
129-
return CacheTelemetryInfo("duckdb")

airbyte/_processors/sql/postgres.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
from __future__ import annotations
55

6-
from overrides import overrides
7-
86
from airbyte._processors.file import JsonlWriter
97
from airbyte._processors.sql.base import SqlProcessorBase
10-
from airbyte.telemetry import CacheTelemetryInfo
118

129

1310
class PostgresSqlProcessor(SqlProcessorBase):
@@ -23,7 +20,3 @@ class PostgresSqlProcessor(SqlProcessorBase):
2320

2421
file_writer_class = JsonlWriter
2522
supports_merge_insert = False # TODO: Add native implementation for merge insert
26-
27-
@overrides
28-
def _get_telemetry_info(self) -> CacheTelemetryInfo:
29-
return CacheTelemetryInfo("postgres")

airbyte/_processors/sql/snowflake.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from airbyte._processors.file.jsonl import JsonlWriter
1414
from airbyte._processors.sql.base import SqlProcessorBase
15-
from airbyte.telemetry import CacheTelemetryInfo
1615
from airbyte.types import SQLTypeConverter
1716

1817

@@ -42,11 +41,8 @@ def to_sql_type(
4241
return sql_type
4342

4443

45-
class SnowflakeSQLSqlProcessor(SqlProcessorBase):
46-
"""A Snowflake implementation of the cache.
47-
48-
Parquet is used for local file storage before bulk loading.
49-
"""
44+
class SnowflakeSqlProcessor(SqlProcessorBase):
45+
"""A Snowflake implementation of the cache."""
5046

5147
file_writer_class = JsonlWriter
5248
type_converter_class = SnowflakeTypeConverter
@@ -114,7 +110,3 @@ def _init_connection_settings(self, connection: Connection) -> None:
114110
MULTI_STATEMENT_COUNT = 0
115111
"""
116112
)
117-
118-
@overrides
119-
def _get_telemetry_info(self) -> CacheTelemetryInfo:
120-
return CacheTelemetryInfo("snowflake")

airbyte/_util/meta.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
"""Environment meta utils and globals.
3+
4+
This module contains functions for detecting environment and runtime information.
5+
"""
6+
from __future__ import annotations
7+
8+
import os
9+
import sys
10+
from contextlib import suppress
11+
from functools import lru_cache
12+
from pathlib import Path
13+
from platform import python_implementation, python_version, system
14+
15+
import requests
16+
17+
18+
COLAB_SESSION_URL = "http://172.28.0.12:9000/api/sessions"
19+
"""URL to get the current Google Colab session information."""
20+
21+
22+
def get_colab_release_version() -> str | None:
23+
if "COLAB_RELEASE_TAG" in os.environ:
24+
return os.environ["COLAB_RELEASE_TAG"]
25+
26+
return None
27+
28+
29+
def is_ci() -> bool:
30+
return "CI" in os.environ
31+
32+
33+
@lru_cache
34+
def is_colab() -> bool:
35+
return bool(get_colab_release_version())
36+
37+
38+
@lru_cache
39+
def is_jupyter() -> bool:
40+
"""Return True if running in a Jupyter notebook or qtconsole.
41+
42+
Will return False in Colab (use is_colab() instead).
43+
"""
44+
try:
45+
shell = get_ipython().__class__.__name__ # type: ignore # noqa: PGH003
46+
except NameError:
47+
return False # If 'get_ipython' undefined, we're probably in a standard Python interpreter.
48+
49+
if shell == "ZMQInteractiveShell":
50+
return True # Jupyter notebook or qtconsole.
51+
52+
if shell == "TerminalInteractiveShell":
53+
return False # Terminal running IPython
54+
55+
return False # Other type (?)
56+
57+
58+
@lru_cache
59+
def get_notebook_name() -> str | None:
60+
if is_colab():
61+
session_info = None
62+
response = None
63+
with suppress(Exception):
64+
response = requests.get(COLAB_SESSION_URL)
65+
if response.status_code == 200: # noqa: PLR2004 # Magic number
66+
session_info = response.json()
67+
68+
if session_info and "name" in session_info:
69+
return session_info["name"]
70+
71+
return None
72+
73+
74+
@lru_cache
75+
def get_vscode_notebook_name() -> str | None:
76+
with suppress(Exception):
77+
import IPython
78+
79+
return Path(
80+
IPython.extract_module_locals()[1]["__vsc_ipynb_file__"],
81+
).name
82+
83+
return None
84+
85+
86+
def is_vscode_notebook() -> bool:
87+
return get_vscode_notebook_name() is not None
88+
89+
90+
@lru_cache
91+
def get_python_script_name() -> str | None:
92+
script_name = None
93+
with suppress(Exception):
94+
script_name = sys.argv[0] # When running a python script, this is the script name.
95+
96+
if script_name:
97+
return Path(script_name).name
98+
99+
return None
100+
101+
102+
@lru_cache
103+
def get_application_name() -> str | None:
104+
return get_notebook_name() or get_python_script_name() or get_vscode_notebook_name() or None
105+
106+
107+
def get_python_version() -> str:
108+
return f"{python_version()} ({python_implementation()})"
109+
110+
111+
def get_os() -> str:
112+
if is_colab():
113+
return f"Google Colab ({get_colab_release_version()})"
114+
115+
return f"{system()}"

0 commit comments

Comments
 (0)