Skip to content

Commit

Permalink
JS metrics investigation and proposed fix (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou authored Jul 7, 2021
1 parent effeb77 commit eb3f966
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/endpoints/endpoint_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ namespace ccf::endpoints
EndpointRegistry::Metrics& EndpointRegistry::get_metrics_for_endpoint(
const EndpointDefinitionPtr& e)
{
return metrics[e->dispatch.uri_path][e->dispatch.verb.c_str()];
auto method = e->dispatch.uri_path;
method = method.substr(method.find_first_not_of('/'));
return metrics[method][e->dispatch.verb.c_str()];
}

Endpoint EndpointRegistry::make_endpoint(
Expand Down
32 changes: 26 additions & 6 deletions tests/e2e_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,18 @@ def test_raw_text(network, args):
def test_metrics(network, args):
primary, _ = network.find_primary()

def get_metrics(r, path, method):
return next(
v
for v in r.body.json()["metrics"]
if v["path"] == path and v["method"] == method
)
def get_metrics(r, path, method, default=None):
try:
return next(
v
for v in r.body.json()["metrics"]
if v["path"] == path and v["method"] == method
)
except StopIteration:
if default is None:
raise
else:
return default

calls = 0
errors = 0
Expand All @@ -580,6 +586,20 @@ def get_metrics(r, path, method):
r = c.get("/app/api/metrics")
assert get_metrics(r, "api/metrics", "GET")["errors"] == errors + 1

calls = 0
with primary.client("user0") as c:
r = c.get("/app/api/metrics")
calls = get_metrics(r, "log/public", "POST", {"calls": 0})["calls"]

network.txs.issue(
network=network,
number_txs=1,
)

with primary.client("user0") as c:
r = c.get("/app/api/metrics")
assert get_metrics(r, "log/public", "POST")["calls"] == calls + 1

return network


Expand Down

0 comments on commit eb3f966

Please sign in to comment.