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

batch anonymous usage statistics calls #2089

Merged
merged 1 commit into from
Feb 4, 2020
Merged
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
45 changes: 36 additions & 9 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@

class TimeoutEmitter(Emitter):
def __init__(self):
super().__init__(COLLECTOR_URL, protocol=COLLECTOR_PROTOCOL,
buffer_size=1, on_failure=self.handle_failure)
super().__init__(
COLLECTOR_URL, protocol=COLLECTOR_PROTOCOL,
buffer_size=30, on_failure=self.handle_failure,
method='post',
# don't set this.
byte_limit=None,
)

@staticmethod
def handle_failure(num_ok, unsent):
Expand All @@ -41,21 +46,43 @@ def handle_failure(num_ok, unsent):
logger.warning('Error sending message, disabling tracking')
do_not_track()

def http_get(self, payload):
sp_logger.info("Sending GET request to {}...".format(self.endpoint))
sp_logger.debug("Payload: {}".format(payload))
r = requests.get(self.endpoint, params=payload, timeout=5.0)
def _log_request(self, request, payload):
sp_logger.info(f"Sending {request} request to {self.endpoint}...")
sp_logger.debug(f"Payload: {payload}")

msg = "GET request finished with status code: " + str(r.status_code)
if self.is_good_status_code(r.status_code):
def _log_result(self, request, status_code):
msg = f"{request} request finished with status code: {status_code}"
if self.is_good_status_code(status_code):
sp_logger.info(msg)
else:
sp_logger.warning(msg)

def http_post(self, payload):
self._log_request('POST', payload)

r = requests.post(
self.endpoint,
data=payload,
headers={'content-type': 'application/json; charset=utf-8'},
timeout=5.0
)

self._log_result('GET', r.status_code)
return r

def http_get(self, payload):
self._log_request('GET', payload)

r = requests.get(self.endpoint, params=payload, timeout=5.0)

self._log_result('GET', r.status_code)
return r


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


class User:
Expand Down