Skip to content

Commit

Permalink
feat(dash-board): init dash app
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Apr 1, 2024
1 parent f3bff02 commit 2b7cbe4
Show file tree
Hide file tree
Showing 10 changed files with 970 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v2
dash-board:
name: 'App: dash-board'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Dependencies
working-directory: apps/dash-board
run: poetry install
k6-report-ingress:
name: 'App: k6-report-ingress'
runs-on: ubuntu-latest
Expand Down Expand Up @@ -97,7 +108,7 @@ jobs:
timeout-minutes: 5
run: |
# Start the application in the background
java -jar "$(find build/artifacts -type f -name '*.jar' -not -name '*-plain.jar')" &
java --enable-preview -jar "$(find build/artifacts -type f -name '*.jar' -not -name '*-plain.jar')" &
APP_PID=$!
# Wait for the application to be ready
Expand Down
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/poetry.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/runConfigurations/dash_board.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added apps/dash-board/README.md
Empty file.
102 changes: 102 additions & 0 deletions apps/dash-board/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import os

import dash
import pandas as pd
import plotly.graph_objs as go
import psycopg2
from dash import dcc, html
from dash.dependencies import Input, Output
from dotenv import load_dotenv

load_dotenv()


def get_db_connection():
connection = psycopg2.connect(
dbname=os.getenv('DB_NAME', 'k6_dashboard'),
user=os.getenv('DB_USER', 'k6_dashboard'),
password=os.getenv('DB_PASSWORD', 'KrPPCHdYSXz6wMct5tUK'),
host=os.getenv('DB_HOST', 'localhost')
)
return connection


def fetch_data(query, params=None):
connection = get_db_connection()
cursor = connection.cursor()
if params:
cursor.execute(query, params)
else:
cursor.execute(query)
result = cursor.fetchall()
cursor.close()
connection.close()
return result


# Fetch unique test run IDs for dropdown options
test_run_ids_query = "SELECT DISTINCT tags->>'testid' AS testid FROM samples"
test_run_ids = fetch_data(test_run_ids_query)
test_run_id_options = [{'label': id[0], 'value': id[0]} for id in test_run_ids]

app = dash.Dash('K6 Dashboard')

app.layout = html.Div([
html.H1('K6 DASH Board'),
dcc.Dropdown(
id='test-run-dropdown',
options=test_run_id_options,
value=test_run_id_options[0]['value'] if test_run_id_options else None
),
dcc.Graph(id='response-time-graph')
])

test_run_query = """
SELECT date_trunc('second', ts) AS time,
avg(value) AS avg_rt,
percentile_cont(0.95) WITHIN GROUP (ORDER BY value) AS perc_95_rt
FROM samples
WHERE metric = 'http_req_duration'
AND (tags ->> 'status')::integer < 400
AND tags ->> 'testid' = 'BenZRz7'
GROUP BY 1
ORDER BY 1;
"""


@app.callback(
Output('response-time-graph', 'figure'),
[Input('test-run-dropdown', 'value')]
)
def update_graph(selected_test_run_id):
# Ensure your SQL query uses the selected_test_run_id placeholder correctly
data = fetch_data(test_run_query, (selected_test_run_id,))

# Convert query results to a DataFrame
agg_df = pd.DataFrame(data, columns=['time', 'avg_rt', 'perc_95_rt']) # Include perc_95_rt column

# Create a Plotly graph object for both the average and 95th percentile response times
figure = go.Figure()

# Plot for average response time
figure.add_trace(
go.Scatter(x=agg_df['time'], y=agg_df['avg_rt'], mode='lines+markers', name='Avg Response Time (ms)')
)

# Plot for 95th percentile response time
figure.add_trace(
go.Scatter(x=agg_df['time'], y=agg_df['perc_95_rt'], mode='lines+markers', name='95th Percentile Response Time (ms)')
)

figure.update_layout(
title='Response Times',
xaxis_title='Timestamp',
yaxis_title='Response Time (ms)',
legend_title='Metric'
)

return figure


if __name__ == '__main__':
app.run_server(debug=True)
10 changes: 10 additions & 0 deletions apps/dash-board/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id "base"
}


group = "io.github.bbortt.k6.dashboard"


dependencies {
}

0 comments on commit 2b7cbe4

Please sign in to comment.