diff --git a/Makefile b/Makefile index 6b1f276..e7a14e0 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ update: clean build OUT_DIR=bin build: mkdir -p "${OUT_DIR}" - go build -o "${OUT_DIR}/cpa" main.go + go build -v -o "${OUT_DIR}/cpa" main.go clean: $(RM) ./bin/cpa diff --git a/README.md b/README.md index 9a19a42..468c1b2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ This tool allows OpenShift users to run a watcher for Prometheus queries and def * [x] Add a Makefile * [x] File logging the output * [x] Print output to screen even when logging enabled - simultaneously +* [x] Let user decide query frequency * [ ] Notify/Do Something when results don't match conditions * [ ] Spawn goroutines to keep running queries and evaluating results to handle scale - e.g. when we have very large number of queries in the yaml file, we can divide and concurrently run queries diff --git a/main.go b/main.go index 1d16d45..02c70c4 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,5 @@ +// +build go1.17 + package main import ( @@ -17,10 +19,11 @@ import ( func main() { var args struct { - NoClrscr bool `arg:"--noclrscr" help:"Do not clear screen after each iteration. Clears screen by default." default:"false"` - Queries string `arg:"-q,--queries" help:"queries file to use" default:"queries.yaml"` - Timeout time.Duration `arg:"-t,--timeout" help:"Duration to run Continuous Performance Analysis. You can pass values like 4h or 1h10m10s" default:"4h"` - LogOutput bool `arg:"-l,--log-output" help:"Output will be stored in a log file instead of stdout." default:"false"` + NoClrscr bool `arg:"--noclrscr" help:"Do not clear screen after each iteration. Clears screen by default." default:"false"` + Queries string `arg:"-q,--queries" help:"queries file to use" default:"queries.yaml"` + QueryFrequency time.Duration `arg:"-f,--query-frequency" help:"How often do we run queries. You can pass values like 4h or 1h10m10s" default:"20s"` + Timeout time.Duration `arg:"-t,--timeout" help:"Duration to run Continuous Performance Analysis. You can pass values like 4h or 1h10m10s" default:"4h"` + LogOutput bool `arg:"-l,--log-output" help:"Output will be stored in a log file instead of stdout." default:"false"` } arg.MustParse(&args) @@ -86,9 +89,8 @@ func main() { return } analyze.Queries(queryList, oc, url, bearerToken, c) - d := time.Second * 20 - log.Printf("\n Sleeping for %.2f mins.\n\n\n\n", d.Minutes()) - time.Sleep(d) + log.Printf("\n Sleeping for %.2f mins.\n\n\n\n", args.QueryFrequency.Minutes()) + time.Sleep(args.QueryFrequency) if !args.NoClrscr { log.Print("\033[H\033[2J") // clears screen before printing next iteration }