Skip to content

Commit

Permalink
Add AdapterRegistered event log message (#7862)
Browse files Browse the repository at this point in the history
* Add AdapterRegistered event log message

* Add AdapterRegistered to unit test

* make versioning and logging consistent

* make versioning and logging consistent

* add to_version_string

* remove extra equals

* format fire_event
  • Loading branch information
colin-rogers-dbt authored Jun 14, 2023
1 parent ae97831 commit f767943
Show file tree
Hide file tree
Showing 6 changed files with 908 additions and 868 deletions.
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 @@ -655,6 +655,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,737 changes: 871 additions & 866 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

0 comments on commit f767943

Please sign in to comment.