internal.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Package internal contains gRPC-internal code, to avoid polluting
  18. // the godoc of the top-level grpc package. It must not import any grpc
  19. // symbols to avoid circular dependencies.
  20. package internal
  21. import (
  22. "context"
  23. "time"
  24. "google.golang.org/grpc/connectivity"
  25. "google.golang.org/grpc/serviceconfig"
  26. )
  27. var (
  28. // WithHealthCheckFunc is set by dialoptions.go
  29. WithHealthCheckFunc interface{} // func (HealthChecker) DialOption
  30. // HealthCheckFunc is used to provide client-side LB channel health checking
  31. HealthCheckFunc HealthChecker
  32. // BalancerUnregister is exported by package balancer to unregister a balancer.
  33. BalancerUnregister func(name string)
  34. // KeepaliveMinPingTime is the minimum ping interval. This must be 10s by
  35. // default, but tests may wish to set it lower for convenience.
  36. KeepaliveMinPingTime = 10 * time.Second
  37. // NewRequestInfoContext creates a new context based on the argument context attaching
  38. // the passed in RequestInfo to the new context.
  39. NewRequestInfoContext interface{} // func(context.Context, credentials.RequestInfo) context.Context
  40. // NewClientHandshakeInfoContext returns a copy of the input context with
  41. // the passed in ClientHandshakeInfo struct added to it.
  42. NewClientHandshakeInfoContext interface{} // func(context.Context, credentials.ClientHandshakeInfo) context.Context
  43. // ParseServiceConfigForTesting is for creating a fake
  44. // ClientConn for resolver testing only
  45. ParseServiceConfigForTesting interface{} // func(string) *serviceconfig.ParseResult
  46. // EqualServiceConfigForTesting is for testing service config generation and
  47. // parsing. Both a and b should be returned by ParseServiceConfigForTesting.
  48. // This function compares the config without rawJSON stripped, in case the
  49. // there's difference in white space.
  50. EqualServiceConfigForTesting func(a, b serviceconfig.Config) bool
  51. )
  52. // HealthChecker defines the signature of the client-side LB channel health checking function.
  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, error), serviceName string) error
  61. const (
  62. // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode.
  63. CredsBundleModeFallback = "fallback"
  64. // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer
  65. // mode.
  66. CredsBundleModeBalancer = "balancer"
  67. // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode
  68. // that supports backend returned by grpclb balancer.
  69. CredsBundleModeBackendFromBalancer = "backend-from-balancer"
  70. )