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

(#1574) track adapter type and rpc requests #1575

Merged
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
8 changes: 8 additions & 0 deletions core/dbt/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from dbt.logger import RPC_LOGGER as logger
from dbt.logger import add_queue_handler
import dbt.exceptions
import dbt.tracking


class RPCException(JSONRPCDispatchException):
Expand Down Expand Up @@ -58,6 +59,12 @@ def from_error(cls, err):
return cls(err.code, err.message, err.data, err.data.get('logs'))


def track_rpc_request(task):
dbt.tracking.track_rpc_request({
"task": task
})


def invalid_params(data):
return RPCException(
code=JSONRPCInvalidParams.CODE,
Expand Down Expand Up @@ -429,6 +436,7 @@ def handle(cls, http_request, task_manager):
except JSONRPCInvalidRequestException:
return JSONRPC20Response(error=JSONRPCInvalidRequest()._data)

track_rpc_request(request.method)
dispatcher = RequestDispatcher(
http_request,
request,
Expand Down
23 changes: 22 additions & 1 deletion core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from snowplow_tracker import SelfDescribingJson
from datetime import datetime

from dbt.adapters.factory import get_adapter

import pytz
import platform
import uuid
Expand All @@ -18,11 +20,12 @@
COLLECTOR_URL = "fishtownanalytics.sinter-collect.com"
COLLECTOR_PROTOCOL = "https"

INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-0'
INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-1'
PLATFORM_SPEC = 'iglu:com.dbt/platform/jsonschema/1-0-0'
RUN_MODEL_SPEC = 'iglu:com.dbt/run_model/jsonschema/1-0-1'
INVOCATION_ENV_SPEC = 'iglu:com.dbt/invocation_env/jsonschema/1-0-0'
PACKAGE_INSTALL_SPEC = 'iglu:com.dbt/package_install/jsonschema/1-0-0'
RPC_REQUEST_SPEC = 'iglu:com.dbt/rpc_request/jsonschema/1-0-1'

DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'

Expand Down Expand Up @@ -116,6 +119,11 @@ def get_run_type(args):


def get_invocation_context(user, config, args):
try:
adapter_type = get_adapter(config).type()
except Exception:
adapter_type = None

return {
"project_id": None if config is None else config.hashed_name(),
"user_id": user.id,
Expand All @@ -126,6 +134,7 @@ def get_invocation_context(user, config, args):
"version": str(dbt_version.installed),

"run_type": get_run_type(args),
"adapter_type": adapter_type,
}


Expand Down Expand Up @@ -233,6 +242,18 @@ def track_model_run(options):
)


def track_rpc_request(options):
context = [SelfDescribingJson(RPC_REQUEST_SPEC, options)]

track(
active_user,
category="dbt",
action='rpc_request',
label=active_user.invocation_id,
context=context
)


def track_package_install(options):
context = [SelfDescribingJson(PACKAGE_INSTALL_SPEC, options)]
track(
Expand Down
12 changes: 7 additions & 5 deletions test/integration/033_event_tracking_test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def build_context(
self,
command,
progress,
result_type=None
result_type=None,
adapter_type='postgres'
):

def populate(
Expand All @@ -103,7 +104,7 @@ def populate(
):
return [
{
'schema': 'iglu:com.dbt/invocation/jsonschema/1-0-0',
'schema': 'iglu:com.dbt/invocation/jsonschema/1-0-1',
'data': {
'project_id': project_id,
'user_id': user_id,
Expand All @@ -116,7 +117,8 @@ def populate(

'options': None, # TODO : Add options to compile cmd!
'result_type': result_type,
'result': None
'result': None,
'adapter_type': adapter_type
}
},
{
Expand Down Expand Up @@ -252,9 +254,9 @@ def test__event_tracking_deps(self):
]

expected_contexts = [
self.build_context('deps', 'start'),
self.build_context('deps', 'start', adapter_type=None),
package_context,
self.build_context('deps', 'end', result_type='ok')
self.build_context('deps', 'end', result_type='ok', adapter_type=None)
]

self.run_event_test(["deps"], expected_calls, expected_contexts)
Expand Down