Skip to content

Commit

Permalink
Customise benchmark page (#1233)
Browse files Browse the repository at this point in the history
Currently the benchmark page
[loads](https://github.com/awslabs/mountpoint-s3/blob/gh-pages/dev/bench/index.html#L107)
the chart.js library from CDN, this PR changes that and adds CSP to
ensure that no other resources are loaded from external locations.

### Does this change impact existing behavior?

No.

### Does this change need a changelog entry? Does it require a version
change?

No.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and I agree to the terms of
the [Developer Certificate of Origin
(DCO)](https://developercertificate.org/).

---------

Signed-off-by: Vlad Volodkin <[email protected]>
Co-authored-by: Vlad Volodkin <[email protected]>
  • Loading branch information
vladem and Vlad Volodkin authored Jan 17, 2025
1 parent ace3093 commit ef20898
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 16 deletions.
80 changes: 80 additions & 0 deletions .github/actions/scripts/copy-static-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Source directory in the main branch
SOURCE_DIR="benchmark_website"
# Temporary directory to store files in after switching to gh-pages branch
TMP_DIR="/tmp/benchmark_website"

# Check if at least one destination directory is provided as argument
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <destination_dir1> <destination_dir2> ... <destination_dirN>"
exit 1
fi

# Function to copy files from source to destination dirs
copy_files() {
local SOURCE_DIR=$1
local DEST_DIR=$2
local FILES=("${@:3}") # Capture all remaining arguments as the list of files to copy

echo "Copying files from $SOURCE_DIR to $DEST_DIR..."

# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"

# Iterate through each file in the list and copy it to the destination directory
for FILE in "${FILES[@]}"; do
# Check if the file exists in the source directory
if [[ -f "$SOURCE_DIR/$FILE" ]]; then
echo "Copying $FILE to $DEST_DIR"
cp "$SOURCE_DIR/$FILE" "$DEST_DIR/"
else
echo "File $FILE not found in $SOURCE_DIR"
exit 1
fi
done
}

# List of predefined filenames of static resources
FILES=(
"Chart.min.css"
"Chart.min.js"
"index.html"
"main.js"
"styles.css"
)

# Copy files to the temporary directory
copy_files "$SOURCE_DIR" "$TMP_DIR" "${FILES[@]}"

# Switch to the gh-pages to provision static resources to it
git switch gh-pages

# Iterate through the destination directories and copy files from the temporary one to each of them
for DEST_DIR in "$@"; do
copy_files "$TMP_DIR" "$DEST_DIR" "${FILES[@]}"
done

echo "Copied static files for all charts"

for DIR in "$@"; do
if [ -d "$DIR" ]; then
echo "Adding files from $DIR..."
git add "$DIR"/*
else
echo "Warning: Directory $DIR does not exist. Skipping."
exit 1
fi
done

# Check if there are any files to commit
if git diff --cached --quiet; then
echo "No changes to commit."
exit 0
fi

# Commit the changes
git \
-c user.name=github-bench-workflow \
-c [email protected] \
commit -m "Stored static files"
38 changes: 28 additions & 10 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ jobs:
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: true
max-items-in-chart: 20
summary-always: true
Expand All @@ -99,12 +99,18 @@ jobs:
fail-on-alert: false
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: false
max-items-in-chart: 20
skip-fetch-gh-pages: true
summary-always: true
- name: Provision static content and push benchmark results
# Store the results and deploy GitHub pages if the results are from main branch
if: ${{ inputs.publish }}
run: |
.github/actions/scripts/copy-static-files.sh dev/bench dev/bench/peak_mem_usage
git push 'https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git' gh-pages:gh-pages
latency-bench:
name: Benchmark (Latency)
Expand Down Expand Up @@ -160,11 +166,17 @@ jobs:
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: false
max-items-in-chart: 20
summary-always: true
- name: Provision static content and push benchmark results
# Store the results and deploy GitHub pages if the results are from main branch
if: ${{ inputs.publish }}
run: |
.github/actions/scripts/copy-static-files.sh dev/latency_bench
git push 'https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git' gh-pages:gh-pages
cache-bench:
name: Benchmark (Cache)
Expand Down Expand Up @@ -222,8 +234,8 @@ jobs:
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: false
max-items-in-chart: 20
summary-always: true
Expand All @@ -238,9 +250,15 @@ jobs:
fail-on-alert: false
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: false
max-items-in-chart: 20
skip-fetch-gh-pages: true
summary-always: true
- name: Provision static content and push benchmark results
# Store the results and deploy GitHub pages if the results are from main branch
if: ${{ inputs.publish }}
run: |
.github/actions/scripts/copy-static-files.sh dev/cache_bench dev/cache_bench/peak_mem_usage
git push 'https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git' gh-pages:gh-pages
24 changes: 18 additions & 6 deletions .github/workflows/bench_s3express.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ jobs:
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: true
max-items-in-chart: 20
summary-always: true
Expand All @@ -98,12 +98,18 @@ jobs:
fail-on-alert: false
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: false
max-items-in-chart: 20
skip-fetch-gh-pages: true
summary-always: true
- name: Provision static content and push benchmark results
# Store the results and deploy GitHub pages if the results are from main branch
if: ${{ inputs.publish }}
run: |
.github/actions/scripts/copy-static-files.sh dev/s3-express/bench dev/s3-express/bench/peak_mem_usage
git push 'https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git' gh-pages:gh-pages
latency-bench:
name: Benchmark (Latency)
Expand Down Expand Up @@ -159,8 +165,14 @@ jobs:
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Store the results and deploy GitHub pages automatically if the results are from main branch
auto-push: ${{ inputs.publish }}
# Make sure to add this chart to the step provisioning static content and pushing the changes
auto-push: false
comment-on-alert: false
max-items-in-chart: 20
summary-always: true
- name: Provision static content and push benchmark results
# Store the results and deploy GitHub pages if the results are from main branch
if: ${{ inputs.publish }}
run: |
.github/actions/scripts/copy-static-files.sh dev/s3-express/latency_bench
git push 'https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git' gh-pages:gh-pages
12 changes: 12 additions & 0 deletions benchmark_website/Chart.min.css

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

18 changes: 18 additions & 0 deletions benchmark_website/Chart.min.js

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions benchmark_website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
the MIT License
Copyright (c) 2019 rhysd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!DOCTYPE html>
<meta
http-equiv="Content-Security-Policy"
content="upgrade-insecure-requests; default-src 'none'; object-src 'none'; frame-ancestors 'none'; base-uri 'none'; script-src 'self'; style-src 'self';"
>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes" />
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" type="text/css" href="Chart.min.css">
<title>Benchmarks</title>
</head>

<body>
<header id="header">
<div class="header-item">
<strong class="header-label">Last Update:</strong>
<span id="last-update"></span>
</div>
<div class="header-item">
<strong class="header-label">Repository:</strong>
<a id="repository-link" rel="noopener"></a>
</div>
</header>
<main id="main"></main>
<footer>
<button id="dl-button">Download data as JSON</button>
<div class="spacer"></div>
<div class="small">Powered by <a rel="noopener" href="https://github.com/marketplace/actions/continuous-benchmark">github-action-benchmark</a></div>
</footer>

<script src="Chart.min.js"></script>
<script src="data.js"></script>
<script src="main.js"></script>
</body>
</html>
Loading

0 comments on commit ef20898

Please sign in to comment.