ci/cd: add continuous benchmark action

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
Ramkumar Chinchani
2022-01-13 22:06:35 +00:00
committed by Ramkumar Chinchani
parent 72da8303c5
commit 6a2529f08f
4 changed files with 90 additions and 7 deletions
+4 -4
View File
@@ -13,7 +13,7 @@ import (
func NewPerfRootCmd() *cobra.Command {
showVersion := false
var auth, workdir, repo, output string
var auth, workdir, repo, outFmt string
var concurrency, requests int
@@ -45,7 +45,7 @@ func NewPerfRootCmd() *cobra.Command {
requests = concurrency * (requests / concurrency)
Perf(workdir, url, auth, repo, concurrency, requests)
Perf(workdir, url, auth, repo, concurrency, requests, outFmt)
},
}
@@ -59,8 +59,8 @@ func NewPerfRootCmd() *cobra.Command {
"Number of multiple requests to make at a time")
rootCmd.Flags().IntVarP(&requests, "requests", "n", 1,
"Number of requests to perform")
rootCmd.Flags().StringVarP(&output, "output-format", "o", "",
"Output format of test results [default: stdout]")
rootCmd.Flags().StringVarP(&outFmt, "output-format", "o", "",
"Output format of test results: stdout (default), json, ci-cd")
// "version"
rootCmd.Flags().BoolVarP(&showVersion, "version", "v", false, "show the version and exit")
+38 -3
View File
@@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
@@ -33,6 +34,7 @@ const (
smallBlob = 1 * MiB
mediumBlob = 10 * MiB
largeBlob = 100 * MiB
cicdFmt = "ci-cd"
)
// helper routines
@@ -198,7 +200,17 @@ func updateStats(summary *statsSummary, record statsRecord) {
summary.latencies = append(summary.latencies, record.latency)
}
func printStats(requests int, summary *statsSummary) {
type cicdTestSummary struct {
Name string `json:"name"`
Unit string `json:"unit"`
Value interface{} `json:"value"`
Range string `json:"range,omitempty"`
}
//nolint:gochecknoglobals // used only in this test
var cicdSummary = []cicdTestSummary{}
func printStats(requests int, summary *statsSummary, outFmt string) {
log.Printf("============\n")
log.Printf("Test name:\t%s", summary.name)
log.Printf("Time taken for tests:\t%v", summary.total)
@@ -219,6 +231,18 @@ func printStats(requests int, summary *statsSummary) {
log.Printf("%s:\t%v", "p90", summary.latencies[requests*9/10])
log.Printf("%s:\t%v", "p99", summary.latencies[requests*99/100])
log.Printf("\n")
// ci/cd
if outFmt == cicdFmt {
cicdSummary = append(cicdSummary,
cicdTestSummary{
Name: summary.name,
Unit: "requests per sec",
Value: summary.rps,
Range: "3",
},
)
}
}
// test suites/funcs.
@@ -644,7 +668,7 @@ var testSuite = []testConfig{ // nolint:gochecknoglobals // used only in this te
},
}
func Perf(workdir, url, auth, repo string, concurrency int, requests int) {
func Perf(workdir, url, auth, repo string, concurrency int, requests int, outFmt string) {
// logging
log.SetFlags(0)
log.SetOutput(tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent))
@@ -691,6 +715,17 @@ func Perf(workdir, url, auth, repo string, concurrency int, requests int) {
sort.Sort(Durations(summary.latencies))
printStats(requests, &summary)
printStats(requests, &summary, outFmt)
}
if outFmt == cicdFmt {
jsonOut, err := json.Marshal(cicdSummary)
if err != nil {
log.Fatal(err) //nolint:gocritic // file closed on exit
}
if err := ioutil.WriteFile(fmt.Sprintf("%s.json", outFmt), jsonOut, defaultFilePerms); err != nil {
log.Fatal(err)
}
}
}