Loading src/common/method_wrappers/Decorator.py +23 −0 Original line number Diff line number Diff line Loading @@ -25,12 +25,14 @@ class MetricTypeEnum(Enum): COUNTER_STARTED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_started' COUNTER_COMPLETED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_completed' COUNTER_FAILED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_failed' COUNTER_BLOCKED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_blocked' HISTOGRAM_DURATION = 'tfs_{component:s}_{sub_module:s}_{method:s}_histogram_duration' METRIC_TO_CLASS_PARAMS = { MetricTypeEnum.COUNTER_STARTED : (Counter, {}), MetricTypeEnum.COUNTER_COMPLETED : (Counter, {}), MetricTypeEnum.COUNTER_FAILED : (Counter, {}), MetricTypeEnum.COUNTER_BLOCKED : (Counter, {}), MetricTypeEnum.HISTOGRAM_DURATION: (Histogram, { 'buckets': ( # .005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, INF Loading Loading @@ -93,6 +95,27 @@ class MetricsPool: return histogram_duration, counter_started, counter_completed, counter_failed def get_metrics_loadgen( self, method : str, labels : Optional[Dict[str, str]] = None ) -> Tuple[Histogram, Counter, Counter, Counter, Counter]: histogram_duration : Histogram = self.get_or_create(method, MetricTypeEnum.HISTOGRAM_DURATION) counter_started : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_STARTED) counter_completed : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_COMPLETED) counter_failed : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_FAILED) counter_blocked : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_BLOCKED) if labels is None and len(self._labels) > 0: labels = self._labels if labels is not None and len(labels) > 0: histogram_duration = histogram_duration.labels(**labels) counter_started = counter_started.labels(**labels) counter_completed = counter_completed.labels(**labels) counter_failed = counter_failed.labels(**labels) counter_blocked = counter_blocked.labels(**labels) return histogram_duration, counter_started, counter_completed, counter_failed, counter_blocked def get_pretty_table(self, remove_empty_buckets : bool = True) -> PrettyTable: with MetricsPool.lock: method_to_metric_fields : Dict[str, Dict[str, Dict[str, Any]]] = dict() Loading Loading
src/common/method_wrappers/Decorator.py +23 −0 Original line number Diff line number Diff line Loading @@ -25,12 +25,14 @@ class MetricTypeEnum(Enum): COUNTER_STARTED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_started' COUNTER_COMPLETED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_completed' COUNTER_FAILED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_failed' COUNTER_BLOCKED = 'tfs_{component:s}_{sub_module:s}_{method:s}_counter_requests_blocked' HISTOGRAM_DURATION = 'tfs_{component:s}_{sub_module:s}_{method:s}_histogram_duration' METRIC_TO_CLASS_PARAMS = { MetricTypeEnum.COUNTER_STARTED : (Counter, {}), MetricTypeEnum.COUNTER_COMPLETED : (Counter, {}), MetricTypeEnum.COUNTER_FAILED : (Counter, {}), MetricTypeEnum.COUNTER_BLOCKED : (Counter, {}), MetricTypeEnum.HISTOGRAM_DURATION: (Histogram, { 'buckets': ( # .005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, INF Loading Loading @@ -93,6 +95,27 @@ class MetricsPool: return histogram_duration, counter_started, counter_completed, counter_failed def get_metrics_loadgen( self, method : str, labels : Optional[Dict[str, str]] = None ) -> Tuple[Histogram, Counter, Counter, Counter, Counter]: histogram_duration : Histogram = self.get_or_create(method, MetricTypeEnum.HISTOGRAM_DURATION) counter_started : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_STARTED) counter_completed : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_COMPLETED) counter_failed : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_FAILED) counter_blocked : Counter = self.get_or_create(method, MetricTypeEnum.COUNTER_BLOCKED) if labels is None and len(self._labels) > 0: labels = self._labels if labels is not None and len(labels) > 0: histogram_duration = histogram_duration.labels(**labels) counter_started = counter_started.labels(**labels) counter_completed = counter_completed.labels(**labels) counter_failed = counter_failed.labels(**labels) counter_blocked = counter_blocked.labels(**labels) return histogram_duration, counter_started, counter_completed, counter_failed, counter_blocked def get_pretty_table(self, remove_empty_buckets : bool = True) -> PrettyTable: with MetricsPool.lock: method_to_metric_fields : Dict[str, Dict[str, Dict[str, Any]]] = dict() Loading