Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport 7862 to 1.5.latest #7878

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230613-151507.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Add AdapterRegistered event log message
time: 2023-06-13T15:15:07.367371-07:00
custom:
Author: colin-rogers-dbt
Issue: "7038"
11 changes: 9 additions & 2 deletions core/dbt/adapters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from dbt.adapters.protocol import AdapterConfig, AdapterProtocol, RelationProtocol
from dbt.contracts.connection import AdapterRequiredConfig, Credentials
from dbt.events.functions import fire_event
from dbt.events.types import AdapterImportError, PluginLoadError
from dbt.events.types import AdapterImportError, PluginLoadError, AdapterRegistered
from dbt.exceptions import DbtInternalError, DbtRuntimeError
from dbt.include.global_project import PACKAGE_PATH as GLOBAL_PROJECT_PATH
from dbt.include.global_project import PROJECT_NAME as GLOBAL_PROJECT_NAME
from dbt.semver import VersionSpecifier

Adapter = AdapterProtocol

Expand Down Expand Up @@ -89,7 +90,13 @@ def load_plugin(self, name: str) -> Type[Credentials]:
def register_adapter(self, config: AdapterRequiredConfig) -> None:
adapter_name = config.credentials.type
adapter_type = self.get_adapter_class_by_name(adapter_name)

adapter_version = import_module(f".{adapter_name}.__version__", "dbt.adapters").version
adapter_version_specifier = VersionSpecifier.from_version_string(
adapter_version
).to_version_string()
fire_event(
AdapterRegistered(adapter_name=adapter_name, adapter_version=adapter_version_specifier)
)
with self.lock:
if adapter_name in self.adapters:
# this shouldn't really happen...
Expand Down
13 changes: 13 additions & 0 deletions core/dbt/events/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,19 @@ message CacheDumpGraphMsg {

// Skipping E032, E033, E034



// E034
message AdapterRegistered {
string adapter_name = 1;
string adapter_version = 2;
}

message AdapterRegisteredMsg {
EventInfo info = 1;
AdapterRegistered data = 2;
}

// E035
message AdapterImportError {
string exc = 1;
Expand Down
8 changes: 8 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ def message(self) -> str:
# Skipping E032, E033, E034


class AdapterRegistered(InfoLevel):
def code(self):
return "E034"

def message(self) -> str:
return f"Registered adapter: {self.adapter_name}{self.adapter_version}"


class AdapterImportError(InfoLevel):
def code(self):
return "E035"
Expand Down
1,242 changes: 623 additions & 619 deletions core/dbt/events/types_pb2.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def test_event_codes(self):
types.AdapterEventInfo(),
types.AdapterEventWarning(),
types.AdapterEventError(),
types.AdapterRegistered(adapter_name="dbt-awesome", adapter_version="1.2.3"),
types.NewConnection(conn_type="", conn_name=""),
types.ConnectionReused(conn_name=""),
types.ConnectionLeftOpenInCleanup(conn_name=""),
Expand Down