From d17c1b5b3472b9b17dd424577dfa023a8969d7af Mon Sep 17 00:00:00 2001 From: shiqizng <80276844+shiqizng@users.noreply.github.com> Date: Wed, 3 May 2023 09:37:23 -0400 Subject: [PATCH] tools: block generator data reporting (#5339) --- tools/block-generator/requirements.txt | 1 + tools/block-generator/runner/run.go | 5 +++ tools/block-generator/upload_metrics.py | 53 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tools/block-generator/requirements.txt create mode 100644 tools/block-generator/upload_metrics.py diff --git a/tools/block-generator/requirements.txt b/tools/block-generator/requirements.txt new file mode 100644 index 0000000000..829c2ea815 --- /dev/null +++ b/tools/block-generator/requirements.txt @@ -0,0 +1 @@ +datadog==0.45.0 \ No newline at end of file diff --git a/tools/block-generator/runner/run.go b/tools/block-generator/runner/run.go index 2792c94be7..2113b36a45 100644 --- a/tools/block-generator/runner/run.go +++ b/tools/block-generator/runner/run.go @@ -341,6 +341,11 @@ func (r *Args) runTest(report *os.File, metricsURL string, generatorURL string) return fmt.Errorf("problem collecting final metrics (%d / %s): %w", count, time.Since(start), err) } + // write scenario to report + scenario := path.Base(r.Path) + if _, err := report.WriteString(fmt.Sprintf("scenario:%s\n", scenario)); err != nil { + return fmt.Errorf("unable to write scenario to report: %w", err) + } // Collect results. durationStr := fmt.Sprintf("test_duration_seconds:%d\ntest_duration_actual_seconds:%f\n", uint64(r.RunDuration.Seconds()), diff --git a/tools/block-generator/upload_metrics.py b/tools/block-generator/upload_metrics.py new file mode 100644 index 0000000000..f623a0c55a --- /dev/null +++ b/tools/block-generator/upload_metrics.py @@ -0,0 +1,53 @@ +from datadog import initialize +from datadog import api +import os +import argparse + +parser = argparse.ArgumentParser(description="Upload performance metrics to Datadog") +parser.add_argument( + "-f", + "--perf-reports", + required=True, + action="store", + dest="files", + type=str, + nargs="*", + help="list of reports created by the block generator", +) +parser.add_argument( + "-c", + "--binary-version", + required=True, + help="Release version or the commit hash of the Conduit binary used during the performance test", +) +args = parser.parse_args() + + +def parse_report(report): + data = dict() + with open(report) as f: + for line in f: + tag, value = line.split(":") + data[tag] = value if tag == "scenario" else float(value) + return data + + +if __name__ == "__main__": + print("initializing datadog") + options = { + "api_key": os.getenv("DATADOG_API_KEY"), + "app_key": os.getenv("DATADOG_APP_KEY"), + } + initialize(**options) + for fp in args.files: + print(f"uploading metrics for {fp}") + data = parse_report(fp) + tags = [ + f"conduit_version:{args.binary_version}", + f'duration:{data["test_duration_seconds"]}s', + f'scenario:{data["scenario"]}', + ] + transactionsPerBlockAvgMetricName = "conduit.perf.transactions_per_second" + tps = data["final_overall_transactions_per_second"] + api.Metric.send(metric=transactionsPerBlockAvgMetricName, points=tps, tags=tags) + print("uploaded metrics")