Skip to content

Commit b93ddef

Browse files
authored
fix(meetings): added reachability trigger to metrics (#3850)
1 parent 0af7097 commit b93ddef

File tree

5 files changed

+94
-22
lines changed

5 files changed

+94
-22
lines changed

packages/@webex/plugin-meetings/src/meetings/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ export default class Meetings extends WebexPlugin {
765765
return Promise.all([
766766
this.fetchUserPreferredWebexSite(),
767767
this.getGeoHint(),
768-
this.startReachability().catch((error) => {
768+
this.startReachability('registration').catch((error) => {
769769
LoggerProxy.logger.error(`Meetings:index#register --> GDM error, ${error.message}`);
770770
}),
771771
// @ts-ignore
@@ -967,12 +967,13 @@ export default class Meetings extends WebexPlugin {
967967

968968
/**
969969
* initializes and starts gathering reachability for Meetings
970+
* @param {string} trigger - explains the reason for starting reachability
970971
* @returns {Promise}
971972
* @public
972973
* @memberof Meetings
973974
*/
974-
startReachability() {
975-
return this.getReachability().gatherReachability();
975+
startReachability(trigger = 'client') {
976+
return this.getReachability().gatherReachability(trigger);
976977
}
977978

978979
/**

packages/@webex/plugin-meetings/src/reachability/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export default class Reachability extends EventsScope {
9393
expectedResultsCount = {videoMesh: {udp: 0}, public: {udp: 0, tcp: 0, xtls: 0}};
9494
resultsCount = {videoMesh: {udp: 0}, public: {udp: 0, tcp: 0, xtls: 0}};
9595

96+
protected lastTrigger?: string;
97+
9698
/**
9799
* Creates an instance of Reachability.
98100
* @param {object} webex
@@ -142,13 +144,16 @@ export default class Reachability extends EventsScope {
142144

143145
/**
144146
* Gets a list of media clusters from the backend and performs reachability checks on all the clusters
147+
* @param {string} trigger - explains the reason for starting reachability
145148
* @returns {Promise<ReachabilityResults>} reachability results
146149
* @public
147150
* @memberof Reachability
148151
*/
149-
public async gatherReachability(): Promise<ReachabilityResults> {
152+
public async gatherReachability(trigger: string): Promise<ReachabilityResults> {
150153
// Fetch clusters and measure latency
151154
try {
155+
this.lastTrigger = trigger;
156+
152157
// kick off ip version detection. For now we don't await it, as we're doing it
153158
// to gather the timings and send them with our reachability metrics
154159
// @ts-ignore
@@ -552,6 +557,7 @@ export default class Reachability extends EventsScope {
552557
// @ts-ignore
553558
totalTime: this.webex.internal.device.ipNetworkDetector.totalTime,
554559
},
560+
trigger: this.lastTrigger,
555561
};
556562
Metrics.sendBehavioralMetric(
557563
BEHAVIORAL_METRICS.REACHABILITY_COMPLETED,

packages/@webex/plugin-meetings/src/reconnection-manager/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export default class ReconnectionManager {
342342
}
343343

344344
try {
345-
await this.webex.meetings.startReachability();
345+
await this.webex.meetings.startReachability('reconnection');
346346
} catch (err) {
347347
LoggerProxy.logger.info(
348348
'ReconnectionManager:index#reconnect --> Reachability failed, continuing with reconnection attempt, err: ',

packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('plugin-meetings', () => {
7979
let locusInfo;
8080
let services;
8181
let catalog;
82+
let startReachabilityStub;
8283

8384
describe('meetings index', () => {
8485
beforeEach(() => {
@@ -129,9 +130,7 @@ describe('plugin-meetings', () => {
129130
logger,
130131
});
131132

132-
Object.assign(webex.meetings, {
133-
startReachability: sinon.stub().returns(Promise.resolve()),
134-
});
133+
startReachabilityStub = sinon.stub(webex.meetings, 'startReachability').resolves();
135134

136135
Object.assign(webex.internal, {
137136
llm: {on: sinon.stub()},
@@ -197,6 +196,34 @@ describe('plugin-meetings', () => {
197196
assert.calledOnce(MeetingsUtil.checkH264Support);
198197
});
199198

199+
describe('#startReachability', () => {
200+
let gatherReachabilitySpy;
201+
let fakeResult = {id: 'fake-result'};
202+
203+
beforeEach(() => {
204+
startReachabilityStub.restore();
205+
gatherReachabilitySpy = sinon
206+
.stub(webex.meetings.getReachability(), 'gatherReachability')
207+
.resolves(fakeResult);
208+
});
209+
210+
it('should gather reachability with default trigger value', async () => {
211+
const result = await webex.meetings.startReachability();
212+
213+
assert.calledOnceWithExactly(gatherReachabilitySpy, 'client');
214+
assert.equal(result, fakeResult);
215+
});
216+
217+
it('should gather reachability and pass custom trigger value', async () => {
218+
const trigger = 'custom-trigger';
219+
220+
const result = await webex.meetings.startReachability(trigger);
221+
222+
assert.calledOnceWithExactly(gatherReachabilitySpy, trigger);
223+
assert.equal(result, fakeResult);
224+
});
225+
});
226+
200227
describe('#_toggleUnifiedMeetings', () => {
201228
it('should have toggleUnifiedMeetings', () => {
202229
assert.equal(typeof webex.meetings._toggleUnifiedMeetings, 'function');

packages/@webex/plugin-meetings/test/unit/spec/reachability/index.ts

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import sinon from 'sinon';
44
import EventEmitter from 'events';
55
import testUtils from '../../../utils/testUtils';
66
import Reachability, {
7-
ReachabilityResults,
87
ReachabilityResultsForBackend,
98
} from '@webex/plugin-meetings/src/reachability/';
109
import {ClusterNode} from '../../../../src/reachability/request';
@@ -507,6 +506,11 @@ describe('gatherReachability', () => {
507506
mockClusterReachabilityInstances[id] = mockInstance;
508507
return mockInstance;
509508
});
509+
510+
webex.config.meetings.experimental = {
511+
enableTcpReachability: false,
512+
enableTlsReachability: false,
513+
};
510514
});
511515

512516
afterEach(() => {
@@ -1044,13 +1048,14 @@ describe('gatherReachability', () => {
10441048
enableTlsReachability: true,
10451049
};
10461050

1047-
// the metrics related to ipver are not tested in these tests and are all the same, so setting them up here
1051+
// the metrics related to ipver and trigger are not tested in these tests and are all the same, so setting them up here
10481052
const expectedMetricsFull = {
10491053
...expectedMetrics,
10501054
ipver_firstIpV4: -1,
10511055
ipver_firstIpV6: -1,
10521056
ipver_firstMdns: -1,
10531057
ipver_totalTime: -1,
1058+
trigger: 'test',
10541059
};
10551060

10561061
const receivedEvents = {
@@ -1082,7 +1087,7 @@ describe('gatherReachability', () => {
10821087

10831088
reachability.reachabilityRequest.getClusters = sinon.stub().returns(mockGetClustersResult);
10841089

1085-
const resultPromise = reachability.gatherReachability();
1090+
const resultPromise = reachability.gatherReachability('test');
10861091

10871092
await testUtils.flushPromises();
10881093

@@ -1142,6 +1147,38 @@ describe('gatherReachability', () => {
11421147
})
11431148
);
11441149

1150+
it('sends the trigger parameter in the metrics', async () => {
1151+
const reachability = new TestReachability(webex);
1152+
1153+
const mockGetClustersResult = {
1154+
clusters: {
1155+
clusterA: {
1156+
udp: ['udp-url'],
1157+
tcp: [],
1158+
xtls: [],
1159+
isVideoMesh: false,
1160+
},
1161+
},
1162+
joinCookie: {id: 'id'},
1163+
};
1164+
1165+
reachability.reachabilityRequest.getClusters = sinon.stub().returns(mockGetClustersResult);
1166+
1167+
const resultPromise = reachability.gatherReachability('some trigger');
1168+
1169+
// let it time out
1170+
await testUtils.flushPromises();
1171+
clock.tick(15000);
1172+
await resultPromise;
1173+
1174+
// check the metric contains the right trigger value
1175+
assert.calledWith(
1176+
Metrics.sendBehavioralMetric,
1177+
'js_sdk_reachability_completed',
1178+
sinon.match({trigger: 'some trigger'})
1179+
);
1180+
});
1181+
11451182
it(`starts ip network version detection and includes the results in the metrics`, async () => {
11461183
webex.config.meetings.experimental = {
11471184
enableTcpReachability: true,
@@ -1180,7 +1217,7 @@ describe('gatherReachability', () => {
11801217
joinCookie: {id: 'id'},
11811218
});
11821219

1183-
const resultPromise = reachability.gatherReachability();
1220+
const resultPromise = reachability.gatherReachability('test');
11841221

11851222
await testUtils.flushPromises();
11861223

@@ -1217,6 +1254,7 @@ describe('gatherReachability', () => {
12171254
ipver_firstIpV6: webex.internal.device.ipNetworkDetector.firstIpV6,
12181255
ipver_firstMdns: webex.internal.device.ipNetworkDetector.firstMdns,
12191256
ipver_totalTime: webex.internal.device.ipNetworkDetector.totalTime,
1257+
trigger: 'test',
12201258
});
12211259
});
12221260

@@ -1248,7 +1286,7 @@ describe('gatherReachability', () => {
12481286

12491287
reachability.reachabilityRequest.getClusters = sinon.stub().returns(mockGetClustersResult);
12501288

1251-
const resultPromise = reachability.gatherReachability();
1289+
const resultPromise = reachability.gatherReachability('test');
12521290

12531291
await testUtils.flushPromises();
12541292

@@ -1341,7 +1379,7 @@ describe('gatherReachability', () => {
13411379

13421380
reachability.reachabilityRequest.getClusters = sinon.stub().returns(mockGetClustersResult);
13431381

1344-
const resultPromise = reachability.gatherReachability();
1382+
const resultPromise = reachability.gatherReachability('test');
13451383

13461384
await testUtils.flushPromises();
13471385

@@ -1382,7 +1420,7 @@ describe('gatherReachability', () => {
13821420

13831421
reachability.reachabilityRequest.getClusters = sinon.stub().throws();
13841422

1385-
const result = await reachability.gatherReachability();
1423+
const result = await reachability.gatherReachability('test');
13861424

13871425
assert.empty(result);
13881426

@@ -1400,7 +1438,7 @@ describe('gatherReachability', () => {
14001438
reachability.reachabilityRequest.getClusters = sinon.stub().returns(getClustersResult);
14011439
(reachability as any).performReachabilityChecks = sinon.stub().throws();
14021440

1403-
const result = await reachability.gatherReachability();
1441+
const result = await reachability.gatherReachability('test');
14041442

14051443
assert.empty(result);
14061444

@@ -1435,7 +1473,7 @@ describe('gatherReachability', () => {
14351473

14361474
reachability.reachabilityRequest.getClusters = sinon.stub().returns(getClustersResult);
14371475

1438-
const promise = reachability.gatherReachability();
1476+
const promise = reachability.gatherReachability('test');
14391477

14401478
await simulateTimeout();
14411479
await promise;
@@ -1481,7 +1519,7 @@ describe('gatherReachability', () => {
14811519

14821520
reachability.reachabilityRequest.getClusters = sinon.stub().returns(getClustersResult);
14831521

1484-
const promise = reachability.gatherReachability();
1522+
const promise = reachability.gatherReachability('test');
14851523
await simulateTimeout();
14861524
await promise;
14871525

@@ -1515,7 +1553,7 @@ describe('gatherReachability', () => {
15151553

15161554
reachability.reachabilityRequest.getClusters = sinon.stub().returns(getClustersResult);
15171555

1518-
const promise = reachability.gatherReachability();
1556+
const promise = reachability.gatherReachability('test');
15191557

15201558
await simulateTimeout();
15211559
await promise;
@@ -1550,7 +1588,7 @@ describe('gatherReachability', () => {
15501588

15511589
reachability.reachabilityRequest.getClusters = sinon.stub().returns(getClustersResult);
15521590

1553-
const promise = reachability.gatherReachability();
1591+
const promise = reachability.gatherReachability('test');
15541592

15551593
await simulateTimeout();
15561594
await promise;
@@ -1595,7 +1633,7 @@ describe('gatherReachability', () => {
15951633
return getClustersResult;
15961634
});
15971635

1598-
const promise = reachability.gatherReachability();
1636+
const promise = reachability.gatherReachability('test');
15991637

16001638
await simulateTimeout();
16011639
await promise;
@@ -1616,7 +1654,7 @@ describe('gatherReachability', () => {
16161654
throw new Error('fake error');
16171655
});
16181656

1619-
const promise = reachability.gatherReachability();
1657+
const promise = reachability.gatherReachability('test');
16201658

16211659
await simulateTimeout();
16221660

0 commit comments

Comments
 (0)