Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Add resultsDir env var and summaries VIEW #4

Merged
merged 1 commit into from
Sep 30, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions supabase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ create table public.benchmarks (
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
comment on table public.benchmarks is 'Table to store benchmarking data';

-- BENCHMARKING SUMMARIES
create or replace view benchmark_summaries as (
select
id
, benchmark_name
, data->'metrics'->'http_reqs'->'rate' as http_reqs_rate
, data->'metrics'->'http_reqs'->'count' as http_reqs_count
, data->'metrics'->'http_req_duration'->'avg' as http_req_duration_avg
, pg_size_pretty((data->'metrics'->'data_received'->'count')::bigint) as data_received
, pg_size_pretty((data->'metrics'->'data_sent'->'count')::bigint) as data_sent
, data->'metrics'->'vus'->'value' as vus
, data->'metrics'->'failed requests'->'value' as failed_requests
from
benchmarks
);
```

Export the following environment variables before running the scripts
Expand Down
6 changes: 4 additions & 2 deletions supabase/write-results-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { createClient } = require('@supabase/supabase-js')

const { supabaseKey, supabaseUrl } = process.env

const resultsDir = process.env.resultsDir || './output';

if (!supabaseKey || !supabaseUrl) {
console.log('Export supabaseKey and supabaseUrl as environment variables. Exiting.')
process.exit(0)
Expand All @@ -12,13 +14,13 @@ if (!supabaseKey || !supabaseUrl) {
const supabase = createClient(supabaseUrl, supabaseKey)

;(async () => {
const files = await fs.readdir('./output/')
const files = await fs.readdir(resultsDir)

for (const file of files) {
if (file.endsWith('.json')) {
// valid benchmark file, lets update supabase table
const benchmarkName = file.split('.json')[0]
const data = JSON.parse(await fs.readFile(`./output/${file}`))
const data = JSON.parse(await fs.readFile(`${resultsDir}/${file}`))

try {
await supabase.from('benchmarks').insert([{ data, benchmark_name: benchmarkName }])
Expand Down