1 | /**
|
2 | * @license
|
3 | * Copyright 2020 Google LLC
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | export interface TeenyStatisticsOptions {
|
18 | /**
|
19 | * A positive number representing when to issue a warning about the number
|
20 | * of concurrent requests using teeny-request.
|
21 | * Set to 0 to disable this warning.
|
22 | * Corresponds to the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment
|
23 | * variable.
|
24 | */
|
25 | concurrentRequests?: number;
|
26 | }
|
27 | declare type TeenyStatisticsConfig = Required<TeenyStatisticsOptions>;
|
28 | /**
|
29 | * TeenyStatisticsCounters is distinct from TeenyStatisticsOptions:
|
30 | * Used when dumping current counters and other internal metrics.
|
31 | */
|
32 | export interface TeenyStatisticsCounters {
|
33 | concurrentRequests: number;
|
34 | }
|
35 | /**
|
36 | * @class TeenyStatisticsWarning
|
37 | * @extends Error
|
38 | * @description While an error, is used for emitting warnings when
|
39 | * meeting certain configured thresholds.
|
40 | * @see process.emitWarning
|
41 | */
|
42 | export declare class TeenyStatisticsWarning extends Error {
|
43 | static readonly CONCURRENT_REQUESTS = "ConcurrentRequestsExceededWarning";
|
44 | threshold: number;
|
45 | type: string;
|
46 | value: number;
|
47 | /**
|
48 | * @param {string} message
|
49 | */
|
50 | constructor(message: string);
|
51 | }
|
52 | /**
|
53 | * @class TeenyStatistics
|
54 | * @description Maintain various statistics internal to teeny-request. Tracking
|
55 | * is not automatic and must be instrumented within teeny-request.
|
56 | */
|
57 | export declare class TeenyStatistics {
|
58 | /**
|
59 | * @description A default threshold representing when to warn about excessive
|
60 | * in-flight/concurrent requests.
|
61 | * @type {number}
|
62 | * @static
|
63 | * @readonly
|
64 | * @default 5000
|
65 | */
|
66 | static readonly DEFAULT_WARN_CONCURRENT_REQUESTS = 5000;
|
67 | /**
|
68 | * @type {TeenyStatisticsConfig}
|
69 | * @private
|
70 | */
|
71 | private _options;
|
72 | /**
|
73 | * @type {number}
|
74 | * @private
|
75 | * @default 0
|
76 | */
|
77 | private _concurrentRequests;
|
78 | /**
|
79 | * @type {boolean}
|
80 | * @private
|
81 | * @default false
|
82 | */
|
83 | private _didConcurrentRequestWarn;
|
84 | /**
|
85 | * @param {TeenyStatisticsOptions} [opts]
|
86 | */
|
87 | constructor(opts?: TeenyStatisticsOptions);
|
88 | /**
|
89 | * Returns a copy of the current options.
|
90 | * @return {TeenyStatisticsOptions}
|
91 | */
|
92 | getOptions(): TeenyStatisticsOptions;
|
93 | /**
|
94 | * Change configured statistics options. This will not preserve unspecified
|
95 | * options that were previously specified, i.e. this is a reset of options.
|
96 | * @param {TeenyStatisticsOptions} [opts]
|
97 | * @returns {TeenyStatisticsConfig} The previous options.
|
98 | * @see _prepareOptions
|
99 | */
|
100 | setOptions(opts?: TeenyStatisticsOptions): TeenyStatisticsConfig;
|
101 | /**
|
102 | * @readonly
|
103 | * @return {TeenyStatisticsCounters}
|
104 | */
|
105 | get counters(): TeenyStatisticsCounters;
|
106 | /**
|
107 | * @description Should call this right before making a request.
|
108 | */
|
109 | requestStarting(): void;
|
110 | /**
|
111 | * @description When using `requestStarting`, call this after the request
|
112 | * has finished.
|
113 | */
|
114 | requestFinished(): void;
|
115 | /**
|
116 | * Configuration Precedence:
|
117 | * 1. Dependency inversion via defined option.
|
118 | * 2. Global numeric environment variable.
|
119 | * 3. Built-in default.
|
120 | * This will not preserve unspecified options previously specified.
|
121 | * @param {TeenyStatisticsOptions} [opts]
|
122 | * @returns {TeenyStatisticsOptions}
|
123 | * @private
|
124 | */
|
125 | private static _prepareOptions;
|
126 | }
|
127 | export {};
|