Skip to content

Commit ddcae19

Browse files
authored
otlpgrpc: turn on round_robin LB policy and kuberesolver for resolving k8s service endpoints (#5731)
* otlpgrpc: turn on round_robin loadbalancing policy and use kuberesolver for kubernetes service endpoint Signed-off-by: Ben Ye <[email protected]> * update changelog Signed-off-by: Ben Ye <[email protected]> * make round robin policy configurable Signed-off-by: Ben Ye <[email protected]> * update doc Signed-off-by: Ben Ye <[email protected]> * update changelog Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent 437f8ec commit ddcae19

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* [CHANGE] Index Cache: Multi level cache backfilling operation becomes async. Added `-blocks-storage.bucket-store.index-cache.multilevel.max-async-concurrency` and `-blocks-storage.bucket-store.index-cache.multilevel.max-async-buffer-size` configs and metric `cortex_store_multilevel_index_cache_backfill_dropped_items_total` for number of dropped items. #5661
77
* [FEATURE] Ingester: Add per-tenant new metric `cortex_ingester_tsdb_data_replay_duration_seconds`. #5477
88
* [FEATURE] Query Frontend/Scheduler: Add query priority support. #5605
9+
* [FEATURE] Tracing: Add `kuberesolver` to resolve endpoints address with `kubernetes://` prefix as Kubernetes service. #5731
10+
* [FEATURE] Tracing: Add `tracing.otel.round-robin` flag to use `round_robin` gRPC client side LB policy for sending OTLP traces. #5731
911
* [ENHANCEMENT] Store Gateway: Added `-store-gateway.enabled-tenants` and `-store-gateway.disabled-tenants` to explicitly enable or disable store-gateway for specific tenants. #5638
1012
* [ENHANCEMENT] Compactor: Add new compactor metric `cortex_compactor_start_duration_seconds`. #5683
1113
* [ENHANCEMENT] Upgraded Docker base images to `alpine:3.18`. #5684

docs/configuration/config-file-reference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,6 +5024,12 @@ otel:
50245024
# CLI flag: -tracing.otel.sample-ratio
50255025
[sample_ratio: <float> | default = 0.001]
50265026

5027+
# If enabled, use round_robin gRPC load balancing policy. By default, use
5028+
# pick_first policy. For more details, please refer to
5029+
# https://github.com/grpc/grpc/blob/master/doc/load-balancing.md#load-balancing-policies.
5030+
# CLI flag: -tracing.otel.round-robin
5031+
[round_robin: <boolean> | default = false]
5032+
50275033
# Enable TLS in the GRPC client. This flag needs to be enabled when any other
50285034
# TLS flag is set. If set to false, insecure connection to gRPC server will be
50295035
# used.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ require (
8080
github.com/VictoriaMetrics/fastcache v1.12.1
8181
github.com/cespare/xxhash/v2 v2.2.0
8282
github.com/google/go-cmp v0.6.0
83+
github.com/sercand/kuberesolver v2.4.0+incompatible
8384
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
8485
google.golang.org/protobuf v1.31.0
8586
)
@@ -196,7 +197,6 @@ require (
196197
github.com/rs/cors v1.9.0 // indirect
197198
github.com/rs/xid v1.5.0 // indirect
198199
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
199-
github.com/sercand/kuberesolver v2.4.0+incompatible // indirect
200200
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
201201
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
202202
github.com/sirupsen/logrus v1.9.3 // indirect

pkg/tracing/tracing.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/go-kit/log/level"
1010
"github.com/pkg/errors"
11+
"github.com/sercand/kuberesolver"
1112
"github.com/weaveworks/common/tracing"
1213
"go.opentelemetry.io/contrib/propagators/aws/xray"
1314
"google.golang.org/grpc/credentials"
@@ -41,6 +42,7 @@ type Otel struct {
4142
OtlpEndpoint string `yaml:"otlp_endpoint" json:"otlp_endpoint"`
4243
ExporterType string `yaml:"exporter_type" json:"exporter_type"`
4344
SampleRatio float64 `yaml:"sample_ratio" json:"sample_ratio"`
45+
RoundRobin bool `yaml:"round_robin" json:"round_robin"`
4446
TLSEnabled bool `yaml:"tls_enabled"`
4547
TLS tls.ClientConfig `yaml:"tls"`
4648
ExtraDetectors []resource.Detector `yaml:"-"`
@@ -55,6 +57,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
5557
f.StringVar(&c.Otel.OtlpEndpoint, p+".otel.otlp-endpoint", "", "otl collector endpoint that the driver will use to send spans.")
5658
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.`")
5759
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.")
60+
f.BoolVar(&c.Otel.RoundRobin, p+".otel.round-robin", false, "If enabled, use round_robin gRPC load balancing policy. By default, use pick_first policy. For more details, please refer to https://github.com/grpc/grpc/blob/master/doc/load-balancing.md#load-balancing-policies.")
5861
c.Otel.TLS.RegisterFlagsWithPrefix(p+".otel.tls", f)
5962
}
6063

@@ -91,15 +94,23 @@ func SetupTracing(ctx context.Context, name string, c Config) (func(context.Cont
9194
level.Warn(util_log.Logger).Log("msg", "DEPRECATED: otel.otlp and otel.oltp both set, using otel.otlp because otel.oltp is deprecated")
9295
}
9396

97+
endpoint := c.Otel.OtlpEndpoint
98+
if (c.Otel.OtlpEndpoint == "") && (len(c.Otel.OltpEndpoint) > 0) {
99+
level.Warn(util_log.Logger).Log("msg", "DEPRECATED: otel.oltp is deprecated use otel.otlp")
100+
endpoint = c.Otel.OltpEndpoint
101+
}
94102
options := []otlptracegrpc.Option{
95-
otlptracegrpc.WithEndpoint(c.Otel.OtlpEndpoint),
103+
otlptracegrpc.WithEndpoint(endpoint),
104+
}
105+
// Following https://github.com/sercand/kuberesolver/blob/master/builder.go#L96.
106+
if strings.HasPrefix(endpoint, "kubernetes://") {
107+
// Registers the kuberesolver which resolves endpoint with prefix kubernetes://
108+
// as kubernetes service endpoint addresses.
109+
kuberesolver.RegisterInCluster()
96110
}
97111

98-
if (c.Otel.OtlpEndpoint == "") && (len(c.Otel.OltpEndpoint) > 0) {
99-
level.Warn(util_log.Logger).Log("msg", "DEPRECATED: otel.oltp is deprecated use otel.otlp")
100-
options = []otlptracegrpc.Option{
101-
otlptracegrpc.WithEndpoint(c.Otel.OltpEndpoint),
102-
}
112+
if c.Otel.RoundRobin {
113+
options = append(options, otlptracegrpc.WithServiceConfig(`{"loadBalancingPolicy": "round_robin"}`))
103114
}
104115

105116
if c.Otel.TLSEnabled {

0 commit comments

Comments
 (0)