Skip to content

Commit

Permalink
Merge pull request #234 from analyst-collective/feature/track_dbt_env…
Browse files Browse the repository at this point in the history
…ironment

Feature/track dbt environment
  • Loading branch information
drewbanin authored Dec 7, 2016
2 parents 338bdd9 + c8ba6e8 commit e5e0650
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
23 changes: 20 additions & 3 deletions dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
INVOCATION_SPEC = "https://raw.githubusercontent.com/analyst-collective/dbt/master/events/schemas/com.fishtownanalytics/invocation_event.json"
PLATFORM_SPEC = "https://raw.githubusercontent.com/analyst-collective/dbt/master/events/schemas/com.fishtownanalytics/platform_context.json"
RUN_MODEL_SPEC = "https://raw.githubusercontent.com/analyst-collective/dbt/master/events/schemas/com.fishtownanalytics/run_model_context.json"
INVOCATION_ENV_SPEC = "https://raw.githubusercontent.com/analyst-collective/dbt/feature/track_dbt_environment/events/schemas/com.fishtownanalytics/invocation_env_context.json"

DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'

emitter = Emitter(COLLECTOR_URL, protocol=COLLECTOR_PROTOCOL, buffer_size=1)
tracker = Tracker(emitter, namespace="cf", app_id="dbt")
Expand Down Expand Up @@ -124,8 +127,22 @@ def get_platform_context():

return SelfDescribingJson(PLATFORM_SPEC, data)

def get_dbt_env_context():
default = 'manual'

dbt_invocation_env = os.getenv(DBT_INVOCATION_ENV, default)
if dbt_invocation_env == '':
dbt_invocation_env = default

data = {
"environment" : dbt_invocation_env,
}

return SelfDescribingJson(INVOCATION_ENV_SPEC, data)

invocation_id = str(uuid.uuid4())
platform_context = get_platform_context()
env_context = get_dbt_env_context()

user = get_user()
subject = Subject()
Expand All @@ -146,7 +163,7 @@ def track(*args, **kwargs):

def track_invocation_start(project=None, args=None):
invocation_context = get_invocation_start_context(invocation_id, user, project, args)
context = [invocation_context, platform_context]
context = [invocation_context, platform_context, env_context]
track(category="dbt", action='invocation', label='start', context=context)

def track_model_run(options):
Expand All @@ -156,12 +173,12 @@ def track_model_run(options):

def track_invocation_end(project=None, args=None, result_type=None, result=None):
invocation_context = get_invocation_end_context(invocation_id, user, project, args, result_type, result)
context = [invocation_context, platform_context]
context = [invocation_context, platform_context, env_context]
track(category="dbt", action='invocation', label='end', context=context)

def track_invalid_invocation(project=None, args=None, result_type=None, result=None):
invocation_context = get_invocation_invalid_context(invocation_id, user, project, args, result_type, result)
context = [invocation_context, platform_context]
context = [invocation_context, platform_context, env_context]
track(category="dbt", action='invocation', label='invalid', context=context)

def flush():
Expand Down
10 changes: 10 additions & 0 deletions events/schemas/com.fishtownanalytics/invocation_env_context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "object",
"title": "invocation_env",
"description": "DBT invocation environment type",
"properties": {
"environment": {
"type": "string"
}
}
}
2 changes: 1 addition & 1 deletion test/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ if [ $# = 0 ]; then
tox
else
echo "Running specified tests"
nosetests -v --nocapture --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov $@
DBT_INVOCATION_ENV="ci-local" nosetests -v --nocapture --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov $@
fi
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
envlist = py27, py35

[testenv]
commands = /bin/bash -c 'HOME=/root/ {envpython} $(which nosetests) -v --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov test/unit test/integration/*'
commands = /bin/bash -c 'HOME=/root/ DBT_INVOCATION_ENV=ci-circle {envpython} $(which nosetests) -v --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov test/unit test/integration/*'
deps =
-rrequirements.txt
-rdev_requirements.txt
Expand All @@ -17,6 +17,7 @@ deps =
basepython = {env:PYTHON:}\python.exe
setenv =
DBT_CONFIG_DIR = ~/.dbt
DBT_INVOCATION_ENV = ci-appveyor
commands = nosetests -v --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov test/unit test/integration/
deps =
-rrequirements.txt
Expand Down

0 comments on commit e5e0650

Please sign in to comment.