internal.go (8399B)
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 18 // Package internal contains gRPC-internal code, to avoid polluting 19 // the godoc of the top-level grpc package. It must not import any grpc 20 // symbols to avoid circular dependencies. 21 package internal 22 23 import ( 24 "context" 25 "time" 26 27 "google.golang.org/grpc/connectivity" 28 "google.golang.org/grpc/serviceconfig" 29 ) 30 31 var ( 32 // WithHealthCheckFunc is set by dialoptions.go 33 WithHealthCheckFunc interface{} // func (HealthChecker) DialOption 34 // HealthCheckFunc is used to provide client-side LB channel health checking 35 HealthCheckFunc HealthChecker 36 // BalancerUnregister is exported by package balancer to unregister a balancer. 37 BalancerUnregister func(name string) 38 // KeepaliveMinPingTime is the minimum ping interval. This must be 10s by 39 // default, but tests may wish to set it lower for convenience. 40 KeepaliveMinPingTime = 10 * time.Second 41 // ParseServiceConfig parses a JSON representation of the service config. 42 ParseServiceConfig interface{} // 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 interface{} // 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 interface{} // 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 interface{} // 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 CanonicalString interface{} // func (codes.Code) string 64 // DrainServerTransports initiates a graceful close of existing connections 65 // on a gRPC server accepted on the provided listener address. An 66 // xDS-enabled server invokes this method on a grpc.Server when a particular 67 // listener moves to "not-serving" mode. 68 DrainServerTransports interface{} // func(*grpc.Server, string) 69 // AddGlobalServerOptions adds an array of ServerOption that will be 70 // effective globally for newly created servers. The priority will be: 1. 71 // user-provided; 2. this method; 3. default values. 72 AddGlobalServerOptions interface{} // func(opt ...ServerOption) 73 // ClearGlobalServerOptions clears the array of extra ServerOption. This 74 // method is useful in testing and benchmarking. 75 ClearGlobalServerOptions func() 76 // AddGlobalDialOptions adds an array of DialOption that will be effective 77 // globally for newly created client channels. The priority will be: 1. 78 // user-provided; 2. this method; 3. default values. 79 AddGlobalDialOptions interface{} // func(opt ...DialOption) 80 // DisableGlobalDialOptions returns a DialOption that prevents the 81 // ClientConn from applying the global DialOptions (set via 82 // AddGlobalDialOptions). 83 DisableGlobalDialOptions interface{} // func() grpc.DialOption 84 // ClearGlobalDialOptions clears the array of extra DialOption. This 85 // method is useful in testing and benchmarking. 86 ClearGlobalDialOptions func() 87 // JoinDialOptions combines the dial options passed as arguments into a 88 // single dial option. 89 JoinDialOptions interface{} // func(...grpc.DialOption) grpc.DialOption 90 // JoinServerOptions combines the server options passed as arguments into a 91 // single server option. 92 JoinServerOptions interface{} // func(...grpc.ServerOption) grpc.ServerOption 93 94 // WithBinaryLogger returns a DialOption that specifies the binary logger 95 // for a ClientConn. 96 WithBinaryLogger interface{} // func(binarylog.Logger) grpc.DialOption 97 // BinaryLogger returns a ServerOption that can set the binary logger for a 98 // server. 99 BinaryLogger interface{} // func(binarylog.Logger) grpc.ServerOption 100 101 // NewXDSResolverWithConfigForTesting creates a new xds resolver builder using 102 // the provided xds bootstrap config instead of the global configuration from 103 // the supported environment variables. The resolver.Builder is meant to be 104 // used in conjunction with the grpc.WithResolvers DialOption. 105 // 106 // Testing Only 107 // 108 // This function should ONLY be used for testing and may not work with some 109 // other features, including the CSDS service. 110 NewXDSResolverWithConfigForTesting interface{} // func([]byte) (resolver.Builder, error) 111 112 // RegisterRLSClusterSpecifierPluginForTesting registers the RLS Cluster 113 // Specifier Plugin for testing purposes, regardless of the XDSRLS environment 114 // variable. 115 // 116 // TODO: Remove this function once the RLS env var is removed. 117 RegisterRLSClusterSpecifierPluginForTesting func() 118 119 // UnregisterRLSClusterSpecifierPluginForTesting unregisters the RLS Cluster 120 // Specifier Plugin for testing purposes. This is needed because there is no way 121 // to unregister the RLS Cluster Specifier Plugin after registering it solely 122 // for testing purposes using RegisterRLSClusterSpecifierPluginForTesting(). 123 // 124 // TODO: Remove this function once the RLS env var is removed. 125 UnregisterRLSClusterSpecifierPluginForTesting func() 126 127 // RegisterRBACHTTPFilterForTesting registers the RBAC HTTP Filter for testing 128 // purposes, regardless of the RBAC environment variable. 129 // 130 // TODO: Remove this function once the RBAC env var is removed. 131 RegisterRBACHTTPFilterForTesting func() 132 133 // UnregisterRBACHTTPFilterForTesting unregisters the RBAC HTTP Filter for 134 // testing purposes. This is needed because there is no way to unregister the 135 // HTTP Filter after registering it solely for testing purposes using 136 // RegisterRBACHTTPFilterForTesting(). 137 // 138 // TODO: Remove this function once the RBAC env var is removed. 139 UnregisterRBACHTTPFilterForTesting func() 140 141 // ORCAAllowAnyMinReportingInterval is for examples/orca use ONLY. 142 ORCAAllowAnyMinReportingInterval interface{} // func(so *orca.ServiceOptions) 143 ) 144 145 // HealthChecker defines the signature of the client-side LB channel health checking function. 146 // 147 // The implementation is expected to create a health checking RPC stream by 148 // calling newStream(), watch for the health status of serviceName, and report 149 // it's health back by calling setConnectivityState(). 150 // 151 // The health checking protocol is defined at: 152 // https://github.com/grpc/grpc/blob/master/doc/health-checking.md 153 type HealthChecker func(ctx context.Context, newStream func(string) (interface{}, error), setConnectivityState func(connectivity.State, error), serviceName string) error 154 155 const ( 156 // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode. 157 CredsBundleModeFallback = "fallback" 158 // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer 159 // mode. 160 CredsBundleModeBalancer = "balancer" 161 // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode 162 // that supports backend returned by grpclb balancer. 163 CredsBundleModeBackendFromBalancer = "backend-from-balancer" 164 ) 165 166 // RLSLoadBalancingPolicyName is the name of the RLS LB policy. 167 // 168 // It currently has an experimental suffix which would be removed once 169 // end-to-end testing of the policy is completed. 170 const RLSLoadBalancingPolicyName = "rls_experimental"