internal.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // ParseServiceConfig parses a JSON representation of the service config.
  38. ParseServiceConfig interface{} // func(string) *serviceconfig.ParseResult
  39. // EqualServiceConfigForTesting is for testing service config generation and
  40. // parsing. Both a and b should be returned by ParseServiceConfig.
  41. // This function compares the config without rawJSON stripped, in case the
  42. // there's difference in white space.
  43. EqualServiceConfigForTesting func(a, b serviceconfig.Config) bool
  44. // GetCertificateProviderBuilder returns the registered builder for the
  45. // given name. This is set by package certprovider for use from xDS
  46. // bootstrap code while parsing certificate provider configs in the
  47. // bootstrap file.
  48. GetCertificateProviderBuilder interface{} // func(string) certprovider.Builder
  49. // GetXDSHandshakeInfoForTesting returns a pointer to the xds.HandshakeInfo
  50. // stored in the passed in attributes. This is set by
  51. // credentials/xds/xds.go.
  52. GetXDSHandshakeInfoForTesting interface{} // func (*attributes.Attributes) *xds.HandshakeInfo
  53. // GetServerCredentials returns the transport credentials configured on a
  54. // gRPC server. An xDS-enabled server needs to know what type of credentials
  55. // is configured on the underlying gRPC server. This is set by server.go.
  56. GetServerCredentials interface{} // func (*grpc.Server) credentials.TransportCredentials
  57. // DrainServerTransports initiates a graceful close of existing connections
  58. // on a gRPC server accepted on the provided listener address. An
  59. // xDS-enabled server invokes this method on a grpc.Server when a particular
  60. // listener moves to "not-serving" mode.
  61. DrainServerTransports interface{} // func(*grpc.Server, string)
  62. )
  63. // HealthChecker defines the signature of the client-side LB channel health checking function.
  64. //
  65. // The implementation is expected to create a health checking RPC stream by
  66. // calling newStream(), watch for the health status of serviceName, and report
  67. // it's health back by calling setConnectivityState().
  68. //
  69. // The health checking protocol is defined at:
  70. // https://github.com/grpc/grpc/blob/master/doc/health-checking.md
  71. type HealthChecker func(ctx context.Context, newStream func(string) (interface{}, error), setConnectivityState func(connectivity.State, error), serviceName string) error
  72. const (
  73. // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode.
  74. CredsBundleModeFallback = "fallback"
  75. // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer
  76. // mode.
  77. CredsBundleModeBalancer = "balancer"
  78. // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode
  79. // that supports backend returned by grpclb balancer.
  80. CredsBundleModeBackendFromBalancer = "backend-from-balancer"
  81. )
  82. // RLSLoadBalancingPolicyName is the name of the RLS LB policy.
  83. //
  84. // It currently has an experimental suffix which would be removed once
  85. // end-to-end testing of the policy is completed.
  86. const RLSLoadBalancingPolicyName = "rls_experimental"