Ver código fonte

feat(stats): Add the ability to enable callStats only on a certain % of conferences

master
Jaya Allamsetty 4 anos atrás
pai
commit
a433ca2dbc
Nenhuma conta vinculada ao e-mail do autor do commit
3 arquivos alterados com 29 adições e 1 exclusões
  1. 9
    0
      JitsiConference.js
  2. 1
    1
      modules/statistics/statistics.js
  3. 19
    0
      modules/util/MathUtil.js

+ 9
- 0
JitsiConference.js Ver arquivo

@@ -38,6 +38,7 @@ import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
38 38
 import Statistics from './modules/statistics/statistics';
39 39
 import Transcriber from './modules/transcription/transcriber';
40 40
 import GlobalOnErrorHandler from './modules/util/GlobalOnErrorHandler';
41
+import { hashString } from './modules/util/MathUtil';
41 42
 import RandomUtil from './modules/util/RandomUtil';
42 43
 import ComponentsVersions from './modules/version/ComponentsVersions';
43 44
 import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
@@ -374,6 +375,13 @@ JitsiConference.prototype._init = function(options = {}) {
374 375
             });
375 376
     this.participantConnectionStatus.init();
376 377
 
378
+    // Add the ability to enable callStats only on a percentage of conferences based on config.js settings.
379
+    let enableCallStats = true;
380
+
381
+    if (config.testing && config.testing.callStatsThreshold) {
382
+        enableCallStats = (hashString(this.options.name) % 100) < config.testing.callStatsThreshold;
383
+    }
384
+
377 385
     if (!this.statistics) {
378 386
         this.statistics = new Statistics(this.xmpp, {
379 387
             aliasName: this._statsCurrentId,
@@ -384,6 +392,7 @@ JitsiConference.prototype._init = function(options = {}) {
384 392
             callStatsID: config.callStatsID,
385 393
             callStatsSecret: config.callStatsSecret,
386 394
             callStatsApplicationLogsDisabled: config.callStatsApplicationLogsDisabled,
395
+            enableCallStats,
387 396
             roomName: this.options.name,
388 397
             applicationName: config.applicationName,
389 398
             getWiFiStatsMethod: config.getWiFiStatsMethod

+ 1
- 1
modules/statistics/statistics.js Ver arquivo

@@ -160,7 +160,7 @@ export default function Statistics(xmpp, options) {
160 160
     this.options = options || {};
161 161
 
162 162
     this.callStatsIntegrationEnabled
163
-        = this.options.callStatsID && this.options.callStatsSecret
163
+        = this.options.callStatsID && this.options.callStatsSecret && this.options.enableCallStats
164 164
 
165 165
             // Even though AppID and AppSecret may be specified, the integration
166 166
             // of callstats.io may be disabled because of globally-disallowed

+ 19
- 0
modules/util/MathUtil.js Ver arquivo

@@ -27,6 +27,25 @@ export function calculateAverage(valueArray) {
27 27
     return valueArray.length > 0 ? valueArray.reduce((a, b) => a + b) / valueArray.length : 0;
28 28
 }
29 29
 
30
+/**
31
+ * Calculates a unique hash for a given string similar to Java's
32
+ * implementation of String.hashCode()
33
+ *
34
+ * @param {String} string - String whose hash has to be calculated.
35
+ * @returns {number} - Unique hash code calculated.
36
+ */
37
+export function hashString(string) {
38
+    let hash = 0;
39
+
40
+    for (let i = 0; i < string.length; i++) {
41
+        hash += Math.pow(string.charCodeAt(i) * 31, string.length - i);
42
+
43
+        /* eslint-disable no-bitwise */
44
+        hash = hash & hash; // Convert to 32bit integer
45
+    }
46
+
47
+    return Math.abs(hash);
48
+}
30 49
 
31 50
 /**
32 51
  * Returns only the positive values from an array of numbers.

Carregando…
Cancelar
Salvar