From 75ce5c8b7942d5ec70b951c5113e38d6b866adac Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Wed, 19 Apr 2023 12:06:15 -0400 Subject: [PATCH] promdump: add multi-metric support to promdump Completed and (mostly) polished support for collecting multiple metrics. The utility now supports collecting a known set of Yugabyte metrics (master_export, node_export, tserver_export, cql_export (not a typo), and ysql_export), a specific custom metric, or both. If only --node_prefix is specified, Yugabyte metrics will be collected using the default export name for each metric (i.e. what is specified in export_type in the PromQL query). If --metric is specified but --node_prefix is not, only the specified metric will be collected. If both --node_prefix and --metric are specified, both the Yugabyte metrics and the specified custom metric will be collected. Individual Yugabyte metrics can be enabled or disabled using the corresponding flags. These flags are enabled by default when node_prefix is specified and disabled by default when it is not. The flag list is generated dynamically based on the collector configuration specified in the var() section of the code. New export collectors utilizing metrics of the same format (i.e. {export_type="...",node_prefix="..."}) can be added with no additional code required. The check for existing export files now happens before we attempt to export any metrics. Replaced detailed debug logging for handling of yugabyte metrics collection config with a summary. Added a check that forbids use of reserved export names as --out parameters for custom metrics. Changed the behaviour of individual metric export failures to report an error, then continue with the next metric. Fixed a bug where we were unconditionally trying to export a custom metric even if no custom metric was specified. Changed redundant log.Fatalln(fmt.sprintf(...)) statements to log.Fatalf(...) instead. Updated README with new Golang version. --- README.md | 2 +- promdump/promdump.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1124a5a..19238f6 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ concurrent API requests: ## Compile ``` -docker run --rm -v "$PWD/promdump":/promdump -w /promdump golang:1.12 go build +docker run --rm -v "$PWD/promdump":/promdump -w /promdump golang:1.17 go build docker run --rm -v "$PWD/promremotewrite":/promremotewrite -w /promremotewrite golang:1.12 go build ``` diff --git a/promdump/promdump.go b/promdump/promdump.go index ea5fc26..6cd744c 100644 --- a/promdump/promdump.go +++ b/promdump/promdump.go @@ -85,7 +85,7 @@ func logMetricCollectorConfig() { var skip []string for _, v := range collectMetrics { if *out != "" && *out == v.exportName { - log.Fatalln(fmt.Sprintf("The output file prefix '%v' is reserved. Specify a different --out value.", v.exportName)) + log.Fatalf("The output file prefix '%v' is reserved. Specify a different --out value.", v.exportName) } if v.collect { collect = append(collect, v.exportName) @@ -355,7 +355,7 @@ func main() { for _, v := range collectMetrics { matches, err := filepath.Glob(fmt.Sprintf("%s.[0-9][0-9][0-9][0-9][0-9]", v.exportName)) if err != nil { - log.Fatalln(fmt.Sprintf("main: checking for existing export files with file prefix %v failed with error: %v", v.exportName, err)) + log.Fatalf("main: checking for existing export files with file prefix %v failed with error: %v", v.exportName, err) } if len(matches) > 0 { // No error = file already exists @@ -366,7 +366,7 @@ func main() { if *out != "" { matches, err := filepath.Glob(fmt.Sprintf("%s.[0-9][0-9][0-9][0-9][0-9]", *out)) if err != nil { - log.Fatalln(fmt.Sprintf("main: checking for existing export files with file prefix %v failed with error: %v", *out, err)) + log.Fatalf("main: checking for existing export files with file prefix %v failed with error: %v", *out, err) } if len(matches) > 0 { // No error = file already exists @@ -375,7 +375,7 @@ func main() { } if len(fileConflictPrefixes) > 0 { sort.Strings(fileConflictPrefixes) - log.Fatalln(fmt.Sprintf("main: found existing export files with file prefix(es): %v; move any existing export files aside before proceeding", strings.Join(fileConflictPrefixes, " "))) + log.Fatalf("main: found existing export files with file prefix(es): %v; move any existing export files aside before proceeding", strings.Join(fileConflictPrefixes, " ")) } // TODO: DRY this out