Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devhub: unify devhub and nyrkio metrics format #1771

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/devhub/devhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// - no TypeScript, no build step

async function main() {
const runs = await fetchData();
const series = runsToSeries(runs);
const batches = await fetchData();
const series = batchesToSeries(batches);
plotSeries(series, document.querySelector("#charts"));

const releaseManager = getReleaseManager();
Expand Down Expand Up @@ -63,32 +63,32 @@ async function fetchData() {
// form a single array which is what we want to plot.
//
// This doesn't depend on particular plotting library though.
function runsToSeries(runs) {
function batchesToSeries(batches) {
const result = new Map();
for (const run of runs) {
for (const measurement of run.measurements) {
if (!result.has(measurement.label)) {
result.set(measurement.label, {
label: measurement.label,
for (const batch of batches) {
for (const metric of batch.metrics) {
if (!result.has(metric.name)) {
result.set(metric.label, {
name: metric.name,
unit: undefined,
value: [],
revision: [],
git_commit: [],
timestamp: [],
});
}

const series = result.get(measurement.label);
assert(series.label == measurement.label);
const series = result.get(metric.name);
assert(series.name == metric.name);

if (series.unit) {
assert(series.unit == measurement.unit);
assert(series.unit == metric.unit);
} else {
series.unit = measurement.unit;
series.unit = metric.unit;
}

series.value.push(measurement.value);
series.revision.push(run.revision);
series.timestamp.push(run.timestamp);
series.value.push(metric.value);
series.git_commit.push(batch.attributes.git_commit);
series.timestamp.push(batch.timestamp);
}
}
return result.values();
Expand All @@ -99,7 +99,7 @@ function plotSeries(seriesList, rootNode) {
for (const series of seriesList) {
let options = {
title: {
text: series.label,
text: series.name,
},
chart: {
type: "line",
Expand All @@ -108,7 +108,7 @@ function plotSeries(seriesList, rootNode) {
dataPointSelection: (event, chartContext, { dataPointIndex }) => {
window.open(
"https://github.com/tigerbeetle/tigerbeetle/commit/" +
series.revision[dataPointIndex],
series.git_commit[dataPointIndex],
);
},
},
Expand All @@ -117,7 +117,7 @@ function plotSeries(seriesList, rootNode) {
size: 4,
},
series: [{
name: series.label,
name: series.name,
data: series.value,
}],
xaxis: {
Expand All @@ -137,7 +137,7 @@ function plotSeries(seriesList, rootNode) {
const timestamp = new Date(series.timestamp[dataPointIndex] * 1000);
const formattedDate = timestamp.toLocaleString();
return `<div>${
series.revision[dataPointIndex]
series.git_commit[dataPointIndex]
}</div><div>${formattedDate}</div>`;
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/devhub/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h2>Release</h2>
</section>

<section>
<h2>Release Metrics</h2>
<h2>Metrics (on <a href="https://nyrkio.com/public/https%3A%2F%2Fgithub.com%2Ftigerbeetle%2Ftigerbeetle/main/devhub">Nyrkiö</a>)</h2>
<div id="charts" style="display: flex; flex-direction: column;">
</div>
</section>
Expand Down
62 changes: 22 additions & 40 deletions src/scripts/devhub.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,26 @@ pub fn main(shell: *Shell, gpa: std.mem.Allocator, cli_args: CliArgs) !void {
const query_p99_ms = try get_measurement(benchmark_result, "query latency p99", "ms");
const rss_bytes = try get_measurement(benchmark_result, "rss", "bytes");

try upload_run(shell, Run{
// Use commit timestamp, rather wall clock time here. That way, it is possible to re-bench
// mark the entire history while getting a comparable time series.
.timestamp = commit_timestamp,
.revision = cli_args.sha,
.measurements = &[_]Measurement{
.{ .label = "build time", .value = build_time_ms, .unit = "ms" },
.{ .label = "executable size", .value = executable_size_bytes, .unit = "bytes" },
.{ .label = "TPS", .value = tps, .unit = "count" },
.{ .label = "batch p99", .value = batch_p99_ms, .unit = "ms" },
.{ .label = "query p99", .value = query_p99_ms, .unit = "ms" },
.{ .label = "RSS", .value = rss_bytes, .unit = "bytes" },
},
});

upload_nyrkio(shell, NyrkioRun{
const batch = MetricBatch{
.timestamp = commit_timestamp,
.attributes = .{
.git_repo = "https://github.com/tigerbeetle/tigerbeetle",
.git_commit = cli_args.sha,
.branch = "main",
},
.metrics = &[_]NyrkioRun.Metric{
.metrics = &[_]Metric{
.{ .name = "build time", .value = build_time_ms, .unit = "ms" },
.{ .name = "executable size", .value = executable_size_bytes, .unit = "bytes" },
.{ .name = "TPS", .value = tps, .unit = "count" },
.{ .name = "batch p99", .value = batch_p99_ms, .unit = "ms" },
.{ .name = "query p99", .value = query_p99_ms, .unit = "ms" },
.{ .name = "RSS", .value = rss_bytes, .unit = "bytes" },
},
}) catch |err| {
};

try upload_run(shell, &batch);

upload_nyrkio(shell, &batch) catch |err| {
log.err("failed to upload Nyrkiö metrics: {}", .{err});
};
}
Expand All @@ -88,19 +77,7 @@ fn get_measurement(
return try std.fmt.parseInt(u64, cut.prefix, 10);
}

const Measurement = struct {
label: []const u8,
value: u64,
unit: []const u8,
};

const Run = struct {
timestamp: u64,
revision: []const u8,
measurements: []const Measurement,
};

fn upload_run(shell: *Shell, run: Run) !void {
fn upload_run(shell: *Shell, batch: *const MetricBatch) !void {
const token = try shell.env_get("DEVHUBDB_PAT");
try shell.exec(
\\git clone --depth 1
Expand All @@ -120,7 +97,7 @@ fn upload_run(shell: *Shell, run: Run) !void {
defer file.close();

try file.seekFromEnd(0);
try std.json.stringify(run, .{}, file.writer());
try std.json.stringify(batch, .{}, file.writer());
try file.writeAll("\n");
}

Expand All @@ -130,12 +107,13 @@ fn upload_run(shell: *Shell, run: Run) !void {
try shell.exec("git push", .{});
}

const NyrkioRun = struct {
const Metric = struct {
name: []const u8,
unit: []const u8,
value: u64,
};
const Metric = struct {
name: []const u8,
unit: []const u8,
value: u64,
};

const MetricBatch = struct {
timestamp: u64,
metrics: []const Metric,
attributes: struct {
Expand All @@ -145,9 +123,13 @@ const NyrkioRun = struct {
},
};

fn upload_nyrkio(shell: *Shell, run: NyrkioRun) !void {
fn upload_nyrkio(shell: *Shell, batch: *const MetricBatch) !void {
const token = try shell.env_get("NYRKIO_TOKEN");
const payload = try std.json.stringifyAlloc(shell.arena.allocator(), [_]NyrkioRun{run}, .{});
const payload = try std.json.stringifyAlloc(
shell.arena.allocator(),
[_]*const MetricBatch{batch}, // Nyrkiö needs an _array_ of batches.
.{},
);
try shell.exec(
\\curl -s -X POST --fail-with-body
\\ -H {content_type}
Expand Down