internal.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 any // 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. // KeepaliveMinServerPingTime is the minimum ping interval for servers.
  38. // This must be 1s by default, but tests may wish to set it lower for
  39. // convenience.
  40. KeepaliveMinServerPingTime = time.Second
  41. // ParseServiceConfig parses a JSON representation of the service config.
  42. ParseServiceConfig any // func(string) *serviceconfig.ParseResult
  43. // EqualServiceConfigForTesting is for testing service config generation and
  44. // parsing. Both a and b should be returned by ParseServiceConfig.
  45. // This function compares the config without rawJSON stripped, in case the
  46. // there's difference in white space.
  47. EqualServiceConfigForTesting func(a, b serviceconfig.Config) bool
  48. // GetCertificateProviderBuilder returns the registered builder for the
  49. // given name. This is set by package certprovider for use from xDS
  50. // bootstrap code while parsing certificate provider configs in the
  51. // bootstrap file.
  52. GetCertificateProviderBuilder any // func(string) certprovider.Builder
  53. // GetXDSHandshakeInfoForTesting returns a pointer to the xds.HandshakeInfo
  54. // stored in the passed in attributes. This is set by
  55. // credentials/xds/xds.go.
  56. GetXDSHandshakeInfoForTesting any // func (*attributes.Attributes) *xds.HandshakeInfo
  57. // GetServerCredentials returns the transport credentials configured on a
  58. // gRPC server. An xDS-enabled server needs to know what type of credentials
  59. // is configured on the underlying gRPC server. This is set by server.go.
  60. GetServerCredentials any // func (*grpc.Server) credentials.TransportCredentials
  61. // CanonicalString returns the canonical string of the code defined here:
  62. // https://github.com/grpc/grpc/blob/master/doc/statuscodes.md.
  63. //
  64. // This is used in the 1.0 release of gcp/observability, and thus must not be
  65. // deleted or changed.
  66. CanonicalString any // func (codes.Code) string
  67. // DrainServerTransports initiates a graceful close of existing connections
  68. // on a gRPC server accepted on the provided listener address. An
  69. // xDS-enabled server invokes this method on a grpc.Server when a particular
  70. // listener moves to "not-serving" mode.
  71. DrainServerTransports any // func(*grpc.Server, string)
  72. // IsRegisteredMethod returns whether the passed in method is registered as
  73. // a method on the server.
  74. IsRegisteredMethod any // func(*grpc.Server, string) bool
  75. // ServerFromContext returns the server from the context.
  76. ServerFromContext any // func(context.Context) *grpc.Server
  77. // AddGlobalServerOptions adds an array of ServerOption that will be
  78. // effective globally for newly created servers. The priority will be: 1.
  79. // user-provided; 2. this method; 3. default values.
  80. //
  81. // This is used in the 1.0 release of gcp/observability, and thus must not be
  82. // deleted or changed.
  83. AddGlobalServerOptions any // func(opt ...ServerOption)
  84. // ClearGlobalServerOptions clears the array of extra ServerOption. This
  85. // method is useful in testing and benchmarking.
  86. //
  87. // This is used in the 1.0 release of gcp/observability, and thus must not be
  88. // deleted or changed.
  89. ClearGlobalServerOptions func()
  90. // AddGlobalDialOptions adds an array of DialOption that will be effective
  91. // globally for newly created client channels. The priority will be: 1.
  92. // user-provided; 2. this method; 3. default values.
  93. //
  94. // This is used in the 1.0 release of gcp/observability, and thus must not be
  95. // deleted or changed.
  96. AddGlobalDialOptions any // func(opt ...DialOption)
  97. // DisableGlobalDialOptions returns a DialOption that prevents the
  98. // ClientConn from applying the global DialOptions (set via
  99. // AddGlobalDialOptions).
  100. //
  101. // This is used in the 1.0 release of gcp/observability, and thus must not be
  102. // deleted or changed.
  103. DisableGlobalDialOptions any // func() grpc.DialOption
  104. // ClearGlobalDialOptions clears the array of extra DialOption. This
  105. // method is useful in testing and benchmarking.
  106. //
  107. // This is used in the 1.0 release of gcp/observability, and thus must not be
  108. // deleted or changed.
  109. ClearGlobalDialOptions func()
  110. // JoinDialOptions combines the dial options passed as arguments into a
  111. // single dial option.
  112. JoinDialOptions any // func(...grpc.DialOption) grpc.DialOption
  113. // JoinServerOptions combines the server options passed as arguments into a
  114. // single server option.
  115. JoinServerOptions any // func(...grpc.ServerOption) grpc.ServerOption
  116. // WithBinaryLogger returns a DialOption that specifies the binary logger
  117. // for a ClientConn.
  118. //
  119. // This is used in the 1.0 release of gcp/observability, and thus must not be
  120. // deleted or changed.
  121. WithBinaryLogger any // func(binarylog.Logger) grpc.DialOption
  122. // BinaryLogger returns a ServerOption that can set the binary logger for a
  123. // server.
  124. //
  125. // This is used in the 1.0 release of gcp/observability, and thus must not be
  126. // deleted or changed.
  127. BinaryLogger any // func(binarylog.Logger) grpc.ServerOption
  128. // SubscribeToConnectivityStateChanges adds a grpcsync.Subscriber to a provided grpc.ClientConn
  129. SubscribeToConnectivityStateChanges any // func(*grpc.ClientConn, grpcsync.Subscriber)
  130. // NewXDSResolverWithConfigForTesting creates a new xds resolver builder using
  131. // the provided xds bootstrap config instead of the global configuration from
  132. // the supported environment variables. The resolver.Builder is meant to be
  133. // used in conjunction with the grpc.WithResolvers DialOption.
  134. //
  135. // Testing Only
  136. //
  137. // This function should ONLY be used for testing and may not work with some
  138. // other features, including the CSDS service.
  139. NewXDSResolverWithConfigForTesting any // func([]byte) (resolver.Builder, error)
  140. // RegisterRLSClusterSpecifierPluginForTesting registers the RLS Cluster
  141. // Specifier Plugin for testing purposes, regardless of the XDSRLS environment
  142. // variable.
  143. //
  144. // TODO: Remove this function once the RLS env var is removed.
  145. RegisterRLSClusterSpecifierPluginForTesting func()
  146. // UnregisterRLSClusterSpecifierPluginForTesting unregisters the RLS Cluster
  147. // Specifier Plugin for testing purposes. This is needed because there is no way
  148. // to unregister the RLS Cluster Specifier Plugin after registering it solely
  149. // for testing purposes using RegisterRLSClusterSpecifierPluginForTesting().
  150. //
  151. // TODO: Remove this function once the RLS env var is removed.
  152. UnregisterRLSClusterSpecifierPluginForTesting func()
  153. // RegisterRBACHTTPFilterForTesting registers the RBAC HTTP Filter for testing
  154. // purposes, regardless of the RBAC environment variable.
  155. //
  156. // TODO: Remove this function once the RBAC env var is removed.
  157. RegisterRBACHTTPFilterForTesting func()
  158. // UnregisterRBACHTTPFilterForTesting unregisters the RBAC HTTP Filter for
  159. // testing purposes. This is needed because there is no way to unregister the
  160. // HTTP Filter after registering it solely for testing purposes using
  161. // RegisterRBACHTTPFilterForTesting().
  162. //
  163. // TODO: Remove this function once the RBAC env var is removed.
  164. UnregisterRBACHTTPFilterForTesting func()
  165. // ORCAAllowAnyMinReportingInterval is for examples/orca use ONLY.
  166. ORCAAllowAnyMinReportingInterval any // func(so *orca.ServiceOptions)
  167. // GRPCResolverSchemeExtraMetadata determines when gRPC will add extra
  168. // metadata to RPCs.
  169. GRPCResolverSchemeExtraMetadata string = "xds"
  170. // EnterIdleModeForTesting gets the ClientConn to enter IDLE mode.
  171. EnterIdleModeForTesting any // func(*grpc.ClientConn)
  172. // ExitIdleModeForTesting gets the ClientConn to exit IDLE mode.
  173. ExitIdleModeForTesting any // func(*grpc.ClientConn) error
  174. ChannelzTurnOffForTesting func()
  175. )
  176. // HealthChecker defines the signature of the client-side LB channel health checking function.
  177. //
  178. // The implementation is expected to create a health checking RPC stream by
  179. // calling newStream(), watch for the health status of serviceName, and report
  180. // it's health back by calling setConnectivityState().
  181. //
  182. // The health checking protocol is defined at:
  183. // https://github.com/grpc/grpc/blob/master/doc/health-checking.md
  184. type HealthChecker func(ctx context.Context, newStream func(string) (any, error), setConnectivityState func(connectivity.State, error), serviceName string) error
  185. const (
  186. // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode.
  187. CredsBundleModeFallback = "fallback"
  188. // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer
  189. // mode.
  190. CredsBundleModeBalancer = "balancer"
  191. // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode
  192. // that supports backend returned by grpclb balancer.
  193. CredsBundleModeBackendFromBalancer = "backend-from-balancer"
  194. )
  195. // RLSLoadBalancingPolicyName is the name of the RLS LB policy.
  196. //
  197. // It currently has an experimental suffix which would be removed once
  198. // end-to-end testing of the policy is completed.
  199. const RLSLoadBalancingPolicyName = "rls_experimental"