diff --git a/.gitignore b/.gitignore index 1bf9d06ee..60ac33eff 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,6 @@ doc/_build asab +# VSCode +.vscode/ + diff --git a/bspump/pipeline.py b/bspump/pipeline.py index c92a0c4b1..ef3b9a155 100644 --- a/bspump/pipeline.py +++ b/bspump/pipeline.py @@ -94,7 +94,7 @@ def __init__(self, app, id=None, config=None): self.ProfilerCounter = {} app.PubSub.subscribe( - "Application.Metrics.Flush!", + "Metrics.flush!", self._on_metrics_flush ) @@ -141,28 +141,28 @@ def get_throttles(self): :return: xxxx - """ + """ return self._throttles - def _on_metrics_flush(self, event_type, metric, values): + def _on_metrics_flush(self, event_type): """ Description: Pipeline is ... - Parameters: event_type, metric, values + Parameters: event_type :return: xxxx - """ - if metric != self.MetricsCounter: - return - if values["event.in"] == 0: - self.MetricsGauge.set("warning.ratio", 0.0) - self.MetricsGauge.set("error.ratio", 0.0) - return - self.MetricsGauge.set("warning.ratio", values["warning"] / values["event.in"]) - self.MetricsGauge.set("error.ratio", values["error"] / values["event.in"]) + """ + for field in self.MetricsCounter.Storage["fieldset"]: + values = field["values"] + if values["event.in"] == 0: + self.MetricsGauge.set("warning.ratio", 0.0) + self.MetricsGauge.set("error.ratio", 0.0) + continue + self.MetricsGauge.set("warning.ratio", values["warning"] / values["event.in"]) + self.MetricsGauge.set("error.ratio", values["error"] / values["event.in"]) def is_error(self): """ @@ -173,7 +173,7 @@ def is_error(self): :return: xxxx - """ + """ return self._error is not None def set_error(self, context, event, exc): @@ -710,7 +710,7 @@ def rest_get(self): 'Throttles': list(self._throttles), 'Sources': self.Sources, 'Processors': [], - 'Metrics': self.MetricsService.MemstorTarget, + 'Metrics': self.MetricsService.Storage.Metrics, 'Log': [record.__dict__ for record in self.L.Deque] } diff --git a/bspump/web/__init__.py b/bspump/web/__init__.py index 8414260ee..e9e7b5594 100644 --- a/bspump/web/__init__.py +++ b/bspump/web/__init__.py @@ -19,52 +19,6 @@ # -# TODO: Remove functions *_v0 after September 2020 -async def pipelines_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await pipelines(request) - - -async def example_trigger_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await example_trigger(request) - - -async def example_internal_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await example_internal(request) - - -async def lookup_list_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await lookup_list(request) - - -async def lookup_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await lookup(request) - - -async def lookup_meta_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await lookup_meta(request) - - -async def metric_list_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await metric_list(request) - - -async def metric_detail_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await metric_detail(request) - - -async def manifest_v0(request): - L.warning("This endpoint has been deprecated. Use /bspump/v1/endpoint instead.") - return await manifest(request) - - async def pipelines(request): app = request.app['app'] svc = app.get_service("bspump.PumpService") @@ -132,24 +86,6 @@ async def lookup(request): content_type="application/octet-stream") -async def metric_list(request): - app = request.app['app'] - svc = app.get_service("asab.MetricsService") - return asab.web.rest.json_response(request, svc.MemstorTarget) - - -async def metric_detail(request): - metric_id = request.match_info.get('metric_id') - app = request.app['app'] - svc = app.get_service("asab.MetricsService") - - metric = svc.Metrics.get(metric_id) - if metric is None: - raise aiohttp.web.HTTPNotFound() - - return asab.web.rest.json_response(request, metric) - - async def manifest(request): ''' $ curl http://localhost:8080/manifest?pretty=true @@ -208,9 +144,6 @@ def initialize_web(container): container.WebApp.router.add_get('/bspump/v1/lookup/{lookup_id}', lookup) container.WebApp.router.add_get('/bspump/v1/lookup/{lookup_id}/meta', lookup_meta) - container.WebApp.router.add_get('/bspump/v1/metric', metric_list) - container.WebApp.router.add_get('/bspump/v1/metric/{metric_id}', metric_detail) - container.WebApp.router.add_get('/bspump/v1/manifest', manifest) return container diff --git a/test/test_metrics_service.py b/test/test_metrics_service.py index 476909784..1ee8d52a8 100644 --- a/test/test_metrics_service.py +++ b/test/test_metrics_service.py @@ -39,6 +39,7 @@ def _on_finished(self, event_name, pipeline): class TestMetricsService(bspump.unittest.ProcessorTestCase): + # TODO: "Application.Metrics.Flush!" does not exist in asab anymore def _metric_flush(self, _, __, counter): if counter.get("error"):