UNPKG

2.16 kBTypeScriptView Raw
1import { Status } from './constants';
2import { Duration } from './duration';
3import { LoadBalancingConfig } from './load-balancer';
4export interface MethodConfigName {
5 service?: string;
6 method?: string;
7}
8export interface RetryPolicy {
9 maxAttempts: number;
10 initialBackoff: string;
11 maxBackoff: string;
12 backoffMultiplier: number;
13 retryableStatusCodes: (Status | string)[];
14}
15export interface HedgingPolicy {
16 maxAttempts: number;
17 hedgingDelay?: string;
18 nonFatalStatusCodes?: (Status | string)[];
19}
20export interface MethodConfig {
21 name: MethodConfigName[];
22 waitForReady?: boolean;
23 timeout?: Duration;
24 maxRequestBytes?: number;
25 maxResponseBytes?: number;
26 retryPolicy?: RetryPolicy;
27 hedgingPolicy?: HedgingPolicy;
28}
29export interface RetryThrottling {
30 maxTokens: number;
31 tokenRatio: number;
32}
33export interface ServiceConfig {
34 loadBalancingPolicy?: string;
35 loadBalancingConfig: LoadBalancingConfig[];
36 methodConfig: MethodConfig[];
37 retryThrottling?: RetryThrottling;
38}
39export interface ServiceConfigCanaryConfig {
40 clientLanguage?: string[];
41 percentage?: number;
42 clientHostname?: string[];
43 serviceConfig: ServiceConfig;
44}
45export declare function validateRetryThrottling(obj: any): RetryThrottling;
46export declare function validateServiceConfig(obj: any): ServiceConfig;
47/**
48 * Find the "grpc_config" record among the TXT records, parse its value as JSON, validate its contents,
49 * and select a service config with selection fields that all match this client. Most of these steps
50 * can fail with an error; the caller must handle any errors thrown this way.
51 * @param txtRecord The TXT record array that is output from a successful call to dns.resolveTxt
52 * @param percentage A number chosen from the range [0, 100) that is used to select which config to use
53 * @return The service configuration to use, given the percentage value, or null if the service config
54 * data has a valid format but none of the options match the current client.
55 */
56export declare function extractAndSelectServiceConfig(txtRecord: string[][], percentage: number): ServiceConfig | null;