Skip to content

Commit

Permalink
Merge pull request #143 from LibertyAces/fix/metrics
Browse files Browse the repository at this point in the history
WIP: Metrics fix after renovation
  • Loading branch information
eliska-n authored Jun 28, 2022
2 parents 95c9871 + d5f356f commit 281b5cf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 82 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ doc/_build

asab

# VSCode
.vscode/

30 changes: 15 additions & 15 deletions bspump/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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):
"""
Expand All @@ -173,7 +173,7 @@ def is_error(self):
:return: xxxx
"""
"""
return self._error is not None

def set_error(self, context, event, exc):
Expand Down Expand Up @@ -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]
}

Expand Down
67 changes: 0 additions & 67 deletions bspump/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions test/test_metrics_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 281b5cf

Please sign in to comment.