From e40224d5de562fee154d8085383c3ae1d8e36859 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 18 Jun 2019 10:26:44 +0300 Subject: [PATCH] lib/flagutil: add NewArray helper func --- app/vminsert/main.go | 9 ++++----- app/vmselect/main.go | 10 ++++------ app/vmselect/prometheus/prometheus.go | 11 +++-------- lib/flagutil/array.go | 12 +++++++++++- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/vminsert/main.go b/app/vminsert/main.go index 66e070d73..e6c966942 100644 --- a/app/vminsert/main.go +++ b/app/vminsert/main.go @@ -26,21 +26,20 @@ var ( opentsdbListenAddr = flag.String("opentsdbListenAddr", "", "TCP and UDP address to listen for OpentTSDB put messages. Usually :4242 must be set. Doesn't work if empty") httpListenAddr = flag.String("httpListenAddr", ":8480", "Address to listen for http connections") maxInsertRequestSize = flag.Int("maxInsertRequestSize", 32*1024*1024, "The maximum size of a single insert request in bytes") - storageNodes flagutil.Array + storageNodes = flagutil.NewArray("storageNode", "Address of vmstorage nodes; usage: -storageNode=vmstorage-host1:8400 -storageNode=vmstorage-host2:8400") ) func main() { - flag.Var(&storageNodes, "storageNode", "Vmstorage address, usage -storageNode=vmstorage-host1:8400 -storageNode=vmstorage-host2:8400") flag.Parse() buildinfo.Init() logger.Init() - logger.Infof("initializing netstorage for storageNodes=%v...", storageNodes) + logger.Infof("initializing netstorage for storageNodes=%s...", *storageNodes) startTime := time.Now() - if len(storageNodes) == 0 { + if len(*storageNodes) == 0 { logger.Fatalf("storageNodes cannot be empty") } - netstorage.InitStorageNodes(storageNodes) + netstorage.InitStorageNodes(*storageNodes) logger.Infof("successfully initialized netstorage in %s", time.Since(startTime)) concurrencylimiter.Init() diff --git a/app/vmselect/main.go b/app/vmselect/main.go index 77dfabe02..9475691b4 100644 --- a/app/vmselect/main.go +++ b/app/vmselect/main.go @@ -26,22 +26,20 @@ var ( cacheDataPath = flag.String("cacheDataPath", "", "Path to directory for cache files. Cache isn't saved if empty") maxConcurrentRequests = flag.Int("search.maxConcurrentRequests", runtime.GOMAXPROCS(-1)*2, "The maximum number of concurrent search requests. It shouldn't exceed 2*vCPUs for better performance. See also -search.maxQueueDuration") maxQueueDuration = flag.Duration("search.maxQueueDuration", 10*time.Second, "The maximum time the request waits for execution when -search.maxConcurrentRequests limit is reached") - - storageNodes flagutil.Array + storageNodes = flagutil.NewArray("storageNode", "Addresses of vmstorage nodes; usage: -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401") ) func main() { - flag.Var(&storageNodes, "storageNode", "Vmstorage address, usage -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401") flag.Parse() buildinfo.Init() logger.Init() - logger.Infof("starting netstorage at storageNodes=%v", storageNodes) + logger.Infof("starting netstorage at storageNodes=%s", *storageNodes) startTime := time.Now() - if len(storageNodes) == 0 { + if len(*storageNodes) == 0 { logger.Fatalf("storageNodes cannot be empty") } - netstorage.InitStorageNodes(storageNodes) + netstorage.InitStorageNodes(*storageNodes) logger.Infof("started netstorage in %s", time.Since(startTime)) if len(*cacheDataPath) > 0 { diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 4ddc9b60a..83dfd8a02 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -23,14 +23,9 @@ import ( var ( maxQueryDuration = flag.Duration("search.maxQueryDuration", time.Second*30, "The maximum time for search query execution") maxQueryLen = flag.Int("search.maxQueryLen", 16*1024, "The maximum search query length in bytes") - - selectNodes flagutil.Array + selectNodes = flagutil.NewArray("selectNode", "Addresses of vmselect nodes; usage: -selectNode=vmselect-host1:8481 -selectNode=vmselect-host2:8481") ) -func init() { - flag.Var(&selectNodes, "selectNode", "vmselect address, usage -selectNode=vmselect-host1:8481 -selectNode=vmselect-host2:8481") -} - // Default step used if not set. const defaultStep = 5 * 60 * 1000 @@ -239,10 +234,10 @@ func DeleteHandler(at *auth.Token, r *http.Request) error { var deleteDuration = metrics.NewSummary(`vm_request_duration_seconds{path="/api/v1/admin/tsdb/delete_series"}`) func resetRollupResultCaches() { - if len(selectNodes) == 0 { + if len(*selectNodes) == 0 { logger.Panicf("BUG: missing -selectNode flag") } - for _, selectNode := range selectNodes { + for _, selectNode := range *selectNodes { callURL := fmt.Sprintf("http://%s/internal/resetRollupResultCache", selectNode) resp, err := httpClient.Get(callURL) if err != nil { diff --git a/lib/flagutil/array.go b/lib/flagutil/array.go index d8b55c2fe..8f1d6846b 100644 --- a/lib/flagutil/array.go +++ b/lib/flagutil/array.go @@ -1,6 +1,16 @@ package flagutil -import "strings" +import ( + "flag" + "strings" +) + +// NewArray returns new Array with the given name and descprition. +func NewArray(name, description string) *Array { + var a Array + flag.Var(&a, name, description) + return &a +} // Array holds an array of flag values type Array []string