File tree Expand file tree Collapse file tree 8 files changed +441
-108
lines changed Expand file tree Collapse file tree 8 files changed +441
-108
lines changed Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` Metrics should get metrics data 1` ] = `
4+ Object {
5+ " metrics" : Array [
6+ Object {
7+ " title" : " function invocations & errors" ,
8+ " type" : " empty" ,
9+ },
10+ Object {
11+ " title" : " function latency" ,
12+ " type" : " empty" ,
13+ },
14+ Object {
15+ " title" : " api requests & errors" ,
16+ " type" : " stacked-bar" ,
17+ " x" : Object {
18+ " type" : " timestamp" ,
19+ " values" : Array [],
20+ },
21+ " y" : Array [
22+ Object {
23+ " name" : " requests" ,
24+ " total" : 0 ,
25+ " type" : " count" ,
26+ " values" : Array [
27+ 0 ,
28+ 0 ,
29+ 0 ,
30+ 0 ,
31+ 0 ,
32+ 0 ,
33+ 0 ,
34+ 0 ,
35+ 0 ,
36+ 0 ,
37+ 0 ,
38+ 0 ,
39+ ],
40+ },
41+ Object {
42+ " color" : " error" ,
43+ " name" : " errors" ,
44+ " total" : 0 ,
45+ " type" : " count" ,
46+ " values" : Array [
47+ 0 ,
48+ 0 ,
49+ 0 ,
50+ 0 ,
51+ 0 ,
52+ 0 ,
53+ 0 ,
54+ 0 ,
55+ 0 ,
56+ 0 ,
57+ 0 ,
58+ 0 ,
59+ ],
60+ },
61+ ],
62+ },
63+ Object {
64+ " title" : " api latency" ,
65+ " type" : " multiline" ,
66+ " x" : Object {
67+ " type" : " timestamp" ,
68+ " values" : Array [],
69+ },
70+ " y" : Array [
71+ Object {
72+ " name" : " P95 latency" ,
73+ " total" : 0 ,
74+ " type" : " duration" ,
75+ " values" : Array [
76+ 0 ,
77+ 0 ,
78+ 0 ,
79+ 0 ,
80+ 0 ,
81+ 0 ,
82+ 0 ,
83+ 0 ,
84+ 0 ,
85+ 0 ,
86+ 0 ,
87+ 0 ,
88+ ],
89+ },
90+ Object {
91+ " name" : " P50 latency" ,
92+ " total" : 0 ,
93+ " type" : " duration" ,
94+ " values" : Array [
95+ 0 ,
96+ 0 ,
97+ 0 ,
98+ 0 ,
99+ 0 ,
100+ 0 ,
101+ 0 ,
102+ 0 ,
103+ 0 ,
104+ 0 ,
105+ 0 ,
106+ 0 ,
107+ ],
108+ },
109+ ],
110+ },
111+ Object {
112+ " title" : " api 5xx errors" ,
113+ " type" : " stacked-bar" ,
114+ " x" : Object {
115+ " type" : " timestamp" ,
116+ " values" : Array [],
117+ },
118+ " y" : Array [
119+ Object {
120+ " color" : " error" ,
121+ " name" : " 5xx" ,
122+ " total" : 0 ,
123+ " type" : " count" ,
124+ " values" : Array [
125+ 0 ,
126+ 0 ,
127+ 0 ,
128+ 0 ,
129+ 0 ,
130+ 0 ,
131+ 0 ,
132+ 0 ,
133+ 0 ,
134+ 0 ,
135+ 0 ,
136+ 0 ,
137+ ],
138+ },
139+ ],
140+ },
141+ Object {
142+ " title" : " api 4xx errors" ,
143+ " type" : " stacked-bar" ,
144+ " x" : Object {
145+ " type" : " timestamp" ,
146+ " values" : Array [],
147+ },
148+ " y" : Array [
149+ Object {
150+ " color" : " error" ,
151+ " name" : " 4xx" ,
152+ " total" : 0 ,
153+ " type" : " count" ,
154+ " values" : Array [
155+ 0 ,
156+ 0 ,
157+ 0 ,
158+ 0 ,
159+ 0 ,
160+ 0 ,
161+ 0 ,
162+ 0 ,
163+ 0 ,
164+ 0 ,
165+ 0 ,
166+ 0 ,
167+ ],
168+ },
169+ ],
170+ },
171+ Object {
172+ " color" : " error" ,
173+ " title" : " api errors" ,
174+ " type" : " list-flat-bar" ,
175+ " x" : Object {
176+ " type" : " string" ,
177+ " values" : Array [
178+ " GET - /" ,
179+ " GET - /favicon.ico" ,
180+ " GET - /release" ,
181+ " POST - /upload" ,
182+ " POST - /upload/" ,
183+ ],
184+ },
185+ " y" : Array [
186+ Object {
187+ " name" : " 404" ,
188+ " total" : 0 ,
189+ " type" : " count" ,
190+ " values" : Array [
191+ 0 ,
192+ 0 ,
193+ 0 ,
194+ 0 ,
195+ 0 ,
196+ ],
197+ },
198+ Object {
199+ " name" : " 500" ,
200+ " total" : 0 ,
201+ " type" : " count" ,
202+ " values" : Array [
203+ 0 ,
204+ 0 ,
205+ 0 ,
206+ 0 ,
207+ 0 ,
208+ ],
209+ },
210+ ],
211+ },
212+ Object {
213+ " title" : " api path requests" ,
214+ " type" : " list-details-bar" ,
215+ " x" : Object {
216+ " type" : " string" ,
217+ " values" : Array [
218+ " DELETE - /user/1" ,
219+ " GET - /" ,
220+ " GET - /favicon.ico" ,
221+ " GET - /playground/" ,
222+ " GET - /release" ,
223+ " GET - /user" ,
224+ " POST - /" ,
225+ " POST - /upload" ,
226+ " POST - /upload/" ,
227+ " POST - /user" ,
228+ ],
229+ },
230+ " y" : Array [
231+ Object {
232+ " name" : " requests" ,
233+ " total" : 0 ,
234+ " type" : " count" ,
235+ " values" : Array [
236+ 0 ,
237+ 0 ,
238+ 0 ,
239+ 0 ,
240+ 0 ,
241+ 0 ,
242+ 0 ,
243+ 0 ,
244+ 0 ,
245+ 0 ,
246+ ],
247+ },
248+ Object {
249+ " name" : " avg latency" ,
250+ " total" : 0 ,
251+ " type" : " duration" ,
252+ " values" : Array [
253+ 0 ,
254+ 0 ,
255+ 0 ,
256+ 0 ,
257+ 0 ,
258+ 0 ,
259+ 0 ,
260+ 0 ,
261+ 0 ,
262+ 0 ,
263+ ],
264+ },
265+ ],
266+ },
267+ Object {
268+ " title" : " apigw total request num" ,
269+ " type" : " stacked-bar" ,
270+ " x" : Object {
271+ " type" : " timestamp" ,
272+ " values" : Array [],
273+ },
274+ " y" : Array [
275+ Object {
276+ " name" : " request" ,
277+ " total" : 0 ,
278+ " type" : " count" ,
279+ " values" : Array [
280+ 0 ,
281+ 0 ,
282+ 0 ,
283+ 0 ,
284+ 0 ,
285+ 0 ,
286+ 0 ,
287+ 0 ,
288+ 0 ,
289+ 0 ,
290+ 0 ,
291+ 0 ,
292+ 0 ,
293+ ],
294+ },
295+ ],
296+ },
297+ Object {
298+ " title" : " apigw request response time(ms)" ,
299+ " type" : " stacked-bar" ,
300+ " x" : Object {
301+ " type" : " timestamp" ,
302+ " values" : Array [],
303+ },
304+ " y" : Array [
305+ Object {
306+ " name" : " response time" ,
307+ " total" : 0 ,
308+ " type" : " duration" ,
309+ " values" : Array [
310+ 0 ,
311+ 0 ,
312+ 0 ,
313+ 0 ,
314+ 0 ,
315+ 0 ,
316+ 0 ,
317+ 0 ,
318+ 0 ,
319+ 0 ,
320+ 0 ,
321+ 0 ,
322+ 0 ,
323+ ],
324+ },
325+ ],
326+ },
327+ ],
328+ " rangeEnd" : " 2020-09-09 11:00:00" ,
329+ " rangeStart" : " 2020-09-09 10:00:00" ,
330+ }
331+ ` ;
Original file line number Diff line number Diff line change 1+ import moment from 'moment' ;
12import { Metrics } from '../src' ;
23
4+ function format < T > ( obj : T ) : void {
5+ if ( Array . isArray ( obj ) ) {
6+ ( obj as Array < any > ) . sort ( ) ;
7+ for ( const v of obj ) {
8+ format ( v ) ;
9+ }
10+ }
11+
12+ if ( typeof obj === 'object' ) {
13+ if ( obj [ 'type' ] === 'timestamp' ) {
14+ obj [ 'values' ] = [ ] ;
15+ }
16+ for ( const v of Object . values ( obj ) ) {
17+ format ( v ) ;
18+ }
19+ }
20+ }
21+
322describe ( 'Metrics' , ( ) => {
423 const credentials = {
524 SecretId : process . env . TENCENT_SECRET_ID ,
@@ -13,11 +32,14 @@ describe('Metrics', () => {
1332 const rangeEnd = '2020-09-09 11:00:00' ;
1433
1534 test ( 'should get metrics data' , async ( ) => {
16- const res = await metrics . getDatas ( rangeStart , rangeEnd ) ;
35+ const res = await metrics . getDatas ( rangeStart , rangeEnd , 0xfffffffffff ) ;
1736 expect ( res ) . toEqual ( {
18- rangeStart : rangeStart ,
19- rangeEnd : rangeEnd ,
37+ rangeStart : moment ( rangeStart ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
38+ rangeEnd : moment ( rangeEnd ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
2039 metrics : expect . any ( Array ) ,
2140 } ) ;
41+
42+ format ( res ) ;
43+ expect ( res ) . toMatchSnapshot ( ) ;
2244 } ) ;
2345} ) ;
Original file line number Diff line number Diff line change 9191 "@ygkit/request" : " ^0.1.8" ,
9292 "cos-nodejs-sdk-v5" : " 2.8.6" ,
9393 "lodash" : " ^4.17.20" ,
94- "moment" : " ^2.25.3 " ,
94+ "moment" : " ^2.29.1 " ,
9595 "tencent-cloud-sdk" : " ^1.0.5" ,
9696 "type-fest" : " ^0.20.2"
9797 }
You can’t perform that action at this time.
0 commit comments