From 23f3cfd2ba029a5522aff583e52ab5d8e617ad3a Mon Sep 17 00:00:00 2001 From: Periklis Tsirakidis Date: Mon, 8 Jun 2020 18:52:17 +0200 Subject: [PATCH] Add flag to disable tracing --- cmd/loki/main.go | 24 +++++++++++++----------- docs/configuration/README.md | 14 ++++++++++++++ pkg/loki/loki.go | 3 +++ pkg/tracing/config.go | 13 +++++++++++++ 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 pkg/tracing/config.go diff --git a/cmd/loki/main.go b/cmd/loki/main.go index a87b23f14ab8..fb2725e14932 100644 --- a/cmd/loki/main.go +++ b/cmd/loki/main.go @@ -58,19 +58,21 @@ func main() { os.Exit(1) } - // Setting the environment variable JAEGER_AGENT_HOST enables tracing - trace, err := tracing.NewFromEnv(fmt.Sprintf("loki-%s", config.Target)) - if err != nil { - level.Error(util.Logger).Log("msg", "error in initializing tracing. tracing will not be enabled", "err", err) - } - defer func() { - if trace != nil { - if err := trace.Close(); err != nil { - level.Error(util.Logger).Log("msg", "error closing tracing", "err", err) - } + if config.Tracing.Enabled { + // Setting the environment variable JAEGER_AGENT_HOST enables tracing + trace, err := tracing.NewFromEnv(fmt.Sprintf("loki-%s", config.Target)) + if err != nil { + level.Error(util.Logger).Log("msg", "error in initializing tracing. tracing will not be enabled", "err", err) } + defer func() { + if trace != nil { + if err := trace.Close(); err != nil { + level.Error(util.Logger).Log("msg", "error closing tracing", "err", err) + } + } - }() + }() + } // Start Loki t, err := loki.New(config) diff --git a/docs/configuration/README.md b/docs/configuration/README.md index f5313a80b05c..eab37fea8e1d 100644 --- a/docs/configuration/README.md +++ b/docs/configuration/README.md @@ -25,8 +25,10 @@ Configuration examples can be found in the [Configuration Examples](examples.md) * [table_manager_config](#table_manager_config) * [provision_config](#provision_config) * [auto_scaling_config](#auto_scaling_config) +* [tracing_config](#tracing_config) * [Runtime Configuration file](#runtime-configuration-file) + ## Configuration File Reference To specify which configuration file to load, pass the `-config.file` flag at the @@ -97,6 +99,9 @@ Supported contents and default values of `loki.yaml`: # Configuration for "runtime config" module, responsible for reloading runtime configuration file. [runtime_config: ] + +#Configuration for tracing +[tracing: ] ``` ## server_config @@ -1044,6 +1049,15 @@ The `auto_scaling_config` block configures autoscaling for DynamoDB. [target: | default = 80] ``` +## tracing_config + +The `tracing_config` block configures tracing for Jaeger. Currently limited to disable auto-configuration per [environment variables](https://www.jaegertracing.io/docs/1.16/client-features/) only. + +```yaml +# Whether or not tracing should be enabled. +[enabled: : default = true] +``` + ## Runtime Configuration file Loki has a concept of "runtime config" file, which is simply a file that is reloaded while Loki is running. It is used by some Loki components to allow operator to change some aspects of Loki configuration without restarting it. File is specified by using `-runtime-config.file=` flag and reload period (which defaults to 10 seconds) can be changed by `-runtime-config.reload-period=` flag. Previously this mechanism was only used by limits overrides, and flags were called `-limits.per-user-override-config=` and `-limits.per-user-override-period=10s` respectively. These are still used, if `-runtime-config.file=` is not specified. diff --git a/pkg/loki/loki.go b/pkg/loki/loki.go index 011f500f5634..7b7db40ca369 100644 --- a/pkg/loki/loki.go +++ b/pkg/loki/loki.go @@ -32,6 +32,7 @@ import ( "github.com/grafana/loki/pkg/querier" "github.com/grafana/loki/pkg/querier/queryrange" "github.com/grafana/loki/pkg/storage" + "github.com/grafana/loki/pkg/tracing" serverutil "github.com/grafana/loki/pkg/util/server" "github.com/grafana/loki/pkg/util/validation" ) @@ -57,6 +58,7 @@ type Config struct { QueryRange queryrange.Config `yaml:"query_range,omitempty"` RuntimeConfig runtimeconfig.ManagerConfig `yaml:"runtime_config,omitempty"` MemberlistKV memberlist.KVConfig `yaml:"memberlist"` + Tracing tracing.Config `yaml:"tracing"` } // RegisterFlags registers flag. @@ -81,6 +83,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { c.Worker.RegisterFlags(f) c.QueryRange.RegisterFlags(f) c.RuntimeConfig.RegisterFlags(f) + c.Tracing.RegisterFlags(f) } // Validate the config and returns an error if the validation diff --git a/pkg/tracing/config.go b/pkg/tracing/config.go new file mode 100644 index 000000000000..c6979709592d --- /dev/null +++ b/pkg/tracing/config.go @@ -0,0 +1,13 @@ +package tracing + +import ( + "flag" +) + +type Config struct { + Enabled bool `yaml:"enabled"` +} + +func (cfg *Config) RegisterFlags(f *flag.FlagSet) { + f.BoolVar(&cfg.Enabled, "tracing.enabled", true, "Set to false to disable tracing.") +}