@webex/internal-plugin-metrics 3.0.0-beta.3 → 3.0.0-beta.300

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 (69) hide show
  1. package/README.md +1 -3
  2. package/dist/batcher.js +5 -23
  3. package/dist/batcher.js.map +1 -1
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +66 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +456 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js +798 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +337 -0
  11. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  12. package/dist/call-diagnostic/config.js +604 -0
  13. package/dist/call-diagnostic/config.js.map +1 -0
  14. package/dist/client-metrics-batcher.js +3 -8
  15. package/dist/client-metrics-batcher.js.map +1 -1
  16. package/dist/config.js +23 -6
  17. package/dist/config.js.map +1 -1
  18. package/dist/index.js +31 -10
  19. package/dist/index.js.map +1 -1
  20. package/dist/metrics.js +43 -80
  21. package/dist/metrics.js.map +1 -1
  22. package/dist/metrics.types.js +7 -0
  23. package/dist/metrics.types.js.map +1 -0
  24. package/dist/new-metrics.js +333 -0
  25. package/dist/new-metrics.js.map +1 -0
  26. package/dist/types/batcher.d.ts +2 -0
  27. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +194 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +405 -0
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +96 -0
  31. package/dist/types/call-diagnostic/config.d.ts +171 -0
  32. package/dist/types/client-metrics-batcher.d.ts +2 -0
  33. package/dist/types/config.d.ts +36 -0
  34. package/dist/types/index.d.ts +13 -0
  35. package/dist/types/metrics.d.ts +3 -0
  36. package/dist/types/metrics.types.d.ts +103 -0
  37. package/dist/types/new-metrics.d.ts +139 -0
  38. package/dist/types/utils.d.ts +6 -0
  39. package/dist/utils.js +27 -0
  40. package/dist/utils.js.map +1 -0
  41. package/package.json +13 -8
  42. package/src/batcher.js +34 -26
  43. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +83 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +414 -0
  45. package/src/call-diagnostic/call-diagnostic-metrics.ts +863 -0
  46. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
  47. package/src/call-diagnostic/config.ts +660 -0
  48. package/src/client-metrics-batcher.js +4 -4
  49. package/src/config.js +26 -5
  50. package/src/index.ts +43 -0
  51. package/src/metrics.js +44 -58
  52. package/src/metrics.types.ts +159 -0
  53. package/src/new-metrics.ts +317 -0
  54. package/src/utils.ts +17 -0
  55. package/test/unit/spec/batcher.js +28 -15
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +465 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +477 -0
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1943 -0
  59. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
  60. package/test/unit/spec/client-metrics-batcher.js +28 -15
  61. package/test/unit/spec/metrics.js +86 -116
  62. package/test/unit/spec/new-metrics.ts +269 -0
  63. package/test/unit/spec/utils.ts +22 -0
  64. package/tsconfig.json +6 -0
  65. package/dist/call-diagnostic-events-batcher.js +0 -70
  66. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  67. package/src/call-diagnostic-events-batcher.js +0 -62
  68. package/src/index.js +0 -17
  69. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -180
@@ -1,62 +0,0 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import Batcher from './batcher';
6
-
7
- const CallDiagnosticEventsBatcher = Batcher.extend({
8
- namespace: 'Metrics',
9
-
10
- /**
11
- * @param {string} webClientDomain
12
- * @returns {string}
13
- */
14
- getBuildType(webClientDomain) {
15
- if (
16
- webClientDomain?.includes('teams.webex.com') ||
17
- webClientDomain?.includes('localhost') ||
18
- webClientDomain?.includes('127.0.0.1') ||
19
- process.env.NODE_ENV !== 'production'
20
- ) {
21
- return 'test';
22
- }
23
-
24
- return process.env.NODE_ENV === 'production' ? 'prod' : 'test';
25
- },
26
-
27
- prepareItem(item) {
28
- // networkType should be a enum value: `wifi`, `ethernet`, `cellular`, or `unknown`.
29
- // Browsers cannot provide such information right now. However, it is a required field.
30
- const origin = {
31
- buildType: this.getBuildType(item.event?.eventData?.webClientDomain),
32
- networkType: 'unknown'
33
- };
34
-
35
- item.eventPayload.origin = Object.assign(origin, item.eventPayload.origin);
36
-
37
- return Promise.resolve(item);
38
- },
39
-
40
- prepareRequest(queue) {
41
- // Add sent timestamp
42
- queue.forEach((item) => {
43
- item.eventPayload.originTime = item.eventPayload.originTime || {};
44
- item.eventPayload.originTime.sent = new Date().toISOString();
45
- });
46
-
47
- return Promise.resolve(queue);
48
- },
49
-
50
- submitHttpRequest(payload) {
51
- return this.webex.request({
52
- method: 'POST',
53
- service: 'metrics',
54
- resource: 'clientmetrics',
55
- body: {
56
- metrics: payload
57
- }
58
- });
59
- }
60
- });
61
-
62
- export default CallDiagnosticEventsBatcher;
package/src/index.js DELETED
@@ -1,17 +0,0 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@webex/internal-plugin-device';
6
-
7
- import {registerInternalPlugin} from '@webex/webex-core';
8
-
9
- import Metrics from './metrics';
10
- import config from './config';
11
-
12
- registerInternalPlugin('metrics', Metrics, {
13
- config
14
- });
15
-
16
- export {default} from './metrics';
17
- export {config};
@@ -1,180 +0,0 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import FakeTimers from '@sinonjs/fake-timers';
7
- import Metrics, {config} from '@webex/internal-plugin-metrics';
8
- import MockWebex from '@webex/test-helper-mock-webex';
9
- import sinon from 'sinon';
10
- import {WebexHttpError} from '@webex/webex-core';
11
-
12
- function promiseTick(count) {
13
- let promise = Promise.resolve();
14
-
15
- while (count > 1) {
16
- promise = promise.then(() => promiseTick(1));
17
- count -= 1;
18
- }
19
-
20
- return promise;
21
- }
22
-
23
- describe('plugin-metrics', () => {
24
- describe('callDiagnosticEventsBatcher', () => {
25
- let webex;
26
-
27
- beforeEach(() => {
28
- webex = new MockWebex({
29
- children: {
30
- metrics: Metrics
31
- }
32
- });
33
-
34
- webex.config.metrics = config.metrics;
35
-
36
- webex.request = function (options) {
37
- return Promise.resolve({
38
- statusCode: 204,
39
- body: undefined,
40
- options
41
- });
42
- };
43
- sinon.spy(webex, 'request');
44
- });
45
-
46
- let clock;
47
-
48
- beforeEach(() => {
49
- clock = FakeTimers.install();
50
- });
51
-
52
- afterEach(() => {
53
- clock.uninstall();
54
- });
55
-
56
- describe('#request()', () => {
57
- describe('when the request completes successfully', () => {
58
- it('clears the queue', () => {
59
- clock.uninstall();
60
-
61
- return webex.internal.metrics.callDiagnosticEventsBatcher.request({
62
- type: 'diagnostic-event',
63
- eventPayload: {
64
- originTime: {
65
- triggered: 'mock triggered timestamp'
66
- }
67
- }
68
- })
69
- .then(() => {
70
- assert.calledOnce(webex.request);
71
- assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
72
- });
73
- });
74
- });
75
-
76
- describe('when the request fails due to network disconnect', () => {
77
- it('reenqueues the payload', () => {
78
- // sinon appears to have gap in its api where stub.onCall(n) doesn't
79
- // accept a function, so the following is more verbose than one might
80
- // desire
81
- webex.request = function () {
82
- // noop
83
- };
84
- let count = 0;
85
-
86
- sinon.stub(webex, 'request').callsFake((options) => {
87
- options.headers = {
88
- trackingid: count
89
- };
90
-
91
- count += 1;
92
- if (count < 9) {
93
- return Promise.reject(new WebexHttpError.NetworkOrCORSError({
94
- statusCode: 0,
95
- options
96
- }));
97
- }
98
-
99
- return Promise.resolve({
100
- statusCode: 204,
101
- body: undefined,
102
- options
103
- });
104
- });
105
-
106
- const promise = webex.internal.metrics.callDiagnosticEventsBatcher.request({
107
- type: 'diagnostic-event',
108
- eventPayload: {
109
- originTime: {
110
- triggered: 'mock triggered timestamp'
111
- }
112
- }
113
- });
114
-
115
- return promiseTick(50)
116
- .then(() => assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 1))
117
- .then(() => clock.tick(config.metrics.batcherWait))
118
- .then(() => assert.calledOnce(webex.request))
119
-
120
- .then(() => promiseTick(50))
121
- .then(() => clock.tick(1000))
122
- .then(() => promiseTick(50))
123
- .then(() => clock.tick(config.metrics.batcherWait))
124
- .then(() => assert.calledTwice(webex.request))
125
-
126
- .then(() => promiseTick(50))
127
- .then(() => clock.tick(2000))
128
- .then(() => promiseTick(50))
129
- .then(() => clock.tick(config.metrics.batcherWait))
130
- .then(() => assert.calledThrice(webex.request))
131
-
132
- .then(() => promiseTick(50))
133
- .then(() => clock.tick(4000))
134
- .then(() => promiseTick(50))
135
- .then(() => clock.tick(config.metrics.batcherWait))
136
- .then(() => assert.callCount(webex.request, 4))
137
-
138
- .then(() => promiseTick(50))
139
- .then(() => clock.tick(8000))
140
- .then(() => promiseTick(50))
141
- .then(() => clock.tick(config.metrics.batcherWait))
142
- .then(() => assert.callCount(webex.request, 5))
143
-
144
- .then(() => promiseTick(50))
145
- .then(() => clock.tick(16000))
146
- .then(() => promiseTick(50))
147
- .then(() => clock.tick(config.metrics.batcherWait))
148
- .then(() => assert.callCount(webex.request, 6))
149
-
150
- .then(() => promiseTick(50))
151
- .then(() => clock.tick(32000))
152
- .then(() => promiseTick(50))
153
- .then(() => clock.tick(config.metrics.batcherWait))
154
- .then(() => assert.callCount(webex.request, 7))
155
-
156
- .then(() => promiseTick(50))
157
- .then(() => clock.tick(32000))
158
- .then(() => promiseTick(50))
159
- .then(() => clock.tick(config.metrics.batcherWait))
160
- .then(() => assert.callCount(webex.request, 8))
161
-
162
- .then(() => promiseTick(50))
163
- .then(() => clock.tick(32000))
164
- .then(() => promiseTick(50))
165
- .then(() => clock.tick(config.metrics.batcherWait))
166
- .then(() => assert.callCount(webex.request, 9))
167
-
168
- .then(() => promiseTick(50))
169
- .then(() => assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0))
170
- .then(() => promise)
171
- .then(() => {
172
- assert.lengthOf(webex.request.args[1][0].body.metrics, 1, 'Reenqueuing the metric once did not increase the number of metrics to be submitted');
173
- assert.lengthOf(webex.request.args[2][0].body.metrics, 1, 'Reenqueuing the metric twice did not increase the number of metrics to be submitted');
174
- assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
175
- });
176
- });
177
- });
178
- });
179
- });
180
- });