Scott Baker | 2d89798 | 2019-09-24 11:50:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 gRPC authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | // Package internal contains gRPC-internal code, to avoid polluting |
| 19 | // the godoc of the top-level grpc package. It must not import any grpc |
| 20 | // symbols to avoid circular dependencies. |
| 21 | package internal |
| 22 | |
| 23 | import ( |
| 24 | "context" |
| 25 | "time" |
Scott Baker | 8487c5d | 2019-10-18 12:49:46 -0700 | [diff] [blame] | 26 | |
| 27 | "google.golang.org/grpc/connectivity" |
Scott Baker | 2d89798 | 2019-09-24 11:50:08 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | var ( |
| 31 | // WithResolverBuilder is exported by dialoptions.go |
| 32 | WithResolverBuilder interface{} // func (resolver.Builder) grpc.DialOption |
| 33 | // WithHealthCheckFunc is not exported by dialoptions.go |
| 34 | WithHealthCheckFunc interface{} // func (HealthChecker) DialOption |
| 35 | // HealthCheckFunc is used to provide client-side LB channel health checking |
| 36 | HealthCheckFunc HealthChecker |
| 37 | // BalancerUnregister is exported by package balancer to unregister a balancer. |
| 38 | BalancerUnregister func(name string) |
| 39 | // KeepaliveMinPingTime is the minimum ping interval. This must be 10s by |
| 40 | // default, but tests may wish to set it lower for convenience. |
| 41 | KeepaliveMinPingTime = 10 * time.Second |
Scott Baker | 8487c5d | 2019-10-18 12:49:46 -0700 | [diff] [blame] | 42 | // ParseServiceConfig is a function to parse JSON service configs into |
| 43 | // opaque data structures. |
| 44 | ParseServiceConfig func(sc string) (interface{}, error) |
| 45 | // StatusRawProto is exported by status/status.go. This func returns a |
| 46 | // pointer to the wrapped Status proto for a given status.Status without a |
| 47 | // call to proto.Clone(). The returned Status proto should not be mutated by |
| 48 | // the caller. |
| 49 | StatusRawProto interface{} // func (*status.Status) *spb.Status |
Scott Baker | 2d89798 | 2019-09-24 11:50:08 -0700 | [diff] [blame] | 50 | ) |
| 51 | |
| 52 | // HealthChecker defines the signature of the client-side LB channel health checking function. |
Scott Baker | 8487c5d | 2019-10-18 12:49:46 -0700 | [diff] [blame] | 53 | // |
| 54 | // The implementation is expected to create a health checking RPC stream by |
| 55 | // calling newStream(), watch for the health status of serviceName, and report |
| 56 | // it's health back by calling setConnectivityState(). |
| 57 | // |
| 58 | // The health checking protocol is defined at: |
| 59 | // https://github.com/grpc/grpc/blob/master/doc/health-checking.md |
| 60 | type HealthChecker func(ctx context.Context, newStream func(string) (interface{}, error), setConnectivityState func(connectivity.State), serviceName string) error |
Scott Baker | 2d89798 | 2019-09-24 11:50:08 -0700 | [diff] [blame] | 61 | |
| 62 | const ( |
| 63 | // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode. |
| 64 | CredsBundleModeFallback = "fallback" |
| 65 | // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer |
| 66 | // mode. |
| 67 | CredsBundleModeBalancer = "balancer" |
| 68 | // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode |
| 69 | // that supports backend returned by grpclb balancer. |
| 70 | CredsBundleModeBackendFromBalancer = "backend-from-balancer" |
| 71 | ) |