lib/flagutil: add NewArray helper func

This commit is contained in:
Aliaksandr Valialkin 2019-06-18 10:26:44 +03:00
parent 02417071cd
commit e40224d5de
4 changed files with 22 additions and 20 deletions

View file

@ -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()

View file

@ -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 {

View file

@ -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 {

View file

@ -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