Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Metrics fix after renovation #143

Merged
merged 5 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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