internal.go 9.0 KB

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