-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsplot: Create settable aggregation options. (#12)
Expose ability to set all possible alignment and reduction options on the queries aggregation settings. All Set_* methods are generated using scripts/codegen.go.
- Loading branch information
Showing
8 changed files
with
296 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
BINDIR ?= ./bin | ||
SCRIPTDIR := ./scripts | ||
SHELL := /bin/bash | ||
GOBIN := $(shell which go 2> /dev/null) | ||
ifeq ($(GOBIN),) | ||
GOBIN := /usr/local/go/bin/go | ||
endif | ||
|
||
.PHONY: test | ||
test: | ||
go test -v ./... | ||
$(GOBIN) test -v ./... | ||
|
||
.PHONY: build | ||
build: | ||
build: $(BINDIR)/codegen | ||
make -C tscli | ||
|
||
$(BINDIR)/codegen: $(SCRIPTDIR)/codegen.go | ||
@mkdir -p $(BINDIR) | ||
GOOS=linux GOARCH=amd64 $(GOBIN) build -o $(BINDIR)/codegen $< | ||
|
||
.PHONY: install | ||
install: build | ||
cp ./bin/tscli /usr/local/bin/ | ||
cp $(BINDIR)/tscli /usr/local/bin/ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf ./bin | ||
rm -rf $(BINDIR) | ||
|
||
CODEGENFILE="set_aggregation_opts.go" | ||
.PHONY: codegen | ||
codegen: | ||
$(BINDIR)/codegen -output ./tsplot/$(CODEGENFILE) | ||
|
||
.PHONY: codegendiff | ||
codegendiff: | ||
diff ./tsplot/$(CODEGENFILE) <($(BINDIR)/codegen -stdout) |
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,67 @@ | ||
package main | ||
/* | ||
codegen.go creates Set_* API methods for Google Cloud Monitoring aggregation alignment and reduction options. | ||
Leverages the exported variables in the Google monitoring/v3 package (common.pb.go) to ensure that all | ||
alignment and reduction options are covered. | ||
*/ | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"text/template" | ||
|
||
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" | ||
) | ||
|
||
var rawTpl = `/* | ||
DO NOT EDIT | ||
Generated by codegen.go | ||
https://github.com/googleapis/go-genproto/blob/0135a39c27378c1b903c75204eff61a060be5eb7/googleapis/monitoring/v3/common.pb.go | ||
*/ | ||
package tsplot | ||
{{range $name, $value := .Aligners}} | ||
func (mq *MetricQuery) Set_{{$name}}() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner({{$value}})) | ||
} | ||
{{end -}} | ||
{{range $name, $value := .Reducers}} | ||
func (mq *MetricQuery) Set_{{$name}}() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer({{$value}})) | ||
} | ||
{{end}} | ||
` | ||
|
||
func main() { | ||
outFileName := flag.String("output", "./tsplot/set_aggregation_opts.go", "Output path of generated file.") | ||
toStdout := flag.Bool("stdout", false, "Toggle output to STDOUT.") | ||
flag.Parse() | ||
|
||
var outFile *os.File | ||
var fileErr error | ||
|
||
if *toStdout { | ||
outFile = os.Stdout | ||
} else { | ||
outFile, fileErr = os.OpenFile(*outFileName, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644) | ||
if fileErr != nil { | ||
log.Print(fileErr) | ||
} | ||
defer outFile.Close() | ||
} | ||
|
||
values := struct { | ||
Aligners map[string]int32 | ||
Reducers map[string]int32 | ||
}{ | ||
Aligners: monitoringpb.Aggregation_Aligner_value, | ||
Reducers: monitoringpb.Aggregation_Reducer_value, | ||
} | ||
|
||
t := template.New("codegen") | ||
pt := template.Must(t.Parse(rawTpl)) | ||
err := pt.Execute(outFile, values) | ||
if err != nil { | ||
log.Fatal(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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
BINDIR ?= ../bin | ||
SHELL := /bin/bash | ||
GOBIN := $(shell which go 2> /dev/null) | ||
ifeq ($(GOBIN),) | ||
GOBIN := /usr/local/go/bin/go | ||
endif | ||
|
||
default: build | ||
|
||
.PHONY: build | ||
build: | ||
@mkdir -p $(BINDIR) | ||
GOOS=linux GOARCH=amd64 /usr/local/go/bin/go build -o $(BINDIR)/tscli | ||
GOOS=linux GOARCH=amd64 $(GOBIN) build -o $(BINDIR)/tscli |
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
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,139 @@ | ||
/* | ||
DO NOT EDIT | ||
Generated by codegen.go | ||
https://github.com/googleapis/go-genproto/blob/0135a39c27378c1b903c75204eff61a060be5eb7/googleapis/monitoring/v3/common.pb.go | ||
*/ | ||
package tsplot | ||
|
||
func (mq *MetricQuery) Set_ALIGN_COUNT() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(13)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_COUNT_FALSE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(24)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_COUNT_TRUE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(16)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_DELTA() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(1)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_FRACTION_TRUE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(17)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_INTERPOLATE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(3)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_MAX() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(11)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_MEAN() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(12)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_MIN() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(10)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_NEXT_OLDER() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(4)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_NONE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(0)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_PERCENTILE_05() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(21)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_PERCENTILE_50() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(20)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_PERCENTILE_95() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(19)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_PERCENTILE_99() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(18)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_PERCENT_CHANGE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(23)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_RATE() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(2)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_STDDEV() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(15)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_ALIGN_SUM() { | ||
*mq.aggregation = append(*mq.aggregation, withPerSeriesAligner(14)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_COUNT() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(6)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_COUNT_FALSE() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(15)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_COUNT_TRUE() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(7)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_FRACTION_TRUE() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(8)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_MAX() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(3)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_MEAN() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(1)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_MIN() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(2)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_NONE() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(0)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_PERCENTILE_05() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(12)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_PERCENTILE_50() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(11)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_PERCENTILE_95() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(10)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_PERCENTILE_99() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(9)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_STDDEV() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(5)) | ||
} | ||
|
||
func (mq *MetricQuery) Set_REDUCE_SUM() { | ||
*mq.aggregation = append(*mq.aggregation, withCrossSeriesReducer(4)) | ||
} | ||
|