khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 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 |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 41 | // ParseServiceConfig parses a JSON representation of the service config. |
| 42 | ParseServiceConfig interface{} // func(string) *serviceconfig.ParseResult |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 43 | // EqualServiceConfigForTesting is for testing service config generation and |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 44 | // parsing. Both a and b should be returned by ParseServiceConfig. |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 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 |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 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 interface{} // func (codes.Code) string |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 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 interface{} // func(*grpc.Server, string) |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 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 interface{} // 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 interface{} // 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 interface{} // 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 interface{} // func(...grpc.DialOption) grpc.DialOption |
| 108 | // JoinServerOptions combines the server options passed as arguments into a |
| 109 | // single server option. |
| 110 | JoinServerOptions interface{} // func(...grpc.ServerOption) grpc.ServerOption |
| 111 | |
| 112 | // WithBinaryLogger returns a DialOption that specifies the binary logger |
| 113 | // for a ClientConn. |
| 114 | // |
| 115 | // This is used in the 1.0 release of gcp/observability, and thus must not be |
| 116 | // deleted or changed. |
| 117 | WithBinaryLogger interface{} // func(binarylog.Logger) grpc.DialOption |
| 118 | // BinaryLogger returns a ServerOption that can set the binary logger for a |
| 119 | // server. |
| 120 | // |
| 121 | // This is used in the 1.0 release of gcp/observability, and thus must not be |
| 122 | // deleted or changed. |
| 123 | BinaryLogger interface{} // func(binarylog.Logger) grpc.ServerOption |
| 124 | |
| 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 interface{} // func([]byte) (resolver.Builder, error) |
| 135 | |
| 136 | // RegisterRLSClusterSpecifierPluginForTesting registers the RLS Cluster |
| 137 | // Specifier Plugin for testing purposes, regardless of the XDSRLS environment |
| 138 | // variable. |
| 139 | // |
| 140 | // TODO: Remove this function once the RLS env var is removed. |
| 141 | RegisterRLSClusterSpecifierPluginForTesting func() |
| 142 | |
| 143 | // UnregisterRLSClusterSpecifierPluginForTesting unregisters the RLS Cluster |
| 144 | // Specifier Plugin for testing purposes. This is needed because there is no way |
| 145 | // to unregister the RLS Cluster Specifier Plugin after registering it solely |
| 146 | // for testing purposes using RegisterRLSClusterSpecifierPluginForTesting(). |
| 147 | // |
| 148 | // TODO: Remove this function once the RLS env var is removed. |
| 149 | UnregisterRLSClusterSpecifierPluginForTesting func() |
| 150 | |
| 151 | // RegisterRBACHTTPFilterForTesting registers the RBAC HTTP Filter for testing |
| 152 | // purposes, regardless of the RBAC environment variable. |
| 153 | // |
| 154 | // TODO: Remove this function once the RBAC env var is removed. |
| 155 | RegisterRBACHTTPFilterForTesting func() |
| 156 | |
| 157 | // UnregisterRBACHTTPFilterForTesting unregisters the RBAC HTTP Filter for |
| 158 | // testing purposes. This is needed because there is no way to unregister the |
| 159 | // HTTP Filter after registering it solely for testing purposes using |
| 160 | // RegisterRBACHTTPFilterForTesting(). |
| 161 | // |
| 162 | // TODO: Remove this function once the RBAC env var is removed. |
| 163 | UnregisterRBACHTTPFilterForTesting func() |
| 164 | |
| 165 | // ORCAAllowAnyMinReportingInterval is for examples/orca use ONLY. |
| 166 | ORCAAllowAnyMinReportingInterval interface{} // func(so *orca.ServiceOptions) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 167 | ) |
| 168 | |
| 169 | // HealthChecker defines the signature of the client-side LB channel health checking function. |
| 170 | // |
| 171 | // The implementation is expected to create a health checking RPC stream by |
| 172 | // calling newStream(), watch for the health status of serviceName, and report |
| 173 | // it's health back by calling setConnectivityState(). |
| 174 | // |
| 175 | // The health checking protocol is defined at: |
| 176 | // https://github.com/grpc/grpc/blob/master/doc/health-checking.md |
| 177 | type HealthChecker func(ctx context.Context, newStream func(string) (interface{}, error), setConnectivityState func(connectivity.State, error), serviceName string) error |
| 178 | |
| 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 | ) |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 189 | |
| 190 | // RLSLoadBalancingPolicyName is the name of the RLS LB policy. |
| 191 | // |
| 192 | // It currently has an experimental suffix which would be removed once |
| 193 | // end-to-end testing of the policy is completed. |
| 194 | const RLSLoadBalancingPolicyName = "rls_experimental" |