mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
cmd/utils: allow for multiple influxdb flags (#18520)
This commit is contained in:
parent
4202f23897
commit
3e4583e7c4
4 changed files with 89 additions and 12 deletions
|
|
@ -170,7 +170,7 @@ var (
|
||||||
utils.MetricsInfluxDBDatabaseFlag,
|
utils.MetricsInfluxDBDatabaseFlag,
|
||||||
utils.MetricsInfluxDBUsernameFlag,
|
utils.MetricsInfluxDBUsernameFlag,
|
||||||
utils.MetricsInfluxDBPasswordFlag,
|
utils.MetricsInfluxDBPasswordFlag,
|
||||||
utils.MetricsInfluxDBHostTagFlag,
|
utils.MetricsInfluxDBTagsFlag,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -692,13 +692,13 @@ var (
|
||||||
Value: metrics.DefaultConfig.InfluxDBPassword,
|
Value: metrics.DefaultConfig.InfluxDBPassword,
|
||||||
Category: flags.MetricsCategory,
|
Category: flags.MetricsCategory,
|
||||||
}
|
}
|
||||||
// The `host` tag is part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
|
// Tags are part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
|
||||||
// It is used so that we can group all nodes and average a measurement across all of them, but also so
|
// For example `host` tag could be used so that we can group all nodes and average a measurement
|
||||||
// that we can select a specific node and inspect its measurements.
|
// across all of them, but also so that we can select a specific node and inspect its measurements.
|
||||||
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
|
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
|
||||||
MetricsInfluxDBHostTagFlag = &cli.StringFlag{
|
MetricsInfluxDBTagsFlag = &cli.StringFlag{
|
||||||
Name: "metrics-influxdb.host.tag",
|
Name: "metrics-influxdb.tags",
|
||||||
Usage: "InfluxDB `host` tag attached to all measurements",
|
Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements",
|
||||||
Value: metrics.DefaultConfig.InfluxDBTags,
|
Value: metrics.DefaultConfig.InfluxDBTags,
|
||||||
Category: flags.MetricsCategory,
|
Category: flags.MetricsCategory,
|
||||||
}
|
}
|
||||||
|
|
@ -1518,14 +1518,14 @@ func SetupMetrics(ctx *cli.Context) {
|
||||||
database = ctx.String(MetricsInfluxDBDatabaseFlag.Name)
|
database = ctx.String(MetricsInfluxDBDatabaseFlag.Name)
|
||||||
username = ctx.String(MetricsInfluxDBUsernameFlag.Name)
|
username = ctx.String(MetricsInfluxDBUsernameFlag.Name)
|
||||||
password = ctx.String(MetricsInfluxDBPasswordFlag.Name)
|
password = ctx.String(MetricsInfluxDBPasswordFlag.Name)
|
||||||
hosttag = ctx.String(MetricsInfluxDBHostTagFlag.Name)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if enableExport {
|
if enableExport {
|
||||||
log.Info("Enabling metrics export to InfluxDB")
|
log.Info("Enabling metrics export to InfluxDB")
|
||||||
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "xdc.", map[string]string{
|
|
||||||
"host": hosttag,
|
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
|
||||||
})
|
|
||||||
|
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "xdc.", tagsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsSet(MetricsHTTPFlag.Name) {
|
if ctx.IsSet(MetricsHTTPFlag.Name) {
|
||||||
|
|
@ -1538,6 +1538,23 @@ func SetupMetrics(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SplitTagsFlag(tagsFlag string) map[string]string {
|
||||||
|
tags := strings.Split(tagsFlag, ",")
|
||||||
|
tagsMap := map[string]string{}
|
||||||
|
|
||||||
|
for _, t := range tags {
|
||||||
|
if t != "" {
|
||||||
|
kv := strings.Split(t, "=")
|
||||||
|
|
||||||
|
if len(kv) == 2 {
|
||||||
|
tagsMap[kv[0]] = kv[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagsMap
|
||||||
|
}
|
||||||
|
|
||||||
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
|
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
|
||||||
func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
|
func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,20 @@
|
||||||
|
// Copyright 2019 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Package utils contains internal helper functions for go-ethereum commands.
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -8,6 +25,49 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Test_SplitTagsFlag(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
want map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"2 tags case",
|
||||||
|
"host=localhost,bzzkey=123",
|
||||||
|
map[string]string{
|
||||||
|
"host": "localhost",
|
||||||
|
"bzzkey": "123",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1 tag case",
|
||||||
|
"host=localhost123",
|
||||||
|
map[string]string{
|
||||||
|
"host": "localhost123",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"empty case",
|
||||||
|
"",
|
||||||
|
map[string]string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"garbage",
|
||||||
|
"smth=smthelse=123",
|
||||||
|
map[string]string{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
if got := SplitTagsFlag(tt.args); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("splitTagsFlag() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestWalkMatch(t *testing.T) {
|
func TestWalkMatch(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
root string
|
root string
|
||||||
|
|
|
||||||
|
|
@ -41,5 +41,5 @@ var DefaultConfig = Config{
|
||||||
InfluxDBDatabase: "xdc",
|
InfluxDBDatabase: "xdc",
|
||||||
InfluxDBUsername: "test",
|
InfluxDBUsername: "test",
|
||||||
InfluxDBPassword: "test",
|
InfluxDBPassword: "test",
|
||||||
InfluxDBTags: "localhost",
|
InfluxDBTags: "host=localhost",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue