Skip to content

Commit

Permalink
allow toggling between all-time and last 90 day flake charts
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Dec 30, 2021
1 parent 984f3d3 commit 96802bd
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 23 deletions.
3 changes: 2 additions & 1 deletion hack/jenkins/test-flake-chart/flake_chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</style>
</head>
<body>
<div id="period_display"></div>
<div id="chart_div"></div>
<div id="data_date_container" style="text-align: right; display: none">
Data collected on <span id="data_date"></span>
Expand All @@ -33,4 +34,4 @@
el.setAttribute('src', `flake_chart.js?t=${Math.random()}`);
document.head.appendChild(el);
</script>
</html>
</html>
24 changes: 17 additions & 7 deletions hack/jenkins/test-flake-chart/flake_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ const testStatus = {
SKIPPED: "Skipped"
}

async function loadTestData() {
const response = await fetch("data.csv", {
async function loadTestData(period) {
const file = period === "last90" ? "data-last-90.csv" : "data.csv";
const response = await fetch(file, {
headers: {
"Cache-Control": "max-age=3600,must-revalidate",
}
Expand Down Expand Up @@ -664,30 +665,39 @@ function displayEnvironmentChart(testData, environmentName) {
}

async function init() {
const query = parseUrlQuery(window.location.search);
const desiredTest = query.test, desiredEnvironment = query.env || "", desiredPeriod = query.period || "";

google.charts.load('current', { 'packages': ['corechart'] });
let testData, responseDate;
try {
// Wait for Google Charts to load, and for test data to load.
// Only store the test data (at index 1) into `testData`.
[testData, responseDate] = (await Promise.all([
new Promise(resolve => google.charts.setOnLoadCallback(resolve)),
loadTestData()
loadTestData(desiredPeriod)
]))[1];
} catch (err) {
displayError(err);
return;
}

const query = parseUrlQuery(window.location.search);
const desiredTest = query.test, desiredEnvironment = query.env || "";

if (desiredTest === undefined) {
displayEnvironmentChart(testData, desiredEnvironment);
displayEnvironmentChart(testData, desiredEnvironment, desiredPeriod);
} else {
displayTestAndEnvironmentChart(testData, desiredTest, desiredEnvironment);
}
document.querySelector('#data_date_container').style.display = 'block';
document.querySelector('#data_date').innerText = responseDate.toLocaleString();
let periodDisplay, newURL;
if (desiredPeriod === 'last90') {
newURL = window.location.href.replace(/&?period=last90/gi, '');
periodDisplay = `Currently viewing last 90 days of data: <a href="` + newURL + `">View all-time data</a>`;
} else {
newURL = window.location.href + '&period=last90';
periodDisplay = `Currently viewing all-time data: <a href="` + newURL + `">View last 90 days of data</a>`;
}
document.querySelector('#period_display').innerHTML = periodDisplay;
}

init();
104 changes: 104 additions & 0 deletions hack/jenkins/test-flake-chart/process_last_90.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright 2021 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
"time"
)

func main() {
dataFile := flag.String("source", "", "The source of the csv file to process")
dataLast90File := flag.String("target", "", "The target of the csv file containing last 90 days of data")
flag.Parse()

if *dataFile == "" || *dataLast90File == "" {
fmt.Println("All flags are required and cannot be empty")
flag.PrintDefaults()
}

data, err := os.Open(*dataFile)
if err != nil {
log.Fatalf("failed opening source file %q: %v", *dataFile, err)
}
defer data.Close()

dataLast90, err := os.OpenFile(*dataLast90File, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("failed creating target file %q: %v", *dataLast90File, err)
}
defer dataLast90.Close()

dw := bufio.NewWriter(dataLast90)

cutoffDate := time.Now().AddDate(0, 0, -90)

// to save space we don't repeat duplicate back to back lines if they have the same value
// for example:
// 2021-09-10,TestOffline,Passed
// ,TestForceSystemd,
// So the date for line two will be empty, so we need to remember the last line that had a date if it's within last 90 days or not
validDate := true

s := bufio.NewScanner(data)
for s.Scan() {
line := s.Text()
stringDate := strings.Split(line, ",")[1]

// copy headers
if stringDate == "Test Date" {
write(dw, line)
continue
}

if stringDate == "" {
if validDate {
write(dw, line)
}
continue
}

testDate, err := time.Parse("2006-01-02", stringDate)
if err != nil {
log.Fatalf("failed to parse date %q: %v", stringDate, err)
}
if testDate.Before(cutoffDate) {
validDate = false
continue
}
validDate = true
write(dw, line)
}

if err := dw.Flush(); err != nil {
log.Fatalf("failed to flush data writer: %v", err)
}
if err := s.Err(); err != nil {
log.Fatalf("scanner had an error: %v", err)
}
}

func write(dw *bufio.Writer, line string) {
if _, err := dw.WriteString(line + "\n"); err != nil {
log.Fatalf("failed to write to data writer: %v", err)
}
}
33 changes: 33 additions & 0 deletions hack/jenkins/test-flake-chart/process_last_90.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Copyright 2021 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eux -o pipefail

# Get directory of script.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

"${DIR}/../installers/check_install_golang.sh" || true

DATA_CSV=$(mktemp)
DATA_LAST_90_CSV=$(mktemp)

gsutil cp gs://minikube-flake-rate/data.csv "$DATA_CSV"

go run "${DIR}/process_last_90.go" --source "$DATA_CSV" --target "$DATA_LAST_90_CSV"

gsutil cp "$DATA_LAST_90_CSV" gs://minikube-flake-rate/data-last-90.csv

rm "$DATA_CSV" "$DATA_LAST_90_CSV"
1 change: 1 addition & 0 deletions hack/jenkins/test-flake-chart/sync_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ if [[ "${MINIKUBE_LOCATION}" == "master" ]]; then
SUMMARY="${BUCKET_PATH}/${ENVIRONMENT}_summary.json"
"${DIR}/upload_tests.sh" "${SUMMARY}" || true
done
"${DIR}/process_last_90.sh"
else
"${DIR}/report_flakes.sh" "${MINIKUBE_LOCATION}" "${ROOT_JOB_ID}" "${FINISHED_LIST}"
fi
Expand Down
30 changes: 15 additions & 15 deletions site/content/en/docs/contrib/test_flakes.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ description: >

|OS|Driver|ContainerRuntime|Link|
|---|---|---|---|
|Linux|docker|docker|[Docker_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux)|
|Linux|docker|containerd|[Docker_Linux_containerd](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_containerd)|
|Linux|docker|crio|[Docker_Linux_crio](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_crio)|
|Linux - arm64|docker|crio|[Docker_Linux_crio_arm64](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_crio_arm64)|
|Linux - arm64|docker|docker|[Docker_Linux_docker_arm64](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_docker_arm64)|
|Linux|kvm2|docker|[KVM_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=KVM_Linux)|
|Linux|kvm2|containerd|[KVM_Linux_containerd](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=KVM_Linux_containerd)|
|Linux|kvm2|crio|[KVM_Linux_crio](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=KVM_Linux_crio)|
|Linux|virtualbox|docker|[VirtualBox_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=VirtualBox_Linux)|
|Linux|none|docker|[none_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=none_Linux)|
|MacOS|docker|docker|[Docker_macOS](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_macOS)|
|MacOS|hyperkit|docker|[Hyperkit_macOS](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Hyperkit_macOS)|
|Windows|docker|docker|[Docker_Windows](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Windows)|
|Windows|hyperv|docker|[Hyper-V_Windows](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Hyper-V_Windows)|
|Cloud Shell|docker|docker|[Docker_Cloud_Shell](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Cloud_Shell)|
|Linux|docker|docker|[Docker_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux&period=last90)|
|Linux|docker|containerd|[Docker_Linux_containerd](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_containerd&period=last90)|
|Linux|docker|crio|[Docker_Linux_crio](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_crio&period=last90)|
|Linux - arm64|docker|crio|[Docker_Linux_crio_arm64](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_crio_arm64&period=last90)|
|Linux - arm64|docker|docker|[Docker_Linux_docker_arm64](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Linux_docker_arm64&period=last90)|
|Linux|kvm2|docker|[KVM_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=KVM_Linux&period=last90)|
|Linux|kvm2|containerd|[KVM_Linux_containerd](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=KVM_Linux_containerd&period=last90)|
|Linux|kvm2|crio|[KVM_Linux_crio](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=KVM_Linux_crio&period=last90)|
|Linux|virtualbox|docker|[VirtualBox_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=VirtualBox_Linux&period=last90)|
|Linux|none|docker|[none_Linux](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=none_Linux&period=last90)|
|MacOS|docker|docker|[Docker_macOS](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_macOS&period=last90)|
|MacOS|hyperkit|docker|[Hyperkit_macOS](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Hyperkit_macOS&period=last90)|
|Windows|docker|docker|[Docker_Windows](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Windows&period=last90)|
|Windows|hyperv|docker|[Hyper-V_Windows](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Hyper-V_Windows&period=last90)|
|Cloud Shell|docker|docker|[Docker_Cloud_Shell](https://storage.googleapis.com/minikube-flake-rate/flake_chart.html?env=Docker_Cloud_Shell&period=last90)|

0 comments on commit 96802bd

Please sign in to comment.