Skip to content

Commit

Permalink
.*: Add support for tracing with Lightstep (thanos-io#1678)
Browse files Browse the repository at this point in the history
* Add support for tracing with Lightstep

Signed-off-by: Antonio Santos <antonio@santosvelasco.com>

* Remove type cast

Signed-off-by: Antonio Santos <antonio@santosvelasco.com>

* Add documentation for the exported methods and types

Signed-off-by: Antonio Santos <antonio@santosvelasco.com>

* Apply suggestions from @bwplotka

Co-Authored-By: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Antonio Santos <antonio@santosvelasco.com>

* Inline variable

Co-Authored-By: Povilas Versockas <p.versockas@gmail.com>
Signed-off-by: Antonio Santos <antonio@santosvelasco.com>

* Update lightstep library and add proper error handling

lightstep/lightstep-tracer-go#228 introduced a
new method to create a Tracer that returns an error when it does not
succeed, instead of nil

Signed-off-by: Antonio Santos <antonio@santosvelasco.com>

* Remove unused import

Signed-off-by: Antonio Santos <antonio@santosvelasco.com>
  • Loading branch information
antonio authored and GiedriusS committed Nov 19, 2019
1 parent b70256a commit c18666b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 154 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel

### Added

- [#1678](https://github.com/thanos-io/thanos/pull/1678) Add Lightstep as a tracing provider.
- [#1687](https://github.com/thanos-io/thanos/pull/1687) Add a new `--grpc-grace-period` CLI option to components which serve gRPC to set how long to wait until gRPC Server shuts down.
- [#1660](https://github.com/thanos-io/thanos/pull/1660) Add a new `--prometheus.ready_timeout` CLI option to the sidecar to set how long to wait until Prometheus starts up.
- [#1573](https://github.com/thanos-io/thanos/pull/1573) `AliYun OSS` object storage, see [documents](docs/storage.md#aliyun-oss) for further information.
Expand Down
19 changes: 19 additions & 0 deletions docs/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,22 @@ config:
service_version: ""
service_environment: ""
```

### Lightstep

Client for [Ligthstep](https://lightstep.com).

In order to configure Thanos to interact with Lightstep you need to provide at least an [access token](https://docs.lightstep.com/docs/create-and-use-access-tokens) in the configuration file. The `collector` key is optional and used when you have on-premise satellites.

[embedmd]:# (flags/config_tracing_lightstep.txt yaml)
```yaml
type: LIGHTSTEP
config:
access_token: ""
collector:
scheme: ""
host: ""
port: 0
plaintext: false
custom_ca_cert_file: ""
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/leanovate/gopter v0.2.4
github.com/lightstep/lightstep-tracer-go v0.18.0
github.com/lovoo/gcloud-opentracing v0.3.0
github.com/mattn/go-ieproxy v0.0.0-20191113090002-7c0f6868bffe // indirect
github.com/mattn/go-runewidth v0.0.6 // indirect
Expand Down
189 changes: 35 additions & 154 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/tracing/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/thanos-io/thanos/pkg/tracing/elasticapm"
"github.com/thanos-io/thanos/pkg/tracing/jaeger"
"github.com/thanos-io/thanos/pkg/tracing/lightstep"
"github.com/thanos-io/thanos/pkg/tracing/stackdriver"
"gopkg.in/yaml.v2"
)
Expand All @@ -22,6 +23,7 @@ const (
STACKDRIVER TracingProvider = "STACKDRIVER"
JAEGER TracingProvider = "JAEGER"
ELASTIC_APM TracingProvider = "ELASTIC_APM"
LIGHTSTEP TracingProvider = "LIGHTSTEP"
)

type TracingConfig struct {
Expand Down Expand Up @@ -53,6 +55,8 @@ func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Regis
return jaeger.NewTracer(ctx, logger, metrics, config)
case string(ELASTIC_APM):
return elasticapm.NewTracer(config)
case string(LIGHTSTEP):
return lightstep.NewTracer(ctx, config)
default:
return nil, nil, errors.Errorf("tracing with type %s is not supported", tracingConf.Type)
}
Expand Down
57 changes: 57 additions & 0 deletions pkg/tracing/lightstep/lightstep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package lightstep

import (
"context"
"io"

"github.com/lightstep/lightstep-tracer-go"
"github.com/opentracing/opentracing-go"
"gopkg.in/yaml.v2"
)

// Config - YAML configuration.
type Config struct {
// AccessToken is the unique API key for your LightStep project. It is
// available on your account page at https://app.lightstep.com/account.
AccessToken string `yaml:"access_token"`

// Collector is the host, port, and plaintext option to use
// for the collector.
Collector lightstep.Endpoint `yaml:"collector"`
}

// Tracer wraps the Lightstep tracer and the context.
type Tracer struct {
lightstep.Tracer
ctx context.Context
}

// Close synchronously flushes the Lightstep tracer, then terminates it.
func (t *Tracer) Close() error {
t.Tracer.Close(t.ctx)

return nil
}

// NewTracer creates a Tracer with the options present in the YAML config.
func NewTracer(ctx context.Context, yamlConfig []byte) (opentracing.Tracer, io.Closer, error) {
config := Config{}
if err := yaml.Unmarshal(yamlConfig, &config); err != nil {
return nil, nil, err
}

options := lightstep.Options{
AccessToken: config.AccessToken,
Collector: config.Collector,
}
lighstepTracer, err := lightstep.CreateTracer(options)
if err != nil {
return nil, nil, err
}

t := &Tracer{
lighstepTracer,
ctx,
}
return t, t, nil
}
2 changes: 2 additions & 0 deletions scripts/cfggen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
trclient "github.com/thanos-io/thanos/pkg/tracing/client"
"github.com/thanos-io/thanos/pkg/tracing/elasticapm"
"github.com/thanos-io/thanos/pkg/tracing/jaeger"
"github.com/thanos-io/thanos/pkg/tracing/lightstep"
"github.com/thanos-io/thanos/pkg/tracing/stackdriver"
kingpin "gopkg.in/alecthomas/kingpin.v2"
yaml "gopkg.in/yaml.v2"
Expand All @@ -42,6 +43,7 @@ var (
trclient.JAEGER: jaeger.Config{},
trclient.STACKDRIVER: stackdriver.Config{},
trclient.ELASTIC_APM: elasticapm.Config{},
trclient.LIGHTSTEP: lightstep.Config{},
}
)

Expand Down

0 comments on commit c18666b

Please sign in to comment.