Преглед изворни кода

feat(AvgRTPStatsReporter): batch avg RTP stats

Tries to batch as many reports as possible into single analytics event
and sends all of them under "avg.rtp.stats" event name.

Also converts dots to underscores in all of the stat names, because now
they become JSON keys where dots are not allowed.
dev1
paweldomas пре 8 година
родитељ
комит
b94f1d027e
1 измењених фајлова са 87 додато и 46 уклоњено
  1. 87
    46
      modules/statistics/AvgRTPStatsReporter.js

+ 87
- 46
modules/statistics/AvgRTPStatsReporter.js Прегледај датотеку

@@ -9,6 +9,39 @@ import RTCBrowserType from '../RTC/RTCBrowserType';
9 9
 import Statistics from './statistics';
10 10
 import * as VideoType from '../../service/RTC/VideoType';
11 11
 
12
+/**
13
+ * All avg RTP stats are currently reported under 1 event name, but under
14
+ * different keys. This constant stores the name of this event.
15
+ * Example structure of "avg.rtp.stats" analytics event:
16
+ *
17
+ * {
18
+ *   "stat_avg_rtt": {
19
+ *     value: 200,
20
+ *     samples: [ 100, 200, 300 ]
21
+ *   },
22
+ *   "stat_avg_packetloss_total": {
23
+ *     value: 10,
24
+ *     samples: [ 5, 10, 15]
25
+ *   },
26
+ *   "p2p_stat_avg_packetloss_total": {
27
+ *     value: 15,
28
+ *     samples: [ 10, 15, 20]
29
+ *   }
30
+ * }
31
+ *
32
+ * Note that the samples array is currently emitted for debug purposes only and
33
+ * can be removed anytime soon from the structure.
34
+ *
35
+ * Also not all values are always present in "avg.rtp.stats", some of the values
36
+ * are obtained and calculated as part of different process/event pipe. For
37
+ * example {@link ConnectionAvgStats} instances are doing the reports for each
38
+ * {@link TraceablePeerConnection} and work independently from the main stats
39
+ * pipe.
40
+ *
41
+ * @type {string}
42
+ */
43
+const AVG_RTP_STATS_EVENT = 'avg.rtp.stats';
44
+
12 45
 const logger = getLogger(__filename);
13 46
 
14 47
 /**
@@ -55,19 +88,18 @@ class AverageStatReport {
55 88
     }
56 89
 
57 90
     /**
58
-     * Calculates an average and submit the report to the analytics module.
59
-     * @param {boolean} isP2P indicates if the report is to be submitted for
60
-     * the P2P connection (when conference is currently in the P2P mode). This
61
-     * will add 'p2p.' prefix to the name of the event. All averages should be
62
-     * cleared when the conference switches, between P2P and JVB modes.
91
+     * Appends the report to the analytics "data" object. The object will be
92
+     * added under {@link this.name} key or "p2p_" + {@link this.name} if
93
+     * <tt>isP2P</tt> is <tt>true</tt>.
94
+     * @param {Object} report the analytics "data" object
95
+     * @param {boolean} isP2P <tt>true</tt> if the stats is being report for
96
+     * P2P connection or <tt>false</tt> for the JVB connection.
63 97
      */
64
-    report(isP2P) {
65
-        Statistics.analytics.sendEvent(
66
-            `${isP2P ? 'p2p.' : ''}${this.name}`,
67
-            {
68
-                value: this.calculate(),
69
-                samples: this.samples
70
-            });
98
+    appendReport(report, isP2P) {
99
+        report[`${isP2P ? 'p2p_' : ''}${this.name}`] = {
100
+            value: this.calculate(),
101
+            samples: this.samples
102
+        };
71 103
     }
72 104
 
73 105
     /**
@@ -120,7 +152,7 @@ class ConnectionAvgStats {
120 152
          * Average round trip time reported by the ICE candidate pair.
121 153
          * @type {AverageStatReport}
122 154
          */
123
-        this._avgRTT = new AverageStatReport('stat.avg.rtt');
155
+        this._avgRTT = new AverageStatReport('stat_avg_rtt');
124 156
 
125 157
         /**
126 158
          * Map stores average RTT to the JVB reported by remote participants.
@@ -183,7 +215,9 @@ class ConnectionAvgStats {
183 215
 
184 216
         if (this._sampleIdx >= this._n) {
185 217
             if (RTCBrowserType.supportsRTTStatistics()) {
186
-                this._avgRTT.report(this.isP2P);
218
+                const batchReport = { };
219
+
220
+                this._avgRTT.appendReport(batchReport, this.isP2P);
187 221
 
188 222
                 // Report end to end RTT only for JVB
189 223
                 if (!this.isP2P) {
@@ -191,11 +225,14 @@ class ConnectionAvgStats {
191 225
                     const avgLocalRTT = this._avgRTT.calculate();
192 226
 
193 227
                     if (!isNaN(avgLocalRTT) && !isNaN(avgRemoteRTT)) {
194
-                        Statistics.analytics.sendEvent(
195
-                            'stat.avg.end2endrtt',
196
-                            { value: avgLocalRTT + avgRemoteRTT });
228
+                        // eslint-disable-next-line camelcase
229
+                        batchReport.stat_avg_end2endrtt
230
+                            = { value: avgLocalRTT + avgRemoteRTT };
197 231
                     }
198 232
                 }
233
+
234
+                Statistics.analytics.sendEvent(
235
+                    AVG_RTP_STATS_EVENT, batchReport);
199 236
             }
200 237
 
201 238
             this._resetAvgStats();
@@ -238,7 +275,7 @@ class ConnectionAvgStats {
238 275
         let rttAvg = this._avgRemoteRTTMap.get(id);
239 276
 
240 277
         if (!rttAvg && validData) {
241
-            rttAvg = new AverageStatReport(`${id}.stat.rtt`);
278
+            rttAvg = new AverageStatReport(`${id}_stat_rtt`);
242 279
             this._avgRemoteRTTMap.set(id, rttAvg);
243 280
         }
244 281
 
@@ -332,7 +369,7 @@ export default class AvgRTPStatsReporter {
332 369
          * @private
333 370
          */
334 371
         this._avgAudioBitrateUp
335
-            = new AverageStatReport('stat.avg.bitrate.audio.upload');
372
+            = new AverageStatReport('stat_avg_bitrate_audio_upload');
336 373
 
337 374
         /**
338 375
          * Average audio download bitrate
@@ -340,7 +377,7 @@ export default class AvgRTPStatsReporter {
340 377
          * @private
341 378
          */
342 379
         this._avgAudioBitrateDown
343
-            = new AverageStatReport('stat.avg.bitrate.audio.download');
380
+            = new AverageStatReport('stat_avg_bitrate_audio_download');
344 381
 
345 382
         /**
346 383
          * Average video upload bitrate
@@ -348,7 +385,7 @@ export default class AvgRTPStatsReporter {
348 385
          * @private
349 386
          */
350 387
         this._avgVideoBitrateUp
351
-            = new AverageStatReport('stat.avg.bitrate.video.upload');
388
+            = new AverageStatReport('stat_avg_bitrate_video_upload');
352 389
 
353 390
         /**
354 391
          * Average video download bitrate
@@ -356,7 +393,7 @@ export default class AvgRTPStatsReporter {
356 393
          * @private
357 394
          */
358 395
         this._avgVideoBitrateDown
359
-            = new AverageStatReport('stat.avg.bitrate.video.download');
396
+            = new AverageStatReport('stat_avg_bitrate_video_download');
360 397
 
361 398
         /**
362 399
          * Average upload bandwidth
@@ -364,7 +401,7 @@ export default class AvgRTPStatsReporter {
364 401
          * @private
365 402
          */
366 403
         this._avgBandwidthUp
367
-            = new AverageStatReport('stat.avg.bandwidth.upload');
404
+            = new AverageStatReport('stat_avg_bandwidth_upload');
368 405
 
369 406
         /**
370 407
          * Average download bandwidth
@@ -372,7 +409,7 @@ export default class AvgRTPStatsReporter {
372 409
          * @private
373 410
          */
374 411
         this._avgBandwidthDown
375
-            = new AverageStatReport('stat.avg.bandwidth.download');
412
+            = new AverageStatReport('stat_avg_bandwidth_download');
376 413
 
377 414
         /**
378 415
          * Average total packet loss
@@ -380,7 +417,7 @@ export default class AvgRTPStatsReporter {
380 417
          * @private
381 418
          */
382 419
         this._avgPacketLossTotal
383
-            = new AverageStatReport('stat.avg.packetloss.total');
420
+            = new AverageStatReport('stat_avg_packetloss_total');
384 421
 
385 422
         /**
386 423
          * Average upload packet loss
@@ -388,7 +425,7 @@ export default class AvgRTPStatsReporter {
388 425
          * @private
389 426
          */
390 427
         this._avgPacketLossUp
391
-            = new AverageStatReport('stat.avg.packetloss.upload');
428
+            = new AverageStatReport('stat_avg_packetloss_upload');
392 429
 
393 430
         /**
394 431
          * Average download packet loss
@@ -396,14 +433,14 @@ export default class AvgRTPStatsReporter {
396 433
          * @private
397 434
          */
398 435
         this._avgPacketLossDown
399
-            = new AverageStatReport('stat.avg.packetloss.download');
436
+            = new AverageStatReport('stat_avg_packetloss_download');
400 437
 
401 438
         /**
402 439
          * Average FPS for remote videos
403 440
          * @type {AverageStatReport}
404 441
          * @private
405 442
          */
406
-        this._avgRemoteFPS = new AverageStatReport('stat.avg.framerate.remote');
443
+        this._avgRemoteFPS = new AverageStatReport('stat_avg_framerate_remote');
407 444
 
408 445
         /**
409 446
          * Average FPS for remote screen streaming videos (reported only if not
@@ -412,14 +449,14 @@ export default class AvgRTPStatsReporter {
412 449
          * @private
413 450
          */
414 451
         this._avgRemoteScreenFPS
415
-            = new AverageStatReport('stat.avg.framerate.screen.remote');
452
+            = new AverageStatReport('stat_avg_framerate_screen_remote');
416 453
 
417 454
         /**
418 455
          * Average FPS for local video (camera)
419 456
          * @type {AverageStatReport}
420 457
          * @private
421 458
          */
422
-        this._avgLocalFPS = new AverageStatReport('stat.avg.framerate.local');
459
+        this._avgLocalFPS = new AverageStatReport('stat_avg_framerate_local');
423 460
 
424 461
         /**
425 462
          * Average FPS for local screen streaming video (reported only if not
@@ -428,7 +465,7 @@ export default class AvgRTPStatsReporter {
428 465
          * @private
429 466
          */
430 467
         this._avgLocalScreenFPS
431
-            = new AverageStatReport('stat.avg.framerate.screen.local');
468
+            = new AverageStatReport('stat_avg_framerate_screen_local');
432 469
 
433 470
         /**
434 471
          * Average connection quality as defined by
@@ -436,7 +473,7 @@ export default class AvgRTPStatsReporter {
436 473
          * @type {AverageStatReport}
437 474
          * @private
438 475
          */
439
-        this._avgCQ = new AverageStatReport('stat.avg.cq');
476
+        this._avgCQ = new AverageStatReport('stat_avg_cq');
440 477
 
441 478
         this._onLocalStatsUpdated = data => this._calculateAvgStats(data);
442 479
         conference.on(
@@ -551,30 +588,34 @@ export default class AvgRTPStatsReporter {
551 588
         this._sampleIdx += 1;
552 589
 
553 590
         if (this._sampleIdx >= this._n) {
554
-            this._avgAudioBitrateUp.report(isP2P);
555
-            this._avgAudioBitrateDown.report(isP2P);
591
+            const batchReport = { };
556 592
 
557
-            this._avgVideoBitrateUp.report(isP2P);
558
-            this._avgVideoBitrateDown.report(isP2P);
593
+            this._avgAudioBitrateUp.appendReport(batchReport, isP2P);
594
+            this._avgAudioBitrateDown.appendReport(batchReport, isP2P);
595
+
596
+            this._avgVideoBitrateUp.appendReport(batchReport, isP2P);
597
+            this._avgVideoBitrateDown.appendReport(batchReport, isP2P);
559 598
 
560 599
             if (RTCBrowserType.supportsBandwidthStatistics()) {
561
-                this._avgBandwidthUp.report(isP2P);
562
-                this._avgBandwidthDown.report(isP2P);
600
+                this._avgBandwidthUp.appendReport(batchReport, isP2P);
601
+                this._avgBandwidthDown.appendReport(batchReport, isP2P);
563 602
             }
564
-            this._avgPacketLossUp.report(isP2P);
565
-            this._avgPacketLossDown.report(isP2P);
566
-            this._avgPacketLossTotal.report(isP2P);
603
+            this._avgPacketLossUp.appendReport(batchReport, isP2P);
604
+            this._avgPacketLossDown.appendReport(batchReport, isP2P);
605
+            this._avgPacketLossTotal.appendReport(batchReport, isP2P);
567 606
 
568
-            this._avgRemoteFPS.report(isP2P);
607
+            this._avgRemoteFPS.appendReport(batchReport, isP2P);
569 608
             if (!isNaN(this._avgRemoteScreenFPS.calculate())) {
570
-                this._avgRemoteScreenFPS.report(isP2P);
609
+                this._avgRemoteScreenFPS.appendReport(batchReport, isP2P);
571 610
             }
572
-            this._avgLocalFPS.report(isP2P);
611
+            this._avgLocalFPS.appendReport(batchReport, isP2P);
573 612
             if (!isNaN(this._avgLocalScreenFPS.calculate())) {
574
-                this._avgLocalScreenFPS.report(isP2P);
613
+                this._avgLocalScreenFPS.appendReport(batchReport, isP2P);
575 614
             }
576 615
 
577
-            this._avgCQ.report(isP2P);
616
+            this._avgCQ.appendReport(batchReport, isP2P);
617
+
618
+            Statistics.analytics.sendEvent(AVG_RTP_STATS_EVENT, batchReport);
578 619
 
579 620
             this._resetAvgStats();
580 621
         }

Loading…
Откажи
Сачувај