Skip to content

Commit 87fcf87

Browse files
authored
Using tls client config as the other clients on cortex (#4849)
* Using tls client config as the other clients on cortex Signed-off-by: Alan Protasio <approtas@amazon.com> * lint Signed-off-by: Alan Protasio <approtas@amazon.com> Signed-off-by: Alan Protasio <approtas@amazon.com>
1 parent 44e5e67 commit 87fcf87

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

docs/configuration/config-file-reference.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3989,10 +3989,6 @@ otel:
39893989
# CLI flag: -tracing.otel.oltp-endpoint
39903990
[oltp_endpoint: <string> | default = ""]
39913991

3992-
# Disables client transport security for the exporter.
3993-
# CLI flag: -tracing.otel.insecure
3994-
[insecure: <boolean> | default = false]
3995-
39963992
# enhance/modify traces/propagators for specific exporter. If empty, OTEL
39973993
# defaults will apply. Supported values are: `awsxray.`
39983994
# CLI flag: -tracing.otel.exporter-type
@@ -4002,4 +3998,34 @@ otel:
40023998
# everything is traced.
40033999
# CLI flag: -tracing.otel.sample-ration
40044000
[sample_ratio: <float> | default = 0.001]
4001+
4002+
# Enable TLS in the GRPC client. This flag needs to be enabled when any other
4003+
# TLS flag is set. If set to false, insecure connection to gRPC server will be
4004+
# used.
4005+
# CLI flag: -tracing.otel.tls-enabled
4006+
[tls_enabled: <boolean> | default = false]
4007+
4008+
tls:
4009+
# Path to the client certificate file, which will be used for authenticating
4010+
# with the server. Also requires the key path to be configured.
4011+
# CLI flag: -tracing.otel.tls.tls-cert-path
4012+
[tls_cert_path: <string> | default = ""]
4013+
4014+
# Path to the key file for the client certificate. Also requires the client
4015+
# certificate to be configured.
4016+
# CLI flag: -tracing.otel.tls.tls-key-path
4017+
[tls_key_path: <string> | default = ""]
4018+
4019+
# Path to the CA certificates file to validate server certificate against.
4020+
# If not set, the host's root CA certificates are used.
4021+
# CLI flag: -tracing.otel.tls.tls-ca-path
4022+
[tls_ca_path: <string> | default = ""]
4023+
4024+
# Override the expected name on the server certificate.
4025+
# CLI flag: -tracing.otel.tls.tls-server-name
4026+
[tls_server_name: <string> | default = ""]
4027+
4028+
# Skip validating server certificate.
4029+
# CLI flag: -tracing.otel.tls.tls-insecure-skip-verify
4030+
[tls_insecure_skip_verify: <boolean> | default = false]
40054031
```

pkg/tracing/tracing.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ package tracing
22

33
import (
44
"context"
5-
"errors"
65
"flag"
76
"fmt"
87
"strings"
98

109
"github.com/go-kit/log/level"
10+
"github.com/pkg/errors"
1111
"github.com/weaveworks/common/tracing"
12-
"go.opentelemetry.io/otel/propagation"
12+
"google.golang.org/grpc/credentials"
1313

1414
"github.com/opentracing/opentracing-go"
1515
"go.opentelemetry.io/contrib/propagators/aws/xray"
1616
"go.opentelemetry.io/otel"
1717
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
1818
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
19+
"go.opentelemetry.io/otel/propagation"
1920
"go.opentelemetry.io/otel/sdk/resource"
2021
sdktrace "go.opentelemetry.io/otel/sdk/trace"
2122
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
2223

2324
"github.com/cortexproject/cortex/pkg/tracing/migration"
2425
util_log "github.com/cortexproject/cortex/pkg/util/log"
26+
"github.com/cortexproject/cortex/pkg/util/tls"
2527
)
2628

2729
const (
@@ -35,10 +37,11 @@ type Config struct {
3537
}
3638

3739
type Otel struct {
38-
OltpEndpoint string `yaml:"oltp_endpoint" json:"oltp_endpoint"`
39-
Insecure bool `yaml:"insecure" json:"insecure"`
40-
ExporterType string `yaml:"exporter_type" json:"exporter_type"`
41-
SampleRatio float64 `yaml:"sample_ratio" json:"sample_ratio"`
40+
OltpEndpoint string `yaml:"oltp_endpoint" json:"oltp_endpoint"`
41+
ExporterType string `yaml:"exporter_type" json:"exporter_type"`
42+
SampleRatio float64 `yaml:"sample_ratio" json:"sample_ratio"`
43+
TLSEnabled bool `yaml:"tls_enabled"`
44+
TLS tls.ClientConfig `yaml:"tls"`
4245
}
4346

4447
// RegisterFlags registers flag.
@@ -47,8 +50,9 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
4750
f.StringVar(&c.Type, p+".type", JaegerType, "Tracing type. OTEL and JAEGER are currently supported. For jaeger `JAEGER_AGENT_HOST` environment variable should also be set. See: https://cortexmetrics.io/docs/guides/tracing .")
4851
f.Float64Var(&c.Otel.SampleRatio, p+".otel.sample-ration", 0.001, "Fraction of traces to be sampled. Fractions >= 1 means sampling if off and everything is traced.")
4952
f.StringVar(&c.Otel.OltpEndpoint, p+".otel.oltp-endpoint", "", "otl collector endpoint that the driver will use to send spans.")
50-
f.BoolVar(&c.Otel.Insecure, p+".otel.insecure", false, "Disables client transport security for the exporter.")
5153
f.StringVar(&c.Otel.ExporterType, p+".otel.exporter-type", "", "enhance/modify traces/propagators for specific exporter. If empty, OTEL defaults will apply. Supported values are: `awsxray.`")
54+
f.BoolVar(&c.Otel.TLSEnabled, p+".otel.tls-enabled", c.Otel.TLSEnabled, "Enable TLS in the GRPC client. This flag needs to be enabled when any other TLS flag is set. If set to false, insecure connection to gRPC server will be used.")
55+
c.Otel.TLS.RegisterFlagsWithPrefix(p+".otel.tls", f)
5256
}
5357

5458
func (c *Config) Validate() error {
@@ -81,7 +85,13 @@ func SetupTracing(ctx context.Context, name string, c Config) (func(context.Cont
8185
otlptracegrpc.WithEndpoint(c.Otel.OltpEndpoint),
8286
}
8387

84-
if c.Otel.Insecure {
88+
if c.Otel.TLSEnabled {
89+
tlsConfig, err := c.Otel.TLS.GetTLSConfig()
90+
if err != nil {
91+
return nil, errors.Wrap(err, "error creating grpc dial options")
92+
}
93+
options = append(options, otlptracegrpc.WithTLSCredentials(credentials.NewTLS(tlsConfig)))
94+
} else {
8595
options = append(options, otlptracegrpc.WithInsecure())
8696
}
8797

0 commit comments

Comments
 (0)