Skip to content

Commit

Permalink
Merge pull request #92 from grafana/activate-tracing
Browse files Browse the repository at this point in the history
Allows to activate tracing.
  • Loading branch information
cyriltovena committed Jul 19, 2022
2 parents 83cea9c + 867bfe3 commit c5331fe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions deploy/helm/fire/templates/deployments-statefulsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ spec:
{{- range $key, $value := $cfg.extraArgs }}
- "-{{ $key }}={{ $value }}"
{{- end }}
{{- with .Values.fire.extraEnvVars }}
env:
{{- range $key, $value := . }}
- name: {{ $key }}
value: {{ $value }}
{{- end }}
{{- end }}
ports:
- name: {{ .Values.fire.service.port_name }}
containerPort: {{ .Values.fire.service.port }}
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/fire/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fire:
log.level: debug

extraLabels: {}
extraEnvVars:
# The following environment variables are set by the Helm chart.
# JAEGER_AGENT_HOST: jaeger-agent.jaeger.svc.cluster.local.

imagePullSecrets: []
nameOverride: ""
Expand Down
20 changes: 20 additions & 0 deletions pkg/fire/fire.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/weaveworks/common/middleware"
"github.com/weaveworks/common/server"
"github.com/weaveworks/common/signals"
wwtracing "github.com/weaveworks/common/tracing"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc/health/grpc_health_v1"

Expand All @@ -35,6 +36,7 @@ import (
"github.com/grafana/fire/pkg/gen/push/v1/pushv1connect"
"github.com/grafana/fire/pkg/ingester"
"github.com/grafana/fire/pkg/querier"
"github.com/grafana/fire/pkg/tracing"
"github.com/grafana/fire/pkg/util"
)

Expand All @@ -47,6 +49,7 @@ type Config struct {
Ingester ingester.Config `yaml:"ingester,omitempty"`
MemberlistKV memberlist.KVConfig `yaml:"memberlist"`
FireDB firedb.Config `yaml:"firedb,omitempty"`
Tracing tracing.Config `yaml:"tracing"`

AuthEnabled bool `yaml:"auth_enabled,omitempty"`
ConfigFile string
Expand All @@ -66,6 +69,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
c.Distributor.RegisterFlags(f)
c.Querier.RegisterFlags(f)
c.FireDB.RegisterFlags(f)
c.Tracing.RegisterFlags(f)
}

// registerServerFlagsWithChangedDefaultValues registers *Config.Server flags, but overrides some defaults set by the weaveworks package.
Expand Down Expand Up @@ -164,6 +168,22 @@ func New(cfg Config) (*Fire, error) {
return nil, err
}

if cfg.Tracing.Enabled {
// Setting the environment variable JAEGER_AGENT_HOST enables tracing
trace, err := wwtracing.NewFromEnv(fmt.Sprintf("fire-%s", cfg.Target))
if err != nil {
level.Error(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(logger).Log("msg", "error closing tracing", "err", err)
}
}
}()
}

// instantiate a fallback pusher client (when not run with a local distributor
pusherHTTPClient, err := commonconfig.NewClientFromConfig(cfg.AgentConfig.ClientConfig.Client, cfg.AgentConfig.ClientConfig.URL.String())
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/tracing/config.go
Original file line number Diff line number Diff line change
@@ -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.")
}

0 comments on commit c5331fe

Please sign in to comment.