浏览代码

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

release-8443
Jaya Allamsetty 5 年前
父节点
当前提交
a433ca2dbc
没有帐户链接到提交者的电子邮件
共有 3 个文件被更改,包括 29 次插入1 次删除
  1. 9
    0
      JitsiConference.js
  2. 1
    1
      modules/statistics/statistics.js
  3. 19
    0
      modules/util/MathUtil.js

+ 9
- 0
JitsiConference.js 查看文件

38
 import Statistics from './modules/statistics/statistics';
38
 import Statistics from './modules/statistics/statistics';
39
 import Transcriber from './modules/transcription/transcriber';
39
 import Transcriber from './modules/transcription/transcriber';
40
 import GlobalOnErrorHandler from './modules/util/GlobalOnErrorHandler';
40
 import GlobalOnErrorHandler from './modules/util/GlobalOnErrorHandler';
41
+import { hashString } from './modules/util/MathUtil';
41
 import RandomUtil from './modules/util/RandomUtil';
42
 import RandomUtil from './modules/util/RandomUtil';
42
 import ComponentsVersions from './modules/version/ComponentsVersions';
43
 import ComponentsVersions from './modules/version/ComponentsVersions';
43
 import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
44
 import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
374
             });
375
             });
375
     this.participantConnectionStatus.init();
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
     if (!this.statistics) {
385
     if (!this.statistics) {
378
         this.statistics = new Statistics(this.xmpp, {
386
         this.statistics = new Statistics(this.xmpp, {
379
             aliasName: this._statsCurrentId,
387
             aliasName: this._statsCurrentId,
384
             callStatsID: config.callStatsID,
392
             callStatsID: config.callStatsID,
385
             callStatsSecret: config.callStatsSecret,
393
             callStatsSecret: config.callStatsSecret,
386
             callStatsApplicationLogsDisabled: config.callStatsApplicationLogsDisabled,
394
             callStatsApplicationLogsDisabled: config.callStatsApplicationLogsDisabled,
395
+            enableCallStats,
387
             roomName: this.options.name,
396
             roomName: this.options.name,
388
             applicationName: config.applicationName,
397
             applicationName: config.applicationName,
389
             getWiFiStatsMethod: config.getWiFiStatsMethod
398
             getWiFiStatsMethod: config.getWiFiStatsMethod

+ 1
- 1
modules/statistics/statistics.js 查看文件

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

+ 19
- 0
modules/util/MathUtil.js 查看文件

27
     return valueArray.length > 0 ? valueArray.reduce((a, b) => a + b) / valueArray.length : 0;
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
  * Returns only the positive values from an array of numbers.
51
  * Returns only the positive values from an array of numbers.

正在加载...
取消
保存