Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/flags: Fix parsing of metrics.labels, if provided in config .yml #2906

Merged
merged 1 commit into from May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/2905.bugfix.md
@@ -0,0 +1,4 @@
common/flags: Fix parsing of metrics.labels, if provided in config .yml

[Bug in viper library](https://github.com/spf13/viper/issues/608) was fixed
upstream and drop-in replacement for `GetStringMapString` was removed.
11 changes: 6 additions & 5 deletions go/go.mod
Expand Up @@ -33,7 +33,7 @@ require (
github.com/libp2p/go-libp2p-core v0.0.3
github.com/libp2p/go-msgio v0.0.3 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mitchellh/mapstructure v1.3.0 // indirect
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multiaddr-net v0.0.1
github.com/multiformats/go-multihash v0.0.6 // indirect
Expand All @@ -49,10 +49,11 @@ require (
github.com/seccomp/libseccomp-golang v0.9.1
github.com/smartystreets/assertions v1.0.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.6.3
github.com/spf13/viper v1.7.0
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect
github.com/stretchr/testify v1.5.1
github.com/tendermint/go-amino v0.15.0
Expand All @@ -67,12 +68,12 @@ require (
gitlab.com/yawning/dynlib.git v0.0.0-20190911075527-1e6ab3739fd8
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25 // indirect
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a
google.golang.org/grpc v1.29.1
google.golang.org/grpc/security/advancedtls v0.0.0-20200504170109-c8482678eb49
google.golang.org/protobuf v1.21.0
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/ini.v1 v1.56.0 // indirect
)

go 1.13
89 changes: 83 additions & 6 deletions go/go.sum

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions go/oasis-node/cmd/common/flags/flags.go
Expand Up @@ -3,8 +3,6 @@
package flags

import (
"strings"

flag "github.com/spf13/pflag"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -92,27 +90,6 @@ func DryRun() bool {
return viper.GetBool(CfgDryRun)
}

// GetStringMapString is a drop-in replacement for viper.GetStringMapString due to https://github.com/spf13/viper/issues/608.
func GetStringMapString(key string) map[string]string {
labels := map[string]string{}
val := viper.GetString(key)

// viper.GetString() wraps the string inside [] parenthesis, unwrap it.
if len(val) < 2 {
return labels
}
val = val[1 : len(val)-1]

for _, lPair := range strings.Split(val, ",") {
kv := strings.Split(lPair, "=")
if len(kv) != 2 || kv[0] == "" {
continue
}
labels[kv[0]] = kv[1]
}
return labels
}

func init() {
VerboseFlags.BoolP(cfgVerbose, "v", false, "verbose output")

Expand Down
3 changes: 1 addition & 2 deletions go/oasis-node/cmd/common/logging.go
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/spf13/viper"

"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags"
)

const (
Expand All @@ -32,7 +31,7 @@ func initLogging() error {
return errDefault
}

for k, v := range flags.GetStringMapString(cfgLogLevel) {
for k, v := range viper.GetStringMapString(cfgLogLevel) {
if k == "default" {
continue
}
Expand Down
5 changes: 2 additions & 3 deletions go/oasis-node/cmd/common/metrics/metrics.go
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/oasislabs/oasis-core/go/common/service"
"github.com/oasislabs/oasis-core/go/common/version"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasislabs/oasis-core/go/oasis-test-runner/env"
)

Expand Down Expand Up @@ -199,7 +198,7 @@ func (s *pushService) worker() {
func newPushService() (service.BackgroundService, error) {
addr := viper.GetString(CfgMetricsAddr)
jobName := viper.GetString(CfgMetricsJobName)
labels := flags.GetStringMapString(CfgMetricsLabels)
labels := viper.GetStringMapString(CfgMetricsLabels)
interval := viper.GetDuration(CfgMetricsInterval)

if jobName == "" {
Expand Down Expand Up @@ -269,7 +268,7 @@ func GetDefaultPushLabels(ti *env.TestInstanceInfo) map[string]string {
labels[EscapeLabelCharacters(f.Name)] = f.Value.String()
})
// Override any labels passed to oasis-test-runner via CLI.
for k, v := range flags.GetStringMapString(CfgMetricsLabels) {
for k, v := range viper.GetStringMapString(CfgMetricsLabels) {
labels[k] = v
}

Expand Down
3 changes: 1 addition & 2 deletions go/oasis-test-runner/cmd/cmp/cmp.go
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/oasislabs/oasis-core/go/common/logging"
nodeCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/metrics"
"github.com/oasislabs/oasis-core/go/oasis-test-runner/cmd/common"
)
Expand Down Expand Up @@ -442,7 +441,7 @@ func runCmp(cmd *cobra.Command, args []string) {

// Set other required Prometheus labels, if passed.
// TODO: Integrate test parameters and parameter set combinations if multiple values provided like we do in oasis-test-runner.
for k, v := range flags.GetStringMapString(metrics.CfgMetricsLabels) {
for k, v := range viper.GetStringMapString(metrics.CfgMetricsLabels) {
sLabels[k] = v
tLabels[k] = v
}
Expand Down