Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wigley committed Nov 18, 2020
1 parent 4edd98f commit f7c0c1c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
10 changes: 5 additions & 5 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time

import dbt.exceptions
import dbt.tracking
import dbt.flags as flags

from dbt.adapters.factory import (
Expand Down Expand Up @@ -49,9 +50,8 @@
from dbt.parser.sources import patch_sources
from dbt.ui import warning_tag
from dbt.version import __version__
from hologram import JsonSchemaMixin
import dbt.tracking

from hologram import JsonSchemaMixin

PARTIAL_PARSE_FILE_NAME = 'partial_parse.pickle'
PARSING_STATE = DbtProcessState('parsing')
Expand Down Expand Up @@ -155,9 +155,9 @@ def __init__(
is_partial_parse_enabled=self._partial_parse_enabled()
)

def track_loading_time(self):
def track_project_load(self):
invocation_id = dbt.tracking.active_user.invocation_id
dbt.tracking.track_loading_time({
dbt.tracking.track_project_load({
"invocation_id": invocation_id,
"project_id": self.root_project.hashed_name(),
"path_count": self._perf_info.path_count,
Expand Down Expand Up @@ -445,7 +445,7 @@ def load_all(
time.perf_counter() - start_load_all
)

loader.track_loading_time()
loader.track_project_load()

return manifest

Expand Down
4 changes: 2 additions & 2 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ def track_invocation_start(config=None, args=None):
)


def track_loading_time(options):
def track_project_load(options):
context = [SelfDescribingJson(LOAD_ALL_TIMING_SPEC, options)]
assert active_user is not None, \
'Cannot track project loading time when active user is None'

track(
active_user,
category='dbt',
action='load_all_timing',
action='load_project',
label=active_user.invocation_id,
context=context
)
Expand Down
74 changes: 74 additions & 0 deletions test/integration/033_event_tracking_test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ def run_event_test(
populated_contexts
)

def load_context(self):

def populate(project_id, user_id, invocation_id, version):
return [{
'schema': 'iglu:com.dbt/load_all_timing/jsonschema/1-0-0',
'data': {
'invocation_id': invocation_id,
'project_id': project_id,
'path_count': ANY,
'is_partial_parse_enabled': ANY,
'load_all_elapsed': ANY,
'parse_project_elapsed': ANY,
'patch_sources_elapsed': ANY,
'process_manifest_elapsed': ANY,
},
}]
return populate

def build_context(
self,
command,
Expand Down Expand Up @@ -205,6 +223,12 @@ def test__postgres_event_tracking_compile(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='invocation',
Expand All @@ -215,6 +239,7 @@ def test__postgres_event_tracking_compile(self):

expected_contexts = [
self.build_context('compile', 'start'),
self.load_context(),
self.build_context('compile', 'end', result_type='ok')
]

Expand Down Expand Up @@ -312,6 +337,12 @@ def seed_context(project_id, user_id, invocation_id, version):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand All @@ -328,6 +359,7 @@ def seed_context(project_id, user_id, invocation_id, version):

expected_contexts = [
self.build_context('seed', 'start'),
self.load_context(),
seed_context,
self.build_context('seed', 'end', result_type='ok')
]
Expand All @@ -343,6 +375,12 @@ def test__postgres_event_tracking_models(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand Down Expand Up @@ -371,6 +409,7 @@ def test__postgres_event_tracking_models(self):

expected_contexts = [
self.build_context('run', 'start'),
self.load_context(),
self.run_context(
hashed_contents='1e5789d34cddfbd5da47d7713aa9191c',
model_id='4fbacae0e1b69924b22964b457148fb8',
Expand Down Expand Up @@ -408,6 +447,12 @@ def test__postgres_event_tracking_model_error(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand All @@ -424,6 +469,7 @@ def test__postgres_event_tracking_model_error(self):

expected_contexts = [
self.build_context('run', 'start'),
self.load_context(),
self.run_context(
hashed_contents='4419e809ce0995d99026299e54266037',
model_id='576c3d4489593f00fad42b97c278641e',
Expand Down Expand Up @@ -454,6 +500,12 @@ def test__postgres_event_tracking_tests(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='invocation',
Expand All @@ -464,6 +516,7 @@ def test__postgres_event_tracking_tests(self):

expected_contexts = [
self.build_context('test', 'start'),
self.load_context(),
self.build_context('test', 'end', result_type='ok')
]

Expand Down Expand Up @@ -558,6 +611,12 @@ def test__postgres_event_tracking_unable_to_connect(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='invocation',
Expand All @@ -568,6 +627,7 @@ def test__postgres_event_tracking_unable_to_connect(self):

expected_contexts = [
self.build_context('run', 'start'),
self.load_context(),
self.build_context('run', 'end', result_type='error')
]

Expand Down Expand Up @@ -598,6 +658,12 @@ def test__postgres_event_tracking_snapshot(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand All @@ -615,6 +681,7 @@ def test__postgres_event_tracking_snapshot(self):
# the model here has a raw_sql that contains the schema, which changes
expected_contexts = [
self.build_context('snapshot', 'start'),
self.load_context(),
self.run_context(
hashed_contents=ANY,
model_id='820793a4def8d8a38d109a9709374849',
Expand Down Expand Up @@ -646,6 +713,12 @@ def test__postgres_event_tracking_catalog_generate(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY,
),
call(
category='dbt',
action='invocation',
Expand All @@ -656,6 +729,7 @@ def test__postgres_event_tracking_catalog_generate(self):

expected_contexts = [
self.build_context('generate', 'start'),
self.load_context(),
self.build_context('generate', 'end', result_type='ok')
]

Expand Down

0 comments on commit f7c0c1c

Please sign in to comment.