Skip to content

Commit

Permalink
feat: use chart.js for graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 16, 2024
1 parent e9fac06 commit 388507a
Show file tree
Hide file tree
Showing 22 changed files with 3,716 additions and 317 deletions.
149 changes: 0 additions & 149 deletions cmd/README.md

This file was deleted.

1 change: 1 addition & 0 deletions cmd/doc_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
)

// todo: export in a /tools folder
func NewDocEventsCommand() *cobra.Command {
const (
writeDirFlag = "write-dir"
Expand Down
1 change: 1 addition & 0 deletions cmd/doc_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/pflag"
)

// todo: export in a /tools folder
func NewDocFlagsCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "flags",
Expand Down
19 changes: 19 additions & 0 deletions test/performance/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
VERSION 0.8

IMPORT github.com/formancehq/earthly:tags/v0.16.2 AS core

run:
LOCALLY
ARG args=""
RUN go test -bench="Write" -run ^$ -tags it -report.file ./report/report.json -timeout 60m $args

generate-graphs:
FROM core+base-image
RUN apk update && apk add nodejs npm
COPY charts /src
COPY ./report/report.json /report/report.json
WORKDIR /src
RUN npm install
RUN npm run build
RUN node index.js
SAVE ARTIFACT *.png AS LOCAL ./report/
49 changes: 24 additions & 25 deletions test/performance/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
# Performance test

Each feature is tested against a test script involving a transaction from a source to a destination.
The benchmarks also test the minimal set of features and the full set of features.

Refer to [features](../../CONTRIBUTING.md/#features) for more information about features.

Three types of script are actually tested:
* world->bank : A transaction from `@world` to `@bank`
* world->any : A transaction from `@world` to `@dst:<iteration>`
* any(unbounded)->any : A transaction from `@src:<iteration>` to `@dst:<iteration>`

## Run locally

```shell
go test -bench=. -run ^$ -tags it
earthly +run
```

You can pass additional arguments (the underlying command is a standard `go test -bench=.`) using the flag `--args`.
For example:
```shell
earthly +run --args="-benchtime 10s"
```

## Run on a remote stack

```shell
go test -bench=. -run ^$ -tags it \
--stack.url=XXX \
--client.id=XXX \
--client.secret=XXX
earthly +run --args="--stack.url=XXX --client.id=XXX --client.secret=XXX"
```

## Run on a remote ledger

```shell
go test -bench=. -run ^$ -tags it \
--ledger.url=XXX \
--auth.url=XXX \
--client.id=XXX \
--client.secret=XXX
earthly +run --args="--ledger.url=XXX --auth.url=XXX --client.id=XXX --client.secret=XXX"
```

## Results

The output is a standard go bench output.
TPS is included as a benchmark metrics.

Additionally, you can pass the flag `-report.dir` to export results:
```shell
go test -bench=testserver -run ^$ -tags it -report.dir .
You can generate some graphs using the command:
```
earthly +generate-graphs
```

The exported files are PNG.

Each feature is tested against a test script involving a transaction from a source to a destination.
The benchmarks also test the minimal set of features and the full set of features.

Refer to [features](../../CONTRIBUTING.md/#features) for more information about features.

Three types of script are actually tested:
* world->bank : A transaction from `@world` to `@bank`
* world->any : A transaction from `@world` to `@dst:<iteration>`
* any(unbounded)->any : A transaction from `@src:<iteration>` to `@dst:<iteration>`
See generated files in `report` directory.
51 changes: 51 additions & 0 deletions test/performance/charts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
require("chartjs-to-image");
const graphs_1 = require("./src/graphs");
const main = () => __awaiter(void 0, void 0, void 0, function* () {
let buffer = fs.readFileSync('../report/report.json', 'utf-8');
let reports = JSON.parse(buffer);
yield (0, graphs_1.exportTPSGraph)({
output: 'tps.png',
}, reports);
yield (0, graphs_1.exportLatencyGraph)({
output: 'p99.png'
}, 'P99', reports);
yield (0, graphs_1.exportLatencyGraph)({
output: 'p95.png'
}, 'P95', reports);
});
main();
21 changes: 21 additions & 0 deletions test/performance/charts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as fs from 'fs';
import 'chartjs-to-image';
import {exportLatencyGraph, exportTPSGraph} from "./src/graphs";

const main = async () => {
let buffer = fs.readFileSync('../report/report.json', 'utf-8');
let reports = JSON.parse(buffer);
await exportTPSGraph({
output: 'tps.png',
}, reports);

const ps: (keyof MetricsTime)[] = ['P99', 'P95', 'P75', 'Avg']
for (let p of ps) {
await exportLatencyGraph({
output: p.toLowerCase() + '.png'
}, p, reports);
}
}

main();

Loading

0 comments on commit 388507a

Please sign in to comment.