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

Improve tracking failure handling (#1063) #1445

Merged
merged 2 commits into from
May 9, 2019
Merged
Changes from 1 commit
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
31 changes: 30 additions & 1 deletion core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytz
import platform
import uuid
import requests
import yaml
import os

Expand All @@ -25,7 +26,35 @@

DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'

emitter = Emitter(COLLECTOR_URL, protocol=COLLECTOR_PROTOCOL, buffer_size=1)

class TimeoutEmitter(Emitter):
def __init__(self):
super(TimeoutEmitter, self).__init__(COLLECTOR_URL,
protocol=COLLECTOR_PROTOCOL,
buffer_size=1,
on_failure=self.handle_failure)

@staticmethod
def handle_failure(num_ok, unsent):
# num_ok will always be 0, unsent will always be 1 entry long, because
# the buffer is length 1, so not much to talk about
logger.warning('Error sending message, disabling tracking')
do_not_track()

def http_get(self, payload):
sp_logger.info("Sending GET request to %s..." % self.endpoint)
sp_logger.debug("Payload: %s" % payload)
r = requests.get(self.endpoint, params=payload, timeout=1.0)
beckjake marked this conversation as resolved.
Show resolved Hide resolved

msg = "GET request finished with status code: " + str(r.status_code)
if self.is_good_status_code(r.status_code):
sp_logger.info(msg)
else:
sp_logger.warn(msg)
return r


emitter = TimeoutEmitter()
tracker = Tracker(emitter, namespace="cf", app_id="dbt")

active_user = None
Expand Down