MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / VortexSynchronousSender

Class VortexSynchronousSender

mssqlcli/telemetry_upload.py:34–70  ·  view source on GitHub ↗

A Synchronous sender specific to the Vortex service with limited retry logic.

Source from the content-addressed store, hash-verified

32
33
34class VortexSynchronousSender(SynchronousSender):
35 """
36 A Synchronous sender specific to the Vortex service with limited retry logic.
37 """
38 def __init__(self, service_endpoint_uri='https://vortex.data.microsoft.com/collect/v1'):
39 SynchronousSender.__init__(self, service_endpoint_uri)
40 self.retry = 0
41
42 def send(self, data_to_send):
43 """
44 Override the send method to strip the request_payload's brackets since Vortex does not.
45 """
46 request_payload = json.dumps([a.write() for a in data_to_send]).strip('[').strip(']')
47
48 request = HTTPClient.Request(self._service_endpoint_uri,
49 bytearray(request_payload, 'utf-8'),
50 {'Accept': 'application/json',
51 'Content-Type': 'application/json; charset=utf-8'})
52 try:
53 response = HTTPClient.urlopen(request, timeout=self._timeout)
54 status_code = response.getcode()
55 if 200 <= status_code < 300:
56 if in_diagnostic_mode():
57 print('Telemetry uploaded succesfully.')
58 return
59 except HTTPError as e:
60 if e.getcode() == 400:
61 raise e
62 except (AttributeError, ValueError, URLError):
63 if self.retry < 3:
64 self.retry += 1
65 else:
66 return
67
68 # Add our unsent data back on to the queue
69 for data in data_to_send:
70 self._queue.put(data)
71
72
73class VortexTelemetryChannel(TelemetryChannel):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected