@@ -9,21 +9,6 @@ const Storage = require('./storage');
9
9
const schemas = require ( '../lib/schemas' ) ;
10
10
const { hashContent } = require ( './hasher' ) ;
11
11
12
- const PERSIST_TO_STORAGE_METRIC = {
13
- name : 'asset_server_persist_to_storage_timer' ,
14
- description : 'Time taken for a persist operation to storage' ,
15
- } ;
16
-
17
- const RETRIEVE_FROM_STORAGE_METRIC = {
18
- name : 'asset_server_retrieve_from_storage_timer' ,
19
- description : 'Time taken for a retrieve operation from storage' ,
20
- } ;
21
-
22
- const EXISTS_IN_STORAGE_METRIC = {
23
- name : 'asset_server_exists_in_storage_timer' ,
24
- description : 'Time taken for a check for existence operation from storage' ,
25
- } ;
26
-
27
12
module . exports = class OptimisticBundler extends Bundler {
28
13
constructor ( { bundleInProcess, ...options } ) {
29
14
super ( { bundleInProcess } ) ;
@@ -38,6 +23,63 @@ module.exports = class OptimisticBundler extends Bundler {
38
23
this . log = abslog ( options . logger ) ;
39
24
this . options = opts ;
40
25
this . overrides = { } ;
26
+
27
+ this . bundleSizeGaugeMetric = this . metrics . gauge ( {
28
+ name : 'asset_server_bundle_size_gauge' ,
29
+ description : 'Measures the size of bundles created' ,
30
+ } ) ;
31
+ this . bundlingTimerMetric = this . metrics . histogram ( {
32
+ name : 'asset_server_bundling_timer' ,
33
+ description : 'Time taken to bundle assets' ,
34
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
35
+ } ) ;
36
+ this . retrieveFromStorageTimerMetric = this . metrics . histogram ( {
37
+ name : 'asset_server_retrieve_from_storage_timer' ,
38
+ description : 'Time taken for a retrieve operation from storage' ,
39
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
40
+ } ) ;
41
+ this . existsInStorageTimerMetric = this . metrics . histogram ( {
42
+ name : 'asset_server_exists_in_storage_timer' ,
43
+ description :
44
+ 'Time taken for a check for existence operation from storage' ,
45
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
46
+ } ) ;
47
+ this . persistToStorageTimerMetric = this . metrics . histogram ( {
48
+ name : 'asset_server_persist_to_storage_timer' ,
49
+ description : 'Time taken for a persist operation to storage' ,
50
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
51
+ } ) ;
52
+ this . publishAssetsTimerMetric = this . metrics . histogram ( {
53
+ name : 'asset_server_publish_assets_timer' ,
54
+ description :
55
+ 'Time taken for a publish assets operation to complete' ,
56
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
57
+ } ) ;
58
+ this . saveFeedTimerMetric = this . metrics . histogram ( {
59
+ name : 'asset_server_save_feed_timer' ,
60
+ description : 'Time taken for a feed to be saved to storage' ,
61
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
62
+ } ) ;
63
+ this . fallbackBundleSizeGaugeMetric = this . metrics . gauge ( {
64
+ name : 'asset_server_fallback_bundle_size_gauge' ,
65
+ description : 'Measures the size of fallback bundles created' ,
66
+ } ) ;
67
+ this . saveFallbackBundleTimerMetric = this . metrics . histogram ( {
68
+ name : 'asset_server_save_fallback_bundle_timer' ,
69
+ description :
70
+ 'Time taken for a fallback bundle to be bundled and saved' ,
71
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
72
+ } ) ;
73
+ this . publishInstructionsTimerMetric = this . metrics . histogram ( {
74
+ name : 'asset_server_publish_instructions_timer' ,
75
+ description : 'Time taken for publishInstructions() to complete' ,
76
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
77
+ } ) ;
78
+ this . rebundleInstructionsTimerMetric = this . metrics . histogram ( {
79
+ name : 'asset_server_rebundle_instructions_timer' ,
80
+ description : 'Time taken to rebundle all instructions for a tag' ,
81
+ buckets : [ 1 , 5 , 10 , 15 , 20 , 30 , 60 , 120 ] ,
82
+ } ) ;
41
83
}
42
84
43
85
async assetsPublished ( tags , hashes , type ) {
@@ -55,85 +97,85 @@ module.exports = class OptimisticBundler extends Bundler {
55
97
}
56
98
57
99
async getTags ( tags , type ) {
58
- const end = this . metrics . timer ( RETRIEVE_FROM_STORAGE_METRIC ) ;
100
+ const end = this . retrieveFromStorageTimerMetric . timer ( ) ;
59
101
60
102
const storageTags = await this . storage . getTags ( tags , type ) ;
61
103
62
- end ( { meta : { method : 'getTags' } } ) ;
104
+ end ( { labels : { method : 'getTags' } } ) ;
63
105
64
106
return storageTags ;
65
107
}
66
108
67
109
async getFeed ( hash ) {
68
- const end = this . metrics . timer ( RETRIEVE_FROM_STORAGE_METRIC ) ;
110
+ const end = this . retrieveFromStorageTimerMetric . timer ( ) ;
69
111
70
112
const feed = await this . storage . getFeed ( hash ) ;
71
113
72
- end ( { meta : { method : 'getFeed' } } ) ;
114
+ end ( { labels : { method : 'getFeed' } } ) ;
73
115
74
116
return feed ;
75
117
}
76
118
77
119
async hasFeed ( hash ) {
78
- const end = this . metrics . timer ( EXISTS_IN_STORAGE_METRIC ) ;
120
+ const end = this . existsInStorageTimerMetric . timer ( ) ;
79
121
80
122
const hasFeed = await this . storage . hasFeed ( hash ) ;
81
123
82
- end ( { meta : { method : 'hasFeed' } } ) ;
124
+ end ( { labels : { method : 'hasFeed' } } ) ;
83
125
84
126
return hasFeed ;
85
127
}
86
128
87
129
async hasBundle ( hash , type ) {
88
- const end = this . metrics . timer ( EXISTS_IN_STORAGE_METRIC ) ;
130
+ const end = this . existsInStorageTimerMetric . timer ( ) ;
89
131
90
132
const hasBundle = await this . storage . hasBundle ( hash , type ) ;
91
133
92
- end ( { meta : { method : 'hasBundle' } } ) ;
134
+ end ( { labels : { method : 'hasBundle' } } ) ;
93
135
94
136
return hasBundle ;
95
137
}
96
138
97
139
async setBundle ( hash , type , content ) {
98
- const end = this . metrics . timer ( PERSIST_TO_STORAGE_METRIC ) ;
140
+ const end = this . persistToStorageTimerMetric . timer ( ) ;
99
141
100
142
await this . storage . setBundle ( hash , type , content ) ;
101
143
102
- end ( { meta : { method : 'setBundle' } } ) ;
144
+ end ( { labels : { method : 'setBundle' } } ) ;
103
145
}
104
146
105
147
async getInstructions ( tag , type ) {
106
- const end = this . metrics . timer ( RETRIEVE_FROM_STORAGE_METRIC ) ;
148
+ const end = this . retrieveFromStorageTimerMetric . timer ( ) ;
107
149
108
150
const instructions = await this . storage . getInstructions ( tag , type ) ;
109
151
110
- end ( { meta : { method : 'getInstructions' } } ) ;
152
+ end ( { labels : { method : 'getInstructions' } } ) ;
111
153
112
154
return instructions ;
113
155
}
114
156
115
157
async setInstruction ( tag , type , instruction ) {
116
- const end = this . metrics . timer ( PERSIST_TO_STORAGE_METRIC ) ;
158
+ const end = this . persistToStorageTimerMetric . timer ( ) ;
117
159
118
160
await this . storage . setInstruction ( tag , type , instruction ) ;
119
161
120
- end ( { meta : { method : 'setInstruction' } } ) ;
162
+ end ( { labels : { method : 'setInstruction' } } ) ;
121
163
}
122
164
123
165
async setFeed ( feedHash , assetFeed ) {
124
- const end = this . metrics . timer ( PERSIST_TO_STORAGE_METRIC ) ;
166
+ const end = this . persistToStorageTimerMetric . timer ( ) ;
125
167
126
168
await this . storage . setFeed ( feedHash , assetFeed ) ;
127
169
128
- end ( { meta : { method : 'setFeed' } } ) ;
170
+ end ( { labels : { method : 'setFeed' } } ) ;
129
171
}
130
172
131
173
async setTag ( tag , assetType , feedHash ) {
132
- const end = this . metrics . timer ( PERSIST_TO_STORAGE_METRIC ) ;
174
+ const end = this . persistToStorageTimerMetric . timer ( ) ;
133
175
134
176
await this . storage . setTag ( tag , assetType , feedHash ) ;
135
177
136
- end ( { meta : { method : 'setTag' } } ) ;
178
+ end ( { labels : { method : 'setTag' } } ) ;
137
179
}
138
180
139
181
async bundleExists ( tags , hashes , type ) {
@@ -164,11 +206,9 @@ module.exports = class OptimisticBundler extends Bundler {
164
206
async bundle ( tag , tags , hashes , type ) {
165
207
const feeds = await this . getFeeds ( hashes ) ;
166
208
167
- const end = this . metrics . timer ( {
168
- name : 'asset_server_bundling_timer' ,
169
- description : 'Time taken to bundle assets' ,
170
- meta : {
171
- sources : tags ,
209
+ const end = this . bundlingTimerMetric . timer ( {
210
+ labels : {
211
+ sources : JSON . stringify ( tags ) ,
172
212
assetType : type ,
173
213
publisher : tag ,
174
214
} ,
@@ -182,12 +222,9 @@ module.exports = class OptimisticBundler extends Bundler {
182
222
183
223
end ( ) ;
184
224
185
- this . metrics . metric ( {
186
- name : 'asset_server_bundle_size_gauge' ,
187
- description : 'Measures the size of bundles created' ,
188
- value : Buffer . byteLength ( content , 'utf8' ) ,
189
- meta : {
190
- sources : tags ,
225
+ this . bundleSizeGaugeMetric . set ( Buffer . byteLength ( content , 'utf8' ) , {
226
+ labels : {
227
+ sources : JSON . stringify ( tags ) ,
191
228
assetType : type ,
192
229
publisher : tag ,
193
230
} ,
@@ -242,10 +279,8 @@ module.exports = class OptimisticBundler extends Bundler {
242
279
}
243
280
244
281
async rebundle ( tag , type ) {
245
- const end = this . metrics . timer ( {
246
- name : 'asset_server_rebundle_instructions_timer' ,
247
- description : 'Time taken to rebundle all instructions for a tag' ,
248
- meta : {
282
+ const end = this . rebundleInstructionsTimerMetric . timer ( {
283
+ labels : {
249
284
assetType : type ,
250
285
publisher : tag ,
251
286
} ,
@@ -266,10 +301,8 @@ module.exports = class OptimisticBundler extends Bundler {
266
301
`Invalid 'instruction' object given when attempting to publish instructions.` ,
267
302
) ;
268
303
269
- const end = this . metrics . timer ( {
270
- name : 'asset_server_publish_instructions_timer' ,
271
- description : 'Time taken for publishInstructions() to complete' ,
272
- meta : {
304
+ const end = this . publishAssetsTimerMetric . timer ( {
305
+ labels : {
273
306
assetType : type ,
274
307
publisher : tag ,
275
308
} ,
@@ -291,11 +324,8 @@ module.exports = class OptimisticBundler extends Bundler {
291
324
}
292
325
293
326
async saveFallbackBundle ( tag , hash , type , feed ) {
294
- const end = this . metrics . timer ( {
295
- name : 'asset_server_save_fallback_bundle_timer' ,
296
- description :
297
- 'Time taken for a fallback bundle to be bundled and saved' ,
298
- meta : {
327
+ const end = this . saveFallbackBundleTimerMetric . timer ( {
328
+ labels : {
299
329
assetType : type ,
300
330
publisher : tag ,
301
331
} ,
@@ -309,15 +339,15 @@ module.exports = class OptimisticBundler extends Bundler {
309
339
const bundle = await super . bundleFeeds ( [ feed ] , type ) ;
310
340
await this . setBundle ( hash , type , bundle ) ;
311
341
312
- this . metrics . metric ( {
313
- name : 'asset_server_fallback_bundle_size_gauge' ,
314
- description : 'Measures the size of fallback bundles created' ,
315
- value : Buffer . byteLength ( bundle , 'utf8' ) ,
316
- meta : {
317
- assetType : type ,
318
- publisher : tag ,
342
+ this . fallbackBundleSizeGaugeMetric . set (
343
+ Buffer . byteLength ( bundle , 'utf8' ) ,
344
+ {
345
+ labels : {
346
+ assetType : type ,
347
+ publisher : tag ,
348
+ } ,
319
349
} ,
320
- } ) ;
350
+ ) ;
321
351
322
352
this . log . info (
323
353
`${ type } fallback bundle for tag "${ tag } " published as "${ hash } .${ type } "` ,
@@ -328,10 +358,8 @@ module.exports = class OptimisticBundler extends Bundler {
328
358
}
329
359
330
360
async saveFeed ( tag , hash , type , feed ) {
331
- const end = this . metrics . timer ( {
332
- name : 'asset_server_save_feed_timer' ,
333
- description : 'Time taken for a feed to be saved to storage' ,
334
- meta : {
361
+ const end = this . saveFeedTimerMetric . timer ( {
362
+ labels : {
335
363
assetType : type ,
336
364
publisher : tag ,
337
365
} ,
@@ -358,11 +386,8 @@ module.exports = class OptimisticBundler extends Bundler {
358
386
`Invalid 'assets' object given when attempting to publish assets.` ,
359
387
) ;
360
388
361
- const end = this . metrics . timer ( {
362
- name : 'asset_server_publish_assets_timer' ,
363
- description :
364
- 'Time taken for a publish assets operation to complete' ,
365
- meta : {
389
+ const end = this . publishAssetsTimerMetric . timer ( {
390
+ labels : {
366
391
assetType : type ,
367
392
publisher : tag ,
368
393
} ,
0 commit comments