forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
75 lines (64 loc) · 2.45 KB
/
client.go
File metadata and controls
75 lines (64 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package client
import (
"flag"
"io"
"time"
"github.com/grafana/dskit/grpcclient"
"github.com/grafana/dskit/middleware"
ring_client "github.com/grafana/dskit/ring/client"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/grafana/tempo/pkg/tempopb"
)
// Config for an ingester client.
type Config struct {
PoolConfig ring_client.PoolConfig `yaml:"pool_config,omitempty"`
RemoteTimeout time.Duration `yaml:"remote_timeout,omitempty"`
GRPCClientConfig grpcclient.Config `yaml:"grpc_client_config"`
}
type Client struct {
tempopb.PusherClient
tempopb.QuerierClient
grpc_health_v1.HealthClient
io.Closer
}
// RegisterFlags registers flags.
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
cfg.GRPCClientConfig.RegisterFlagsWithPrefix("ingester.client", f)
f.DurationVar(&cfg.PoolConfig.HealthCheckTimeout, "ingester.client.healthcheck-timeout", 1*time.Second, "Timeout for healthcheck rpcs.")
f.DurationVar(&cfg.PoolConfig.CheckInterval, "ingester.client.healthcheck-interval", 15*time.Second, "Interval to healthcheck ingesters")
f.BoolVar(&cfg.PoolConfig.HealthCheckEnabled, "ingester.client.healthcheck-enabled", true, "Healthcheck ingesters.")
f.DurationVar(&cfg.RemoteTimeout, "ingester.client.timeout", 5*time.Second, "Timeout for ingester client RPCs.")
}
// New returns a new ingester client.
func New(addr string, cfg Config) (*Client, error) {
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
}
instrumentationOpts, err := cfg.GRPCClientConfig.DialOption(instrumentation())
if err != nil {
return nil, err
}
opts = append(opts, instrumentationOpts...)
conn, err := grpc.Dial(addr, opts...)
if err != nil {
return nil, err
}
return &Client{
PusherClient: tempopb.NewPusherClient(conn),
QuerierClient: tempopb.NewQuerierClient(conn),
HealthClient: grpc_health_v1.NewHealthClient(conn),
Closer: conn,
}, nil
}
func instrumentation() ([]grpc.UnaryClientInterceptor, []grpc.StreamClientInterceptor, middleware.InvalidClusterValidationReporter) {
return []grpc.UnaryClientInterceptor{
middleware.ClientUserHeaderInterceptor,
}, []grpc.StreamClientInterceptor{
middleware.StreamClientUserHeaderInterceptor,
},
middleware.NoOpInvalidClusterValidationReporter
}