Skip to content

Commit

Permalink
Allow changing max log level for gRPC storage plugins (#1962)
Browse files Browse the repository at this point in the history
* Add support for CLI flag grpc-storage-plugin.log-level

Signed-off-by: yyyogev <[email protected]>

* Add test for grpc log level

Signed-off-by: yyyogev <[email protected]>

* Fix log level flag description

Signed-off-by: yyyogev <[email protected]>

* fix formatting

Signed-off-by: yyyogev <[email protected]>
  • Loading branch information
yyyogev authored and yurishkuro committed Dec 5, 2019
1 parent 95331ad commit e9216d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion plugin/storage/grpc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type Configuration struct {
PluginBinary string `yaml:"binary"`
PluginConfigurationFile string `yaml:"configuration-file"`
PluginLogLevel string `yaml:"log-level"`
}

// Build instantiates a StoragePlugin
Expand All @@ -44,7 +45,7 @@ func (c *Configuration) Build() (shared.StoragePlugin, error) {
Cmd: cmd,
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: hclog.New(&hclog.LoggerOptions{
Level: hclog.Warn,
Level: hclog.LevelFromString(c.PluginLogLevel),
}),
})

Expand Down
2 changes: 2 additions & 0 deletions plugin/storage/grpc/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ func TestWithConfiguration(t *testing.T) {
command.ParseFlags([]string{
"--grpc-storage-plugin.binary=noop-grpc-plugin",
"--grpc-storage-plugin.configuration-file=config.json",
"--grpc-storage-plugin.log-level=debug",
})
f.InitFromViper(v)
assert.Equal(t, f.options.Configuration.PluginBinary, "noop-grpc-plugin")
assert.Equal(t, f.options.Configuration.PluginConfigurationFile, "config.json")
assert.Equal(t, f.options.Configuration.PluginLogLevel, "debug")
}
11 changes: 9 additions & 2 deletions plugin/storage/grpc/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import (
"github.com/jaegertracing/jaeger/plugin/storage/grpc/config"
)

const pluginBinary = "grpc-storage-plugin.binary"
const pluginConfigurationFile = "grpc-storage-plugin.configuration-file"
const (
pluginBinary = "grpc-storage-plugin.binary"
pluginConfigurationFile = "grpc-storage-plugin.configuration-file"
pluginLogLevel = "grpc-storage-plugin.log-level"
defaultPluginLogLevel = "warn"
)

// Options contains GRPC plugins configs and provides the ability
// to bind them to command line flags
Expand All @@ -35,10 +39,13 @@ type Options struct {
func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
flagSet.String(pluginBinary, "", "The location of the plugin binary")
flagSet.String(pluginConfigurationFile, "", "A path pointing to the plugin's configuration file, made available to the plugin with the --config arg")
flagSet.String(pluginLogLevel, defaultPluginLogLevel, "Set the log level of the plugin's logger")
}

// InitFromViper initializes Options with properties from viper
func (opt *Options) InitFromViper(v *viper.Viper) {
opt.Configuration.PluginBinary = v.GetString(pluginBinary)
opt.Configuration.PluginConfigurationFile = v.GetString(pluginConfigurationFile)
opt.Configuration.PluginLogLevel = v.GetString(pluginLogLevel)

}
2 changes: 2 additions & 0 deletions plugin/storage/grpc/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ func TestOptionsWithFlags(t *testing.T) {
command.ParseFlags([]string{
"--grpc-storage-plugin.binary=noop-grpc-plugin",
"--grpc-storage-plugin.configuration-file=config.json",
"--grpc-storage-plugin.log-level=debug",
})
opts.InitFromViper(v)

assert.Equal(t, opts.Configuration.PluginBinary, "noop-grpc-plugin")
assert.Equal(t, opts.Configuration.PluginConfigurationFile, "config.json")
assert.Equal(t, opts.Configuration.PluginLogLevel, "debug")
}

0 comments on commit e9216d9

Please sign in to comment.