Skip to content

Commit

Permalink
Add some metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed May 17, 2024
1 parent 2eec594 commit d596dae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
15 changes: 12 additions & 3 deletions tests/commit_latency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import suite.test_requirements as reqs
from infra.log_capture import flush_info
from infra.tx_status import TxStatus
import infra.bencher

from loguru import logger as LOG

Expand Down Expand Up @@ -123,9 +124,17 @@ def run(args):
print_fn(f"Mean commit latency / sig_interval = {factor:.2f}")
factors.append(factor)

# https://github.com/microsoft/CCF/issues/6126
# with cimetrics.upload.metrics(complete=False) as metrics:
# metrics.put("Commit latency factor", statistics.mean(factors))
bf = infra.bencher.Bencher()
bf.set(
"commit_latency_ratio",
{
"latency": {
"value": statistics.mean(factors),
"high_value": max(factors),
"low_value": min(factors),
}
},
)


if __name__ == "__main__":
Expand Down
16 changes: 11 additions & 5 deletions tests/historical_query_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from infra.snp import IS_SNP
import infra.jwt_issuer
import time
import infra.bencher

from loguru import logger as LOG

Expand Down Expand Up @@ -187,14 +188,19 @@ def test_historical_query_range(network, args):
average_fetch_rate = (id_a_fetch_rate + id_b_fetch_rate + id_c_fetch_rate) / 3
LOG.info(f"Average fetch rate: {average_fetch_rate}")

# with cimetrics.upload.metrics(complete=False) as metrics:
# upload_name = "hist_sgx_cft^"
# LOG.debug(f"Uploading metric: {upload_name} = {average_fetch_rate}")
# metrics.put(upload_name, average_fetch_rate)

# NB: The similar test in e2e_logging checks correctness, so we make no duplicate
# assertions here

bf = infra.bencher.Bencher()
bf.set(
"historical_queries",
{
"throughput": {
"value": average_fetch_rate
}
},
)

return network


Expand Down
20 changes: 20 additions & 0 deletions tests/infra/bencher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.

import os
import json

BENCHER_FILE = "bencher.json"

class Bencher:
def __init__(self):
if not os.path.isfile(BENCHER_FILE):
with open(BENCHER_FILE, "w+") as bf:
json.dump({}, bf)

def set(self, key, value):
with open(BENCHER_FILE, "r") as bf:
data = json.load(bf)
data[key] = value
with open(BENCHER_FILE, "w") as bf:
json.dump(data, bf, indent=4)

0 comments on commit d596dae

Please sign in to comment.