From 263d18e7e21c292a3c8dbcada472168f5cf01239 Mon Sep 17 00:00:00 2001 From: jbajic Date: Thu, 8 Dec 2022 13:30:14 +0100 Subject: [PATCH] Add github action --- .github/workflows/diff.yaml | 39 ++++++++++++++++- tests/mgbench/format_json.py | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) create mode 100755 tests/mgbench/format_json.py diff --git a/.github/workflows/diff.yaml b/.github/workflows/diff.yaml index a7faa7d22..1003f37a2 100644 --- a/.github/workflows/diff.yaml +++ b/.github/workflows/diff.yaml @@ -73,7 +73,12 @@ jobs: # This is also needed if we want do to comparison against other branches # See https://github.community/t/checkout-code-fails-when-it-runs-lerna-run-test-since-master/17920 - name: Fetch all history for all tags and branches - run: git fetch + uses: nick-fields/retry@v2 + with: + timeout_minutes: 1 + max_attempts: 3 + shell: bash + command: git fetch - name: Initialize deps run: | @@ -261,7 +266,37 @@ jobs: # Run simulation tests. cd tests/mgbench - ./benchmark.py accesscontrol/small --num-workers-for-import 1 --test-system-arg "split-file splitfiles/accesscontrol_small.shard_configuration bolt-num-workers 1" + ./benchmark.py accesscontrol/small --num-workers-for-import 1 \ + --export-results=output_github_benchmark.json --test-system-arg \ + "split-file splitfiles/accesscontrol_small.shard_configuration bolt-num-workers 1" + + - name: Adapt benchmark results to benchmark github + run: ./tests/mgbench/format_json.py -i output_github_benchmark.json -o formatted_output_benchmark.json + + # Download previous benchmark result from cache (if exists) + - name: Download previous benchmark data + uses: actions/cache@v3 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + + # Run `github-action-benchmark` action + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: "customBiggerIsBetter" + # Where the output from the benchmark tool is stored + output-file-path: formatted_output_benchmark.json + # Where the previous data file is stored + external-data-json-path: ./cache/benchmark-data.json + # Workflow will fail when an alert happens + fail-on-alert: true + # GitHub API token to make a commit comment + github-token: ${{ secrets.GITHUB_TOKEN }} + # Enable alert commit comment + comment-on-alert: true + alert-threshold: "150%" - name: Run e2e tests run: | diff --git a/tests/mgbench/format_json.py b/tests/mgbench/format_json.py new file mode 100755 index 000000000..05b4bf44d --- /dev/null +++ b/tests/mgbench/format_json.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +# Copyright 2022 Memgraph Ltd. +# +# Use of this software is governed by the Business Source License +# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +# License, and you may not use this file except in compliance with the Business Source License. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0, included in the file +# licenses/APL.txt. + +import argparse +import json +from pathlib import Path +from typing import Any, Dict, List + + +def adapt_to_benchmark_action(data: Dict[str, Any]) -> List[Dict[str, Any]]: + output = [] + keys = list(data.keys()) + assert len(keys) == 1 + dataset_name = keys[0] + + dataset_keys = list(data[dataset_name]) + assert len(dataset_keys) == 1 + dataset_type = dataset_keys[0] + + for execution_type, execution_data in data[dataset_name][dataset_type].items(): + if execution_type == "__import__": + continue + for type, type_data in execution_data.items(): + assert "throughput" in type_data, f"There is no throughput in {type_data}!" + output.append( + { + "name": f"{dataset_name}_{dataset_type}_{execution_type}", + "unit": "QPS", + "value": type_data["throughput"], + } + ) + return output + + +ADAPTERS = { + "github_benchmark": adapt_to_benchmark_action, +} + + +def convert_input(input: Dict[str, Any], adapter: str) -> List[Dict[str, Any]]: + return ADAPTERS[adapter](input) + + +def parse_args(): + parser = argparse.ArgumentParser( + description="JSON adapter.", formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + parser.add_argument("-i", "--input", help="Input JSON file.") + parser.add_argument("-o", "--output", help="Output JSON file.") + parser.add_argument( + "--adapter", default="github_benchmark", choices=ADAPTERS.keys(), help="Adapter function to use." + ) + + return parser.parse_args() + + +def read_input(input: str) -> Dict[str, Any]: + with Path(input).open() as input_file: + return json.load(input_file) + + +def output_results(content: List[Dict[str, Any]], output: str): + with Path(output).open("w") as output_file: + output_file.write(json.dumps(content)) + + +def main(): + args = parse_args() + content = read_input(args.input) + output_results(convert_input(content, args.adapter), args.output) + + +if __name__ == "__main__": + main()