/
dialservice.go
35 lines (32 loc) 路 1.06 KB
/
dialservice.go
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
package cloudrunner
import (
"context"
"fmt"
"go.einride.tech/cloudrunner/cloudclient"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
)
// DialService dials another service using the default service account's Google ID Token authentication.
func DialService(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
run, ok := getRunContext(ctx)
if !ok {
return nil, fmt.Errorf("cloudrunner.DialService %s: must be called with a context from cloudrunner.Run", target)
}
return cloudclient.DialService(
ctx,
target,
append(
[]grpc.DialOption{
grpc.WithDefaultServiceConfig(run.config.Client.AsServiceConfigJSON()),
grpc.WithChainUnaryInterceptor(
//nolint:staticcheck // package is deprecated, replace when possible
otelgrpc.UnaryClientInterceptor(),
run.metricMiddleware.GRPCUnaryClientInterceptor,
run.requestLoggerMiddleware.GRPCUnaryClientInterceptor,
run.clientMiddleware.GRPCUnaryClientInterceptor,
),
},
opts...,
)...,
)
}