Skip to content

Commit

Permalink
(#1574) track adapter type and rpc requests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed Jun 26, 2019
1 parent 31f2034 commit 22ebd69
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
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
21 changes: 21 additions & 0 deletions 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 @@ -23,6 +25,7 @@
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-0'

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
10 changes: 6 additions & 4 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 @@ -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

0 comments on commit 22ebd69

Please sign in to comment.