UNPKG

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