|
7 | 7 | from splitio.models.events import Event, EventWrapper |
8 | 8 | from splitio.models.telemetry import get_latency_bucket_index, MethodExceptionsAndLatencies |
9 | 9 | from splitio.client import input_validator |
10 | | -from splitio.util import utctime_ms |
11 | | -from splitio.api.commons import get_current_epoch_time |
| 10 | +from splitio.util.time import get_current_epoch_time, utctime_ms |
12 | 11 |
|
13 | 12 | _LOGGER = logging.getLogger(__name__) |
14 | 13 |
|
@@ -124,7 +123,7 @@ def _make_evaluation(self, key, feature, attributes, method_name, metric_name): |
124 | 123 | except Exception: # pylint: disable=broad-except |
125 | 124 | _LOGGER.error('Error getting treatment for feature') |
126 | 125 | _LOGGER.debug('Error: ', exc_info=True) |
127 | | - self._telemetry_evaluation_producer.record_exception(method_name[4:]) |
| 126 | + self._telemetry_evaluation_producer.record_exception(self._get_method_constant(method_name[4:])) |
128 | 127 | try: |
129 | 128 | impression = self._build_impression( |
130 | 129 | matching_key, |
@@ -207,12 +206,12 @@ def _make_evaluations(self, key, features, attributes, method_name, metric_name) |
207 | 206 | _LOGGER.error('%s: An exception when trying to store ' |
208 | 207 | 'impressions.' % method_name) |
209 | 208 | _LOGGER.debug('Error: ', exc_info=True) |
210 | | - self._telemetry_evaluation_producer.record_exception(method_name[4:]) |
| 209 | + self._telemetry_evaluation_producer.record_exception(self._get_method_constant(method_name[4:])) |
211 | 210 |
|
212 | | - self._telemetry_evaluation_producer.record_latency(method_name[4:], get_current_epoch_time() - start) |
| 211 | + self._telemetry_evaluation_producer.record_latency(self._get_method_constant(method_name[4:]), get_current_epoch_time() - start) |
213 | 212 | return treatments |
214 | 213 | except Exception: # pylint: disable=broad-except |
215 | | - self._telemetry_evaluation_producer.record_exception(method_name[4:]) |
| 214 | + self._telemetry_evaluation_producer.record_exception(self._get_method_constant(method_name[4:])) |
216 | 215 | _LOGGER.error('Error getting treatment for features') |
217 | 216 | _LOGGER.debug('Error: ', exc_info=True) |
218 | 217 | return input_validator.generate_control_treatments(list(features), method_name) |
@@ -350,8 +349,8 @@ def _record_stats(self, impressions, start, operation, method_name=None): |
350 | 349 | end = get_current_epoch_time() |
351 | 350 | self._recorder.record_treatment_stats(impressions, get_latency_bucket_index(end - start), |
352 | 351 | operation) |
353 | | - if not method_name == None: |
354 | | - self._telemetry_evaluation_producer.record_latency(method_name[4:], end - start) |
| 352 | + if method_name is not None: |
| 353 | + self._telemetry_evaluation_producer.record_latency(self._get_method_constant(method_name[4:]), end - start) |
355 | 354 |
|
356 | 355 |
|
357 | 356 | def track(self, key, traffic_type, event_type, value=None, properties=None): |
@@ -413,10 +412,20 @@ def track(self, key, traffic_type, event_type, value=None, properties=None): |
413 | 412 | event=event, |
414 | 413 | size=size, |
415 | 414 | )]) |
416 | | - self._telemetry_evaluation_producer.record_latency(MethodExceptionsAndLatencies.TRACK.value, get_current_epoch_time() - start) |
| 415 | + self._telemetry_evaluation_producer.record_latency(MethodExceptionsAndLatencies.TRACK, get_current_epoch_time() - start) |
| 416 | + return return_flag |
417 | 417 | except Exception: # pylint: disable=broad-except |
418 | | - self._telemetry_evaluation_producer.record_exception(MethodExceptionsAndLatencies.TRACK.value) |
| 418 | + self._telemetry_evaluation_producer.record_exception(MethodExceptionsAndLatencies.TRACK) |
419 | 419 | _LOGGER.error('Error processing track event') |
420 | 420 | _LOGGER.debug('Error: ', exc_info=True) |
| 421 | + return False |
421 | 422 |
|
422 | | - return return_flag |
| 423 | + def _get_method_constant(self, method): |
| 424 | + if method == 'treatment': |
| 425 | + return MethodExceptionsAndLatencies.TREATMENT |
| 426 | + elif method == 'treatments': |
| 427 | + return MethodExceptionsAndLatencies.TREATMENTS |
| 428 | + elif method == 'treatment_with_config': |
| 429 | + return MethodExceptionsAndLatencies.TREATMENT_WITH_CONFIG |
| 430 | + elif method == 'treatments_with_config': |
| 431 | + return MethodExceptionsAndLatencies.TREATMENTS_WITH_CONFIG |
0 commit comments