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

track plugin.get_nodes #8336

Merged
merged 2 commits into from
Aug 10, 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/Under the Hood-20230809-094834.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: add tracking for plugin.get_nodes calls
time: 2023-08-09T09:48:34.819445-04:00
custom:
Author: michelleark
Issue: "8344"
10 changes: 10 additions & 0 deletions core/dbt/plugins/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dbt.exceptions import DbtRuntimeError
from dbt.plugins.contracts import PluginArtifacts
from dbt.plugins.manifest import PluginNodes
import dbt.tracking


def dbt_hook(func):
Expand Down Expand Up @@ -119,5 +120,14 @@ def get_nodes(self) -> PluginNodes:
all_plugin_nodes = PluginNodes()
for hook_method in self.hooks.get("get_nodes", []):
plugin_nodes = hook_method()
dbt.tracking.track_plugin_get_nodes(
{
"plugin_name": hook_method.__self__.name, # type: ignore
"num_model_nodes": len(plugin_nodes.models),
"num_model_packages": len(
{model.package_name for model in plugin_nodes.models.values()}
),
}
)
all_plugin_nodes.update(plugin_nodes)
return all_plugin_nodes
14 changes: 14 additions & 0 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
RPC_REQUEST_SPEC = "iglu:com.dbt/rpc_request/jsonschema/1-0-1"
RUNNABLE_TIMING = "iglu:com.dbt/runnable/jsonschema/1-0-0"
RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-3"
PLUGIN_GET_NODES = "iglu:com.dbt/plugin_get_nodes/jsonschema/1-0-0"


class TimeoutEmitter(Emitter):
Expand Down Expand Up @@ -409,6 +410,19 @@
)


def track_plugin_get_nodes(options):
context = [SelfDescribingJson(PLUGIN_GET_NODES, options)]
assert active_user is not None, "Cannot track plugin node info when active user is None"

Check warning on line 415 in core/dbt/tracking.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/tracking.py#L414-L415

Added lines #L414 - L415 were not covered by tests

track(

Check warning on line 417 in core/dbt/tracking.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/tracking.py#L417

Added line #L417 was not covered by tests
active_user,
category="dbt",
action="plugin_get_nodes",
label=get_invocation_id(),
context=context,
)


def track_runnable_timing(options):
context = [SelfDescribingJson(RUNNABLE_TIMING, options)]
assert active_user is not None, "Cannot track runnable info when active user is None"
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test_plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from unittest import mock

from dbt.exceptions import DbtRuntimeError
from dbt.plugins import PluginManager, dbtPlugin, dbt_hook
Expand Down Expand Up @@ -92,10 +93,21 @@ def test_plugin_manager_init_multiple_hooks(self, get_nodes_plugin, get_artifact
assert len(pm.hooks["get_manifest_artifacts"]) == 1
assert pm.hooks["get_manifest_artifacts"][0] == get_artifacts_plugin.get_manifest_artifacts

def test_get_nodes(self, get_nodes_plugins):
@mock.patch("dbt.tracking")
def test_get_nodes(self, tracking, get_nodes_plugins):
tracking.active_user = mock.Mock()
pm = PluginManager(plugins=get_nodes_plugins)

nodes = pm.get_nodes()

assert len(nodes.models) == 2
assert tracking.track_plugin_get_nodes.called_once_with(
{
"plugin_name": get_nodes_plugins[0].name,
"num_model_nodes": 2,
"num_model_packages": 1,
}
)

def test_get_manifest_artifact(self, get_artifacts_plugins):
pm = PluginManager(plugins=get_artifacts_plugins)
Expand Down
Loading