-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow toggling between all-time and last 90 day flake charts
- Loading branch information
Showing
6 changed files
with
172 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters