internal.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. // AddGlobalServerOptions adds an array of ServerOption that will be
  73. // effective globally for newly created servers. The priority will be: 1.
  74. // user-provided; 2. this method; 3. default values.
  75. //
  76. // This is used in the 1.0 release of gcp/observability, and thus must not be
  77. // deleted or changed.
  78. AddGlobalServerOptions any // func(opt ...ServerOption)
  79. // ClearGlobalServerOptions clears the array of extra ServerOption. This
  80. // method is useful in testing and benchmarking.
  81. //
  82. // This is used in the 1.0 release of gcp/observability, and thus must not be
  83. // deleted or changed.
  84. ClearGlobalServerOptions func()
  85. // AddGlobalDialOptions adds an array of DialOption that will be effective
  86. // globally for newly created client channels. The priority will be: 1.
  87. // user-provided; 2. this method; 3. default values.
  88. //
  89. // This is used in the 1.0 release of gcp/observability, and thus must not be
  90. // deleted or changed.
  91. AddGlobalDialOptions any // func(opt ...DialOption)
  92. // DisableGlobalDialOptions returns a DialOption that prevents the
  93. // ClientConn from applying the global DialOptions (set via
  94. // AddGlobalDialOptions).
  95. //
  96. // This is used in the 1.0 release of gcp/observability, and thus must not be
  97. // deleted or changed.
  98. DisableGlobalDialOptions any // func() grpc.DialOption
  99. // ClearGlobalDialOptions clears the array of extra DialOption. This
  100. // method is useful in testing and benchmarking.
  101. //
  102. // This is used in the 1.0 release of gcp/observability, and thus must not be
  103. // deleted or changed.
  104. ClearGlobalDialOptions func()
  105. // JoinDialOptions combines the dial options passed as arguments into a
  106. // single dial option.
  107. JoinDialOptions any // func(...grpc.DialOption) grpc.DialOption
  108. // JoinServerOptions combines the server options passed as arguments into a
  109. // single server option.
  110. JoinServerOptions any // func(...grpc.ServerOption) grpc.ServerOption
  111. // WithBinaryLogger returns a DialOption that specifies the binary logger
  112. // for a ClientConn.
  113. //
  114. // This is used in the 1.0 release of gcp/observability, and thus must not be
  115. // deleted or changed.
  116. WithBinaryLogger any // func(binarylog.Logger) grpc.DialOption
  117. // BinaryLogger returns a ServerOption that can set the binary logger for a
  118. // server.
  119. //
  120. // This is used in the 1.0 release of gcp/observability, and thus must not be
  121. // deleted or changed.
  122. BinaryLogger any // func(binarylog.Logger) grpc.ServerOption
  123. // SubscribeToConnectivityStateChanges adds a grpcsync.Subscriber to a provided grpc.ClientConn
  124. SubscribeToConnectivityStateChanges any // func(*grpc.ClientConn, grpcsync.Subscriber)
  125. // NewXDSResolverWithConfigForTesting creates a new xds resolver builder using
  126. // the provided xds bootstrap config instead of the global configuration from
  127. // the supported environment variables. The resolver.Builder is meant to be
  128. // used in conjunction with the grpc.WithResolvers DialOption.
  129. //
  130. // Testing Only
  131. //
  132. // This function should ONLY be used for testing and may not work with some
  133. // other features, including the CSDS service.
  134. NewXDSResolverWithConfigForTesting any // func([]byte) (resolver.Builder, error)
  135. // RegisterRLSClusterSpecifierPluginForTesting registers the RLS Cluster
  136. // Specifier Plugin for testing purposes, regardless of the XDSRLS environment
  137. // variable.
  138. //
  139. // TODO: Remove this function once the RLS env var is removed.
  140. RegisterRLSClusterSpecifierPluginForTesting func()
  141. // UnregisterRLSClusterSpecifierPluginForTesting unregisters the RLS Cluster
  142. // Specifier Plugin for testing purposes. This is needed because there is no way
  143. // to unregister the RLS Cluster Specifier Plugin after registering it solely
  144. // for testing purposes using RegisterRLSClusterSpecifierPluginForTesting().
  145. //
  146. // TODO: Remove this function once the RLS env var is removed.
  147. UnregisterRLSClusterSpecifierPluginForTesting func()
  148. // RegisterRBACHTTPFilterForTesting registers the RBAC HTTP Filter for testing
  149. // purposes, regardless of the RBAC environment variable.
  150. //
  151. // TODO: Remove this function once the RBAC env var is removed.
  152. RegisterRBACHTTPFilterForTesting func()
  153. // UnregisterRBACHTTPFilterForTesting unregisters the RBAC HTTP Filter for
  154. // testing purposes. This is needed because there is no way to unregister the
  155. // HTTP Filter after registering it solely for testing purposes using
  156. // RegisterRBACHTTPFilterForTesting().
  157. //
  158. // TODO: Remove this function once the RBAC env var is removed.
  159. UnregisterRBACHTTPFilterForTesting func()
  160. // ORCAAllowAnyMinReportingInterval is for examples/orca use ONLY.
  161. ORCAAllowAnyMinReportingInterval any // func(so *orca.ServiceOptions)
  162. // GRPCResolverSchemeExtraMetadata determines when gRPC will add extra
  163. // metadata to RPCs.
  164. GRPCResolverSchemeExtraMetadata string = "xds"
  165. // EnterIdleModeForTesting gets the ClientConn to enter IDLE mode.
  166. EnterIdleModeForTesting any // func(*grpc.ClientConn) error
  167. // ExitIdleModeForTesting gets the ClientConn to exit IDLE mode.
  168. ExitIdleModeForTesting any // func(*grpc.ClientConn) error
  169. )
  170. // HealthChecker defines the signature of the client-side LB channel health checking function.
  171. //
  172. // The implementation is expected to create a health checking RPC stream by
  173. // calling newStream(), watch for the health status of serviceName, and report
  174. // it's health back by calling setConnectivityState().
  175. //
  176. // The health checking protocol is defined at:
  177. // https://github.com/grpc/grpc/blob/master/doc/health-checking.md
  178. type HealthChecker func(ctx context.Context, newStream func(string) (any, error), setConnectivityState func(connectivity.State, error), serviceName string) error
  179. const (
  180. // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode.
  181. CredsBundleModeFallback = "fallback"
  182. // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer
  183. // mode.
  184. CredsBundleModeBalancer = "balancer"
  185. // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode
  186. // that supports backend returned by grpclb balancer.
  187. CredsBundleModeBackendFromBalancer = "backend-from-balancer"
  188. )
  189. // RLSLoadBalancingPolicyName is the name of the RLS LB policy.
  190. //
  191. // It currently has an experimental suffix which would be removed once
  192. // end-to-end testing of the policy is completed.
  193. const RLSLoadBalancingPolicyName = "rls_experimental"