@webex/internal-plugin-metrics 3.4.0 → 3.5.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/behavioral-metrics.js +63 -0
  2. package/dist/behavioral-metrics.js.map +1 -0
  3. package/dist/business-metrics.js +62 -0
  4. package/dist/business-metrics.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +15 -5
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -1
  7. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +14 -4
  8. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -1
  9. package/dist/{behavioral/behavioral-metrics.js → generic-metrics.js} +77 -92
  10. package/dist/generic-metrics.js.map +1 -0
  11. package/dist/index.js +15 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/metrics.js +1 -1
  14. package/dist/metrics.types.js.map +1 -1
  15. package/dist/new-metrics.js +122 -24
  16. package/dist/new-metrics.js.map +1 -1
  17. package/dist/operational-metrics.js +56 -0
  18. package/dist/operational-metrics.js.map +1 -0
  19. package/dist/types/behavioral-metrics.d.ts +25 -0
  20. package/dist/types/business-metrics.d.ts +19 -0
  21. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +21 -5
  22. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +2 -1
  23. package/dist/types/generic-metrics.d.ts +63 -0
  24. package/dist/types/index.d.ts +4 -2
  25. package/dist/types/metrics.types.d.ts +26 -14
  26. package/dist/types/new-metrics.d.ts +41 -9
  27. package/dist/types/operational-metrics.d.ts +19 -0
  28. package/package.json +12 -12
  29. package/src/behavioral-metrics.ts +40 -0
  30. package/src/business-metrics.ts +30 -0
  31. package/src/call-diagnostic/call-diagnostic-metrics.ts +19 -2
  32. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +17 -4
  33. package/src/generic-metrics.ts +146 -0
  34. package/src/index.ts +5 -1
  35. package/src/metrics.types.ts +30 -16
  36. package/src/new-metrics.ts +95 -17
  37. package/src/operational-metrics.ts +24 -0
  38. package/test/unit/spec/behavioral/behavioral-metrics.ts +51 -10
  39. package/test/unit/spec/business/business-metrics.ts +120 -0
  40. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +2 -1
  41. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +167 -1
  42. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +22 -8
  43. package/test/unit/spec/new-metrics.ts +14 -0
  44. package/test/unit/spec/operational/operational-metrics.ts +115 -0
  45. package/test/unit/spec/prelogin-metrics-batcher.ts +3 -1
  46. package/dist/behavioral/behavioral-metrics.js.map +0 -1
  47. package/dist/behavioral/config.js +0 -11
  48. package/dist/behavioral/config.js.map +0 -1
  49. package/dist/types/behavioral/behavioral-metrics.d.ts +0 -63
  50. package/dist/types/behavioral/config.d.ts +0 -1
  51. package/src/behavioral/behavioral-metrics.ts +0 -179
  52. package/src/behavioral/config.ts +0 -3
@@ -30,6 +30,7 @@ describe('internal-plugin-metrics', () => {
30
30
  const fakeMeeting = {
31
31
  id: '1',
32
32
  correlationId: 'correlationId',
33
+ sessionCorrelationId: undefined,
33
34
  callStateForMetrics: {},
34
35
  environment: 'meeting_evn',
35
36
  locusUrl: 'locus/url',
@@ -354,6 +355,36 @@ describe('internal-plugin-metrics', () => {
354
355
 
355
356
  assert.deepEqual(res, {
356
357
  correlationId: 'correlationId',
358
+ sessionCorrelationId: undefined,
359
+ deviceId: 'deviceUrl',
360
+ locusId: 'url',
361
+ locusStartTime: 'lastActive',
362
+ locusUrl: 'locus/url',
363
+ machineId: 'installationId',
364
+ mediaAgentAlias: 'mediaAgentAlias',
365
+ mediaAgentGroupId: 'mediaAgentGroupId',
366
+ orgId: 'orgId',
367
+ userId: 'userId',
368
+ });
369
+ });
370
+
371
+ it('should build identifiers correctly', () => {
372
+ cd.device = {
373
+ ...cd.device,
374
+ config: {installationId: 'installationId'},
375
+ };
376
+
377
+ const res = cd.getIdentifiers({
378
+ mediaConnections: [
379
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
380
+ ],
381
+ meeting: fakeMeeting,
382
+ sessionCorrelationId: 'sessionCorrelationId',
383
+ });
384
+
385
+ assert.deepEqual(res, {
386
+ correlationId: 'correlationId',
387
+ sessionCorrelationId: 'sessionCorrelationId',
357
388
  deviceId: 'deviceUrl',
358
389
  locusId: 'url',
359
390
  locusStartTime: 'lastActive',
@@ -372,6 +403,7 @@ describe('internal-plugin-metrics', () => {
372
403
  {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
373
404
  ],
374
405
  webexConferenceIdStr: 'webexConferenceIdStr',
406
+ sessionCorrelationId: 'sessionCorrelationId',
375
407
  globalMeetingId: 'globalMeetingId',
376
408
  meeting: {
377
409
  ...fakeMeeting,
@@ -386,6 +418,7 @@ describe('internal-plugin-metrics', () => {
386
418
  assert.deepEqual(res, {
387
419
  correlationId: 'correlationId',
388
420
  webexConferenceIdStr: 'webexConferenceIdStr1',
421
+ sessionCorrelationId: 'sessionCorrelationId',
389
422
  globalMeetingId: 'globalMeetingId1',
390
423
  deviceId: 'deviceUrl',
391
424
  locusId: 'url',
@@ -417,6 +450,7 @@ describe('internal-plugin-metrics', () => {
417
450
 
418
451
  assert.deepEqual(res, {
419
452
  correlationId: 'correlationId',
453
+ sessionCorrelationId: undefined,
420
454
  webexConferenceIdStr: 'webexConferenceIdStr1',
421
455
  globalMeetingId: 'globalMeetingId1',
422
456
  deviceId: 'deviceUrl',
@@ -450,6 +484,43 @@ describe('internal-plugin-metrics', () => {
450
484
 
451
485
  assert.deepEqual(res, {
452
486
  correlationId: 'correlationId',
487
+ sessionCorrelationId: undefined,
488
+ webexConferenceIdStr: 'webexConferenceIdStr1',
489
+ globalMeetingId: 'globalMeetingId1',
490
+ deviceId: 'deviceUrl',
491
+ locusId: 'url',
492
+ locusStartTime: 'lastActive',
493
+ locusUrl: 'locus/url',
494
+ mediaAgentAlias: 'mediaAgentAlias',
495
+ mediaAgentGroupId: 'mediaAgentGroupId',
496
+ orgId: 'orgId',
497
+ userId: 'userId',
498
+ webexSiteName: 'siteName1',
499
+ });
500
+ });
501
+
502
+ it('should build identifiers correctly with a meeting that has sessionCorrelationId', () => {
503
+ const res = cd.getIdentifiers({
504
+ mediaConnections: [
505
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
506
+ ],
507
+ webexConferenceIdStr: 'webexConferenceIdStr',
508
+ globalMeetingId: 'globalMeetingId',
509
+ meeting: {
510
+ ...fakeMeeting,
511
+ sessionCorrelationId: 'sessionCorrelationId1',
512
+ meetingInfo: {
513
+ ...fakeMeeting.meetingInfo,
514
+ confIdStr: 'webexConferenceIdStr1',
515
+ meetingId: 'globalMeetingId1',
516
+ siteName: 'siteName1',
517
+ },
518
+ },
519
+ });
520
+
521
+ assert.deepEqual(res, {
522
+ correlationId: 'correlationId',
523
+ sessionCorrelationId: 'sessionCorrelationId1',
453
524
  webexConferenceIdStr: 'webexConferenceIdStr1',
454
525
  globalMeetingId: 'globalMeetingId1',
455
526
  deviceId: 'deviceUrl',
@@ -472,6 +543,7 @@ describe('internal-plugin-metrics', () => {
472
543
 
473
544
  assert.deepEqual(res, {
474
545
  correlationId: 'correlationId',
546
+ sessionCorrelationId: 'unknown',
475
547
  webexConferenceIdStr: 'webexConferenceIdStr1',
476
548
  deviceId: 'deviceUrl',
477
549
  locusUrl: 'locus-url',
@@ -488,6 +560,7 @@ describe('internal-plugin-metrics', () => {
488
560
 
489
561
  assert.deepEqual(res, {
490
562
  correlationId: 'correlationId',
563
+ sessionCorrelationId: 'unknown',
491
564
  globalMeetingId: 'globalMeetingId1',
492
565
  deviceId: 'deviceUrl',
493
566
  locusUrl: 'locus-url',
@@ -503,6 +576,23 @@ describe('internal-plugin-metrics', () => {
503
576
 
504
577
  assert.deepEqual(res, {
505
578
  correlationId: 'correlationId',
579
+ sessionCorrelationId: 'unknown',
580
+ deviceId: 'deviceUrl',
581
+ locusUrl: 'locus-url',
582
+ orgId: 'orgId',
583
+ userId: 'userId',
584
+ });
585
+ });
586
+
587
+ it('should build identifiers correctly given sessionCorrelationId', () => {
588
+ const res = cd.getIdentifiers({
589
+ correlationId: 'correlationId',
590
+ sessionCorrelationId: 'sessionCorrelationId',
591
+ });
592
+
593
+ assert.deepEqual(res, {
594
+ correlationId: 'correlationId',
595
+ sessionCorrelationId: 'sessionCorrelationId',
506
596
  deviceId: 'deviceUrl',
507
597
  locusUrl: 'locus-url',
508
598
  orgId: 'orgId',
@@ -531,6 +621,7 @@ describe('internal-plugin-metrics', () => {
531
621
 
532
622
  assert.deepEqual(res, {
533
623
  correlationId: 'correlationId',
624
+ sessionCorrelationId: 'unknown',
534
625
  locusUrl: 'locus-url',
535
626
  deviceId: 'deviceUrl',
536
627
  orgId: 'orgId',
@@ -608,6 +699,7 @@ describe('internal-plugin-metrics', () => {
608
699
  meeting: fakeMeeting,
609
700
  mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
610
701
  webexConferenceIdStr: undefined,
702
+ sessionCorrelationId: undefined,
611
703
  globalMeetingId: undefined,
612
704
  });
613
705
  assert.notCalled(generateClientEventErrorPayloadSpy);
@@ -620,6 +712,7 @@ describe('internal-plugin-metrics', () => {
620
712
  },
621
713
  identifiers: {
622
714
  correlationId: 'correlationId',
715
+ sessionCorrelationId: undefined,
623
716
  deviceId: 'deviceUrl',
624
717
  locusId: 'url',
625
718
  locusStartTime: 'lastActive',
@@ -645,6 +738,7 @@ describe('internal-plugin-metrics', () => {
645
738
  },
646
739
  identifiers: {
647
740
  correlationId: 'correlationId',
741
+ sessionCorrelationId: undefined,
648
742
  deviceId: 'deviceUrl',
649
743
  locusId: 'url',
650
744
  locusStartTime: 'lastActive',
@@ -681,6 +775,7 @@ describe('internal-plugin-metrics', () => {
681
775
  },
682
776
  identifiers: {
683
777
  correlationId: 'correlationId',
778
+ sessionCorrelationId: undefined,
684
779
  deviceId: 'deviceUrl',
685
780
  locusId: 'url',
686
781
  locusStartTime: 'lastActive',
@@ -762,7 +857,7 @@ describe('internal-plugin-metrics', () => {
762
857
  ]);
763
858
  });
764
859
 
765
- it('should submit client event successfully with correlationId, webexConferenceIdStr and globalMeetingId', () => {
860
+ it('should submit client event successfully with correlationId, webexConferenceIdStr, sessionCorrelationId, and globalMeetingId', () => {
766
861
  const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
767
862
  const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
768
863
  const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
@@ -773,6 +868,7 @@ describe('internal-plugin-metrics', () => {
773
868
  correlationId: 'correlationId',
774
869
  webexConferenceIdStr: 'webexConferenceIdStr1',
775
870
  globalMeetingId: 'globalMeetingId1',
871
+ sessionCorrelationId: 'sessionCorrelationId1'
776
872
  };
777
873
 
778
874
  cd.submitClientEvent({
@@ -784,6 +880,7 @@ describe('internal-plugin-metrics', () => {
784
880
  correlationId: 'correlationId',
785
881
  webexConferenceIdStr: 'webexConferenceIdStr1',
786
882
  globalMeetingId: 'globalMeetingId1',
883
+ sessionCorrelationId: 'sessionCorrelationId1',
787
884
  preLoginId: undefined,
788
885
  });
789
886
 
@@ -798,6 +895,7 @@ describe('internal-plugin-metrics', () => {
798
895
  identifiers: {
799
896
  correlationId: 'correlationId',
800
897
  webexConferenceIdStr: 'webexConferenceIdStr1',
898
+ sessionCorrelationId: 'sessionCorrelationId1',
801
899
  globalMeetingId: 'globalMeetingId1',
802
900
  deviceId: 'deviceUrl',
803
901
  locusUrl: 'locus-url',
@@ -818,6 +916,7 @@ describe('internal-plugin-metrics', () => {
818
916
  identifiers: {
819
917
  correlationId: 'correlationId',
820
918
  webexConferenceIdStr: 'webexConferenceIdStr1',
919
+ sessionCorrelationId: 'sessionCorrelationId1',
821
920
  globalMeetingId: 'globalMeetingId1',
822
921
  deviceId: 'deviceUrl',
823
922
  locusUrl: 'locus-url',
@@ -863,6 +962,7 @@ describe('internal-plugin-metrics', () => {
863
962
  webexConferenceIdStr: 'webexConferenceIdStr1',
864
963
  globalMeetingId: 'globalMeetingId1',
865
964
  preLoginId: 'myPreLoginId',
965
+ sessionCorrelationId: 'sessionCorrelationId1'
866
966
  };
867
967
 
868
968
  cd.submitClientEvent({
@@ -875,6 +975,7 @@ describe('internal-plugin-metrics', () => {
875
975
  webexConferenceIdStr: 'webexConferenceIdStr1',
876
976
  globalMeetingId: 'globalMeetingId1',
877
977
  preLoginId: 'myPreLoginId',
978
+ sessionCorrelationId: 'sessionCorrelationId1'
878
979
  });
879
980
 
880
981
  assert.notCalled(generateClientEventErrorPayloadSpy);
@@ -887,6 +988,7 @@ describe('internal-plugin-metrics', () => {
887
988
  },
888
989
  identifiers: {
889
990
  correlationId: 'correlationId',
991
+ sessionCorrelationId: 'sessionCorrelationId1',
890
992
  webexConferenceIdStr: 'webexConferenceIdStr1',
891
993
  globalMeetingId: 'globalMeetingId1',
892
994
  deviceId: 'deviceUrl',
@@ -913,6 +1015,7 @@ describe('internal-plugin-metrics', () => {
913
1015
  canProceed: true,
914
1016
  identifiers: {
915
1017
  correlationId: 'correlationId',
1018
+ sessionCorrelationId: 'sessionCorrelationId1',
916
1019
  userId: 'myPreLoginId',
917
1020
  deviceId: 'deviceUrl',
918
1021
  orgId: 'orgId',
@@ -949,6 +1052,58 @@ describe('internal-plugin-metrics', () => {
949
1052
  },
950
1053
  identifiers: {
951
1054
  correlationId: 'correlationId2',
1055
+ sessionCorrelationId: undefined,
1056
+ deviceId: 'deviceUrl',
1057
+ locusId: 'url',
1058
+ locusStartTime: 'lastActive',
1059
+ locusUrl: 'locus/url',
1060
+ mediaAgentAlias: 'alias',
1061
+ mediaAgentGroupId: '1',
1062
+ orgId: 'orgId',
1063
+ userId: 'userId',
1064
+ },
1065
+ loginType: 'fakeLoginType',
1066
+ name: 'client.alert.displayed',
1067
+ userType: 'host',
1068
+ isConvergedArchitectureEnabled: undefined,
1069
+ webexSubServiceType: undefined,
1070
+ },
1071
+ eventId: 'my-fake-id',
1072
+ origin: {
1073
+ origin: 'fake-origin',
1074
+ },
1075
+ originTime: {
1076
+ sent: 'not_defined_yet',
1077
+ triggered: now.toISOString(),
1078
+ },
1079
+ senderCountryCode: 'UK',
1080
+ version: 1,
1081
+ });
1082
+ });
1083
+
1084
+ it('should use meeting loginType if present and meetingId provided, with sessionCorrelationId', () => {
1085
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
1086
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
1087
+ const options = {
1088
+ meetingId: fakeMeeting2.id,
1089
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
1090
+ sessionCorrelationId: 'sessionCorrelationId1'
1091
+ };
1092
+
1093
+ cd.submitClientEvent({
1094
+ name: 'client.alert.displayed',
1095
+ options,
1096
+ });
1097
+
1098
+ assert.calledWith(submitToCallDiagnosticsSpy, {
1099
+ event: {
1100
+ canProceed: true,
1101
+ eventData: {
1102
+ webClientDomain: 'whatever',
1103
+ },
1104
+ identifiers: {
1105
+ correlationId: 'correlationId2',
1106
+ sessionCorrelationId: 'sessionCorrelationId1',
952
1107
  deviceId: 'deviceUrl',
953
1108
  locusId: 'url',
954
1109
  locusStartTime: 'lastActive',
@@ -1006,6 +1161,7 @@ describe('internal-plugin-metrics', () => {
1006
1161
  },
1007
1162
  identifiers: {
1008
1163
  correlationId: 'correlationId',
1164
+ sessionCorrelationId: undefined,
1009
1165
  webexConferenceIdStr: 'webexConferenceIdStr1',
1010
1166
  globalMeetingId: 'globalMeetingId1',
1011
1167
  deviceId: 'deviceUrl',
@@ -1084,6 +1240,7 @@ describe('internal-plugin-metrics', () => {
1084
1240
  },
1085
1241
  identifiers: {
1086
1242
  correlationId: 'correlationId',
1243
+ sessionCorrelationId: undefined,
1087
1244
  deviceId: 'deviceUrl',
1088
1245
  locusId: 'url',
1089
1246
  locusStartTime: 'lastActive',
@@ -1159,6 +1316,7 @@ describe('internal-plugin-metrics', () => {
1159
1316
  },
1160
1317
  identifiers: {
1161
1318
  correlationId: 'correlationId',
1319
+ sessionCorrelationId: 'unknown',
1162
1320
  deviceId: 'deviceUrl',
1163
1321
  locusUrl: 'locus-url',
1164
1322
  orgId: 'orgId',
@@ -1232,6 +1390,7 @@ describe('internal-plugin-metrics', () => {
1232
1390
  },
1233
1391
  identifiers: {
1234
1392
  correlationId: 'correlationId',
1393
+ sessionCorrelationId: 'unknown',
1235
1394
  deviceId: 'deviceUrl',
1236
1395
  locusUrl: 'locus-url',
1237
1396
  orgId: 'orgId',
@@ -1311,6 +1470,7 @@ describe('internal-plugin-metrics', () => {
1311
1470
  },
1312
1471
  identifiers: {
1313
1472
  correlationId: 'correlationId',
1473
+ sessionCorrelationId: undefined,
1314
1474
  deviceId: 'deviceUrl',
1315
1475
  locusId: 'url',
1316
1476
  locusStartTime: 'lastActive',
@@ -1417,6 +1577,7 @@ describe('internal-plugin-metrics', () => {
1417
1577
  meetingId: fakeMeeting.id,
1418
1578
  webexConferenceIdStr: 'webexConferenceIdStr1',
1419
1579
  globalMeetingId: 'globalMeetingId1',
1580
+ sessionCorrelationId: 'sessionCorrelationId1'
1420
1581
  };
1421
1582
 
1422
1583
  cd.submitMQE({
@@ -1442,6 +1603,7 @@ describe('internal-plugin-metrics', () => {
1442
1603
  canProceed: true,
1443
1604
  identifiers: {
1444
1605
  correlationId: 'correlationId',
1606
+ sessionCorrelationId: undefined,
1445
1607
  webexConferenceIdStr: 'webexConferenceIdStr1',
1446
1608
  globalMeetingId: 'globalMeetingId1',
1447
1609
  userId: 'userId',
@@ -1481,6 +1643,7 @@ describe('internal-plugin-metrics', () => {
1481
1643
  canProceed: true,
1482
1644
  identifiers: {
1483
1645
  correlationId: 'correlationId',
1646
+ sessionCorrelationId: undefined,
1484
1647
  webexConferenceIdStr: 'webexConferenceIdStr1',
1485
1648
  globalMeetingId: 'globalMeetingId1',
1486
1649
  userId: 'userId',
@@ -1526,6 +1689,7 @@ describe('internal-plugin-metrics', () => {
1526
1689
  locusUrl: 'locus/url',
1527
1690
  locusId: 'url',
1528
1691
  locusStartTime: 'lastActive',
1692
+ sessionCorrelationId: undefined,
1529
1693
  },
1530
1694
  eventData: {webClientDomain: 'whatever'},
1531
1695
  intervals: [{}],
@@ -2279,6 +2443,7 @@ describe('internal-plugin-metrics', () => {
2279
2443
  locusUrl: 'locus/url',
2280
2444
  orgId: 'orgId',
2281
2445
  userId: 'userId',
2446
+ sessionCorrelationId: undefined,
2282
2447
  },
2283
2448
  loginType: 'login-ci',
2284
2449
  name: 'client.exit.app',
@@ -2302,6 +2467,7 @@ describe('internal-plugin-metrics', () => {
2302
2467
  environment: 'meeting_evn',
2303
2468
  name: 'endpoint',
2304
2469
  networkType: 'unknown',
2470
+ upgradeChannel: 'test',
2305
2471
  userAgent,
2306
2472
  },
2307
2473
  originTime: {
@@ -235,6 +235,8 @@ describe('internal-plugin-metrics', () => {
235
235
  });
236
236
 
237
237
  describe('getBuildType', () => {
238
+ const webex = {internal: {metrics: {config: {}}}};
239
+
238
240
  beforeEach(() => {
239
241
  process.env.NODE_ENV = 'production';
240
242
  });
@@ -246,25 +248,33 @@ describe('internal-plugin-metrics', () => {
246
248
  ['https://web.webex.com', true, 'test'],
247
249
  ].forEach(([webClientDomain, markAsTestEvent, expected]) => {
248
250
  it(`returns expected result for ${webClientDomain}`, () => {
249
- assert.deepEqual(getBuildType(webClientDomain, markAsTestEvent as any), expected);
251
+ assert.deepEqual(getBuildType(webex, webClientDomain, markAsTestEvent as any), expected);
250
252
  });
251
253
  });
252
254
 
253
255
  it('returns "test" for NODE_ENV "foo"', () => {
254
256
  process.env.NODE_ENV = 'foo';
255
- assert.deepEqual(getBuildType('production'), 'test');
257
+ assert.deepEqual(getBuildType(webex, 'production'), 'test');
256
258
  });
257
259
 
258
260
  it('returns "test" for NODE_ENV "production" and markAsTestEvent = true', () => {
259
261
  process.env.NODE_ENV = 'production';
260
- assert.deepEqual(getBuildType('my.domain', true), 'test');
262
+ assert.deepEqual(getBuildType(webex, 'my.domain', true), 'test');
263
+ });
264
+
265
+ it('returns "test" for NODE_ENV "production" when webex.caBuildType = "test"', () => {
266
+ process.env.NODE_ENV = 'production';
267
+ assert.deepEqual(
268
+ getBuildType({internal: {metrics: {config: {caBuildType: 'test'}}}}, 'my.domain'),
269
+ 'test'
270
+ );
261
271
  });
262
272
  });
263
273
 
264
274
  describe('prepareDiagnosticMetricItem', () => {
265
275
  let webex: any;
266
276
 
267
- const check = (eventName: string, expectedEvent: any) => {
277
+ const check = (eventName: string, expectedEvent: any, expectedUpgradeChannel: string) => {
268
278
  const eventPayload = {event: {name: eventName}};
269
279
  const item = prepareDiagnosticMetricItem(webex, {
270
280
  eventPayload,
@@ -276,6 +286,7 @@ describe('internal-plugin-metrics', () => {
276
286
  origin: {
277
287
  buildType: 'prod',
278
288
  networkType: 'unknown',
289
+ upgradeChannel: expectedUpgradeChannel
279
290
  },
280
291
  event: {name: eventName, ...expectedEvent},
281
292
  },
@@ -407,19 +418,19 @@ describe('internal-plugin-metrics', () => {
407
418
  ],
408
419
  ].forEach(([eventName, expectedEvent]) => {
409
420
  it(`returns expected result for ${eventName}`, () => {
410
- check(eventName as string, expectedEvent);
421
+ check(eventName as string, expectedEvent, 'gold');
411
422
  });
412
423
  });
413
424
 
414
- it('getBuildType returns correct value', () => {
425
+ it('sets buildType and upgradeChannel correctly', () => {
415
426
  const item: any = {
416
427
  eventPayload: {
417
428
  event: {
418
429
  name: 'client.exit.app',
419
430
  eventData: {
420
431
  markAsTestEvent: true,
421
- webClientDomain: 'https://web.webex.com'
422
- }
432
+ webClientDomain: 'https://web.webex.com',
433
+ },
423
434
  },
424
435
  },
425
436
  type: ['diagnostic-event'],
@@ -428,11 +439,14 @@ describe('internal-plugin-metrics', () => {
428
439
  // just submit any event
429
440
  prepareDiagnosticMetricItem(webex, item);
430
441
  assert.deepEqual(item.eventPayload.origin.buildType, 'test');
442
+ assert.deepEqual(item.eventPayload.origin.upgradeChannel, 'test');
431
443
 
432
444
  delete item.eventPayload.origin.buildType;
445
+ delete item.eventPayload.origin.upgradeChannel;
433
446
  item.eventPayload.event.eventData.markAsTestEvent = false;
434
447
  prepareDiagnosticMetricItem(webex, item);
435
448
  assert.deepEqual(item.eventPayload.origin.buildType, 'prod');
449
+ assert.deepEqual(item.eventPayload.origin.upgradeChannel, 'gold');
436
450
  });
437
451
  });
438
452
 
@@ -73,6 +73,20 @@ describe('internal-plugin-metrics', () => {
73
73
  sinon.restore();
74
74
  })
75
75
 
76
+ it('lazy metrics backend initialization when checking if backend ready', () => {
77
+ assert.isUndefined(webex.internal.newMetrics.behavioralMetrics);
78
+ webex.internal.newMetrics.isReadyToSubmitBehavioralEvents();
79
+ assert.isDefined(webex.internal.newMetrics.behavioralMetrics);
80
+
81
+ assert.isUndefined(webex.internal.newMetrics.operationalMetrics);
82
+ webex.internal.newMetrics.isReadyToSubmitOperationalEvents();
83
+ assert.isDefined(webex.internal.newMetrics.operationalMetrics);
84
+
85
+ assert.isUndefined(webex.internal.newMetrics.businessMetrics)
86
+ webex.internal.newMetrics.isReadyToSubmitBusinessEvents();
87
+ assert.isDefined(webex.internal.newMetrics.businessMetrics);
88
+ })
89
+
76
90
  it('submits Client Event successfully', () => {
77
91
  webex.internal.newMetrics.submitClientEvent({
78
92
  name: 'client.alert.displayed',
@@ -0,0 +1,115 @@
1
+ import sinon from 'sinon';
2
+ import {assert} from '@webex/test-helper-chai';
3
+ import {BrowserDetection} from '@webex/common';
4
+ import {OperationalMetrics, config, getOSNameInternal} from '@webex/internal-plugin-metrics';
5
+ import uuid from 'uuid';
6
+
7
+ //@ts-ignore
8
+ global.window = {location: {hostname: 'whatever'}, navigator: {language: 'language'}};
9
+ process.env.NODE_ENV = 'test';
10
+
11
+ const {getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
12
+
13
+ describe('internal-plugin-metrics', () => {
14
+ describe('OperationalMetrics', () => {
15
+ let webex;
16
+ let now;
17
+ let operationalMetrics: OperationalMetrics;
18
+
19
+ const tags = {key: 'val'};
20
+
21
+ beforeEach(() => {
22
+ now = new Date();
23
+
24
+ webex = {
25
+ canAuthorize: true,
26
+ version: 'webex-version',
27
+ internal: {
28
+ services: {
29
+ get: () => 'locus-url',
30
+ },
31
+ metrics: {
32
+ submitClientMetrics: sinon.stub(),
33
+ config: {...config.metrics},
34
+ },
35
+ newMetrics: {},
36
+ device: {
37
+ userId: 'userId',
38
+ url: 'https://wdm-intb.ciscospark.com/wdm/api/v1/devices/deviceId',
39
+ orgId: 'orgId',
40
+ },
41
+ },
42
+ meetings: {
43
+ config: {
44
+ metrics: {
45
+ clientType: 'TEAMS_CLIENT',
46
+ subClientType: 'WEB_APP',
47
+ clientName: 'Cantina',
48
+ },
49
+ },
50
+ geoHintInfo: {
51
+ clientAddress: '1.3.4.5',
52
+ countryCode: 'UK',
53
+ },
54
+ },
55
+ credentials: {
56
+ isUnverifiedGuest: false,
57
+ },
58
+ prepareFetchOptions: sinon.stub().callsFake((opts: any) => ({...opts, foo: 'bar'})),
59
+ request: sinon.stub().resolves({body: {}}),
60
+ logger: {
61
+ log: sinon.stub(),
62
+ error: sinon.stub(),
63
+ },
64
+ };
65
+
66
+ sinon.createSandbox();
67
+ sinon.useFakeTimers(now.getTime());
68
+ operationalMetrics = new OperationalMetrics({}, {parent: webex});
69
+ sinon.stub(uuid, 'v4').returns('my-fake-id');
70
+ });
71
+
72
+ afterEach(() => {
73
+ sinon.restore();
74
+ });
75
+
76
+ describe('#sendEvent', () => {
77
+ it('should send correctly shaped operational event (check name building and internal tagged event building)', () => {
78
+ // For some reasons `jest` isn't available when testing form build server - so can't use `jest.fn()` here...
79
+ const requestCalls = [];
80
+ const request = function(arg) { requestCalls.push(arg) }
81
+
82
+ operationalMetrics.clientMetricsBatcher.request = request;
83
+
84
+ assert.equal(requestCalls.length, 0)
85
+ operationalMetrics.submitOperationalEvent({ name: "foobar", payload: {bar:"gee"} })
86
+ assert.equal(requestCalls.length, 1)
87
+ assert.deepEqual(requestCalls[0], {
88
+ context: {
89
+ app: {version: 'webex-version'},
90
+ device: {id: 'deviceId'},
91
+ locale: 'language',
92
+ os: {
93
+ name: getOSNameInternal(),
94
+ version: getOSVersion(),
95
+ },
96
+ },
97
+ metricName: 'foobar',
98
+ tags: {
99
+ browser: getBrowserName(),
100
+ browserHeight: window.innerHeight,
101
+ browserVersion: getBrowserVersion(),
102
+ browserWidth: window.innerWidth,
103
+ domain: window.location.hostname,
104
+ inIframe: false,
105
+ locale: window.navigator.language,
106
+ os: getOSNameInternal(),
107
+ bar: "gee"
108
+ },
109
+ timestamp: requestCalls[0].timestamp, // This is to bypass time check, which is correctly tested in behavioral-metrics tests.
110
+ type: ['operational'],
111
+ });
112
+ })
113
+ })
114
+ });
115
+ });
@@ -82,6 +82,7 @@ describe('internal-plugin-metrics', () => {
82
82
  origin: {
83
83
  buildType: 'test',
84
84
  networkType: 'unknown',
85
+ upgradeChannel: 'test',
85
86
  },
86
87
  originTime: {
87
88
  sent: dateAfterBatcherWait.toISOString(),
@@ -211,7 +212,7 @@ describe('internal-plugin-metrics', () => {
211
212
  // item also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
212
213
  assert.deepEqual(calls.args[0].eventPayload, {
213
214
  event: 'my.event',
214
- origin: {buildType: 'test', networkType: 'unknown'},
215
+ origin: {buildType: 'test', networkType: 'unknown', upgradeChannel: 'test'},
215
216
  });
216
217
 
217
218
  assert.deepEqual(calls.args[0].type, ['diagnostic-event']);
@@ -225,6 +226,7 @@ describe('internal-plugin-metrics', () => {
225
226
  origin: {
226
227
  buildType: 'test',
227
228
  networkType: 'unknown',
229
+ upgradeChannel: 'test',
228
230
  },
229
231
  });
230
232
  assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].type, ['diagnostic-event']);