-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add performance stats and logging (#360)
- Loading branch information
1 parent
ddbf6f4
commit c5fea25
Showing
12 changed files
with
349 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
"""Connector info classes for PyAirbyte. | ||
Used for telemetry and logging. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import asdict, dataclass | ||
from typing import Any | ||
|
||
|
||
@dataclass | ||
class RuntimeInfoBase: | ||
def to_dict(self) -> dict[str, Any]: | ||
return {k: v for k, v in asdict(self).items() if v is not None} | ||
|
||
|
||
@dataclass | ||
class WriterRuntimeInfo(RuntimeInfoBase): | ||
type: str | ||
config_hash: str | None = None | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class ConnectorRuntimeInfo(RuntimeInfoBase): | ||
name: str | ||
executor_type: str | None = None | ||
version: str | None = None | ||
config_hash: str | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
"""Hashing utils for PyAirbyte.""" | ||
|
||
from __future__ import annotations | ||
|
||
import hashlib | ||
from collections.abc import Mapping | ||
|
||
|
||
HASH_SEED = "PyAirbyte:" | ||
"""Additional seed for randomizing one-way hashed strings.""" | ||
|
||
|
||
def one_way_hash( | ||
obj: Mapping | list | object, | ||
/, | ||
) -> str: | ||
"""Return a one-way hash of the given string. | ||
To ensure a unique domain of hashes, we prepend a seed to the string before hashing. | ||
""" | ||
string_to_hash: str | ||
if isinstance(obj, Mapping): | ||
# Recursively sort and convert nested dictionaries to tuples of key-value pairs | ||
string_to_hash = str(sorted((k, one_way_hash(v)) for k, v in obj.items())) | ||
|
||
elif isinstance(obj, list): | ||
# Recursively hash elements of the list | ||
string_to_hash = str([one_way_hash(item) for item in obj]) | ||
|
||
else: | ||
# Convert the object to a string | ||
string_to_hash = str(obj) | ||
|
||
return hashlib.sha256((HASH_SEED + str(string_to_hash)).encode()).hexdigest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.