-
Notifications
You must be signed in to change notification settings - Fork 2
/
dialservice.go
33 lines (30 loc) · 973 Bytes
/
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
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.WithStatsHandler(otelgrpc.NewClientHandler()),
grpc.WithDefaultServiceConfig(run.config.Client.AsServiceConfigJSON()),
grpc.WithChainUnaryInterceptor(
run.requestLoggerMiddleware.GRPCUnaryClientInterceptor,
run.clientMiddleware.GRPCUnaryClientInterceptor,
),
},
opts...,
)...,
)
}