internal.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. // AddGlobalServerOptions adds an array of ServerOption that will be
  63. // effective globally for newly created servers. The priority will be: 1.
  64. // user-provided; 2. this method; 3. default values.
  65. AddGlobalServerOptions interface{} // func(opt ...ServerOption)
  66. // ClearGlobalServerOptions clears the array of extra ServerOption. This
  67. // method is useful in testing and benchmarking.
  68. ClearGlobalServerOptions func()
  69. // AddGlobalDialOptions adds an array of DialOption that will be effective
  70. // globally for newly created client channels. The priority will be: 1.
  71. // user-provided; 2. this method; 3. default values.
  72. AddGlobalDialOptions interface{} // func(opt ...DialOption)
  73. // ClearGlobalDialOptions clears the array of extra DialOption. This
  74. // method is useful in testing and benchmarking.
  75. ClearGlobalDialOptions func()
  76. // JoinServerOptions combines the server options passed as arguments into a
  77. // single server option.
  78. JoinServerOptions interface{} // func(...grpc.ServerOption) grpc.ServerOption
  79. // WithBinaryLogger returns a DialOption that specifies the binary logger
  80. // for a ClientConn.
  81. WithBinaryLogger interface{} // func(binarylog.Logger) grpc.DialOption
  82. // BinaryLogger returns a ServerOption that can set the binary logger for a
  83. // server.
  84. BinaryLogger interface{} // func(binarylog.Logger) grpc.ServerOption
  85. // NewXDSResolverWithConfigForTesting creates a new xds resolver builder using
  86. // the provided xds bootstrap config instead of the global configuration from
  87. // the supported environment variables. The resolver.Builder is meant to be
  88. // used in conjunction with the grpc.WithResolvers DialOption.
  89. //
  90. // Testing Only
  91. //
  92. // This function should ONLY be used for testing and may not work with some
  93. // other features, including the CSDS service.
  94. NewXDSResolverWithConfigForTesting interface{} // func([]byte) (resolver.Builder, error)
  95. // RegisterRLSClusterSpecifierPluginForTesting registers the RLS Cluster
  96. // Specifier Plugin for testing purposes, regardless of the XDSRLS environment
  97. // variable.
  98. //
  99. // TODO: Remove this function once the RLS env var is removed.
  100. RegisterRLSClusterSpecifierPluginForTesting func()
  101. // UnregisterRLSClusterSpecifierPluginForTesting unregisters the RLS Cluster
  102. // Specifier Plugin for testing purposes. This is needed because there is no way
  103. // to unregister the RLS Cluster Specifier Plugin after registering it solely
  104. // for testing purposes using RegisterRLSClusterSpecifierPluginForTesting().
  105. //
  106. // TODO: Remove this function once the RLS env var is removed.
  107. UnregisterRLSClusterSpecifierPluginForTesting func()
  108. // RegisterRBACHTTPFilterForTesting registers the RBAC HTTP Filter for testing
  109. // purposes, regardless of the RBAC environment variable.
  110. //
  111. // TODO: Remove this function once the RBAC env var is removed.
  112. RegisterRBACHTTPFilterForTesting func()
  113. // UnregisterRBACHTTPFilterForTesting unregisters the RBAC HTTP Filter for
  114. // testing purposes. This is needed because there is no way to unregister the
  115. // HTTP Filter after registering it solely for testing purposes using
  116. // RegisterRBACHTTPFilterForTesting().
  117. //
  118. // TODO: Remove this function once the RBAC env var is removed.
  119. UnregisterRBACHTTPFilterForTesting func()
  120. )
  121. // HealthChecker defines the signature of the client-side LB channel health checking function.
  122. //
  123. // The implementation is expected to create a health checking RPC stream by
  124. // calling newStream(), watch for the health status of serviceName, and report
  125. // it's health back by calling setConnectivityState().
  126. //
  127. // The health checking protocol is defined at:
  128. // https://github.com/grpc/grpc/blob/master/doc/health-checking.md
  129. type HealthChecker func(ctx context.Context, newStream func(string) (interface{}, error), setConnectivityState func(connectivity.State, error), serviceName string) error
  130. const (
  131. // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode.
  132. CredsBundleModeFallback = "fallback"
  133. // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer
  134. // mode.
  135. CredsBundleModeBalancer = "balancer"
  136. // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode
  137. // that supports backend returned by grpclb balancer.
  138. CredsBundleModeBackendFromBalancer = "backend-from-balancer"
  139. )
  140. // RLSLoadBalancingPolicyName is the name of the RLS LB policy.
  141. //
  142. // It currently has an experimental suffix which would be removed once
  143. // end-to-end testing of the policy is completed.
  144. const RLSLoadBalancingPolicyName = "rls_experimental"