@libp2p/interface-compliance-tests 6.0.0 → 6.0.1-21fe841f2
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.
- package/dist/src/mocks/metrics.d.ts.map +1 -1
- package/dist/src/mocks/metrics.js +171 -0
- package/dist/src/mocks/metrics.js.map +1 -1
- package/dist/src/pubsub/api.d.ts.map +1 -1
- package/dist/src/pubsub/api.js +4 -1
- package/dist/src/pubsub/api.js.map +1 -1
- package/package.json +11 -9
- package/src/mocks/metrics.ts +225 -1
- package/src/pubsub/api.ts +5 -1
- package/dist/typedoc-urls.json +0 -43
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/mocks/metrics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/mocks/metrics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2E,OAAO,EAAoL,MAAM,mBAAmB,CAAA;AA6X3S,wBAAgB,WAAW,IAAK,MAAM,OAAO,CAE5C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TDigest } from 'tdigest';
|
|
1
2
|
class DefaultMetric {
|
|
2
3
|
value = 0;
|
|
3
4
|
update(value) {
|
|
@@ -50,6 +51,124 @@ class DefaultGroupMetric {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
class DefaultHistogram {
|
|
55
|
+
bucketValues = new Map();
|
|
56
|
+
countValue = 0;
|
|
57
|
+
sumValue = 0;
|
|
58
|
+
constructor(opts) {
|
|
59
|
+
const buckets = [
|
|
60
|
+
...(opts.buckets ?? [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]),
|
|
61
|
+
Infinity
|
|
62
|
+
];
|
|
63
|
+
for (const bucket of buckets) {
|
|
64
|
+
this.bucketValues.set(bucket, 0);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
observe(value) {
|
|
68
|
+
this.countValue++;
|
|
69
|
+
this.sumValue += value;
|
|
70
|
+
for (const [bucket, count] of this.bucketValues.entries()) {
|
|
71
|
+
if (value <= bucket) {
|
|
72
|
+
this.bucketValues.set(bucket, count + 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
reset() {
|
|
77
|
+
this.countValue = 0;
|
|
78
|
+
this.sumValue = 0;
|
|
79
|
+
for (const bucket of this.bucketValues.keys()) {
|
|
80
|
+
this.bucketValues.set(bucket, 0);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
timer() {
|
|
84
|
+
const start = Date.now();
|
|
85
|
+
return () => {
|
|
86
|
+
this.observe(Date.now() - start);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class DefaultHistogramGroup {
|
|
91
|
+
histograms = {};
|
|
92
|
+
constructor(opts) {
|
|
93
|
+
this.histograms = {};
|
|
94
|
+
}
|
|
95
|
+
observe(values) {
|
|
96
|
+
for (const [key, value] of Object.entries(values)) {
|
|
97
|
+
if (this.histograms[key] === undefined) {
|
|
98
|
+
this.histograms[key] = new DefaultHistogram({});
|
|
99
|
+
}
|
|
100
|
+
this.histograms[key].observe(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
reset() {
|
|
104
|
+
for (const histogram of Object.values(this.histograms)) {
|
|
105
|
+
histogram.reset();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
timer(key) {
|
|
109
|
+
const start = Date.now();
|
|
110
|
+
return () => {
|
|
111
|
+
this.observe({ [key]: Date.now() - start });
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class DefaultSummary {
|
|
116
|
+
sumValue = 0;
|
|
117
|
+
countValue = 0;
|
|
118
|
+
percentiles;
|
|
119
|
+
tdigest = new TDigest(0.01);
|
|
120
|
+
compressCount;
|
|
121
|
+
constructor(opts) {
|
|
122
|
+
this.percentiles = opts.percentiles ?? [0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999];
|
|
123
|
+
this.compressCount = opts.compressCount ?? 1000;
|
|
124
|
+
}
|
|
125
|
+
observe(value) {
|
|
126
|
+
this.sumValue += value;
|
|
127
|
+
this.countValue++;
|
|
128
|
+
this.tdigest.push(value);
|
|
129
|
+
if (this.tdigest.size() > this.compressCount) {
|
|
130
|
+
this.tdigest.compress();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
reset() {
|
|
134
|
+
this.sumValue = 0;
|
|
135
|
+
this.countValue = 0;
|
|
136
|
+
this.tdigest.reset();
|
|
137
|
+
}
|
|
138
|
+
timer() {
|
|
139
|
+
const start = Date.now();
|
|
140
|
+
return () => {
|
|
141
|
+
this.observe(Date.now() - start);
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
class DefaultSummaryGroup {
|
|
146
|
+
summaries = {};
|
|
147
|
+
opts;
|
|
148
|
+
constructor(opts) {
|
|
149
|
+
this.summaries = {};
|
|
150
|
+
this.opts = opts;
|
|
151
|
+
}
|
|
152
|
+
observe(values) {
|
|
153
|
+
for (const [key, value] of Object.entries(values)) {
|
|
154
|
+
if (this.summaries[key] === undefined) {
|
|
155
|
+
this.summaries[key] = new DefaultSummary(this.opts);
|
|
156
|
+
}
|
|
157
|
+
this.summaries[key].observe(value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
reset() {
|
|
161
|
+
for (const summary of Object.values(this.summaries)) {
|
|
162
|
+
summary.reset();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
timer(key) {
|
|
166
|
+
const start = Date.now();
|
|
167
|
+
return () => {
|
|
168
|
+
this.observe({ [key]: Date.now() - start });
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
53
172
|
class MockMetrics {
|
|
54
173
|
metrics = new Map();
|
|
55
174
|
trackMultiaddrConnection(maConn) {
|
|
@@ -108,6 +227,58 @@ class MockMetrics {
|
|
|
108
227
|
this.metrics.set(name, metric);
|
|
109
228
|
return metric;
|
|
110
229
|
}
|
|
230
|
+
registerHistogram(name, opts = {}) {
|
|
231
|
+
if (name == null || name.trim() === '') {
|
|
232
|
+
throw new Error('Metric name is required');
|
|
233
|
+
}
|
|
234
|
+
if (opts?.calculate != null) {
|
|
235
|
+
// calculated metric
|
|
236
|
+
this.metrics.set(name, opts.calculate);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const metric = new DefaultHistogram(opts);
|
|
240
|
+
this.metrics.set(name, metric);
|
|
241
|
+
return metric;
|
|
242
|
+
}
|
|
243
|
+
registerHistogramGroup(name, opts = {}) {
|
|
244
|
+
if (name == null || name.trim() === '') {
|
|
245
|
+
throw new Error('Metric name is required');
|
|
246
|
+
}
|
|
247
|
+
if (opts?.calculate != null) {
|
|
248
|
+
// calculated metric
|
|
249
|
+
this.metrics.set(name, opts.calculate);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const metric = new DefaultHistogramGroup(opts);
|
|
253
|
+
this.metrics.set(name, metric);
|
|
254
|
+
return metric;
|
|
255
|
+
}
|
|
256
|
+
registerSummary(name, opts = {}) {
|
|
257
|
+
if (name == null || name.trim() === '') {
|
|
258
|
+
throw new Error('Metric name is required');
|
|
259
|
+
}
|
|
260
|
+
if (opts?.calculate != null) {
|
|
261
|
+
// calculated metric
|
|
262
|
+
this.metrics.set(name, opts.calculate);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const metric = new DefaultSummary(opts);
|
|
266
|
+
this.metrics.set(name, metric);
|
|
267
|
+
return metric;
|
|
268
|
+
}
|
|
269
|
+
registerSummaryGroup(name, opts = {}) {
|
|
270
|
+
if (name == null || name.trim() === '') {
|
|
271
|
+
throw new Error('Metric name is required');
|
|
272
|
+
}
|
|
273
|
+
if (opts?.calculate != null) {
|
|
274
|
+
// calculated metric
|
|
275
|
+
this.metrics.set(name, opts.calculate);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const metric = new DefaultSummaryGroup(opts);
|
|
279
|
+
this.metrics.set(name, metric);
|
|
280
|
+
return metric;
|
|
281
|
+
}
|
|
111
282
|
}
|
|
112
283
|
export function mockMetrics() {
|
|
113
284
|
return () => new MockMetrics();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/mocks/metrics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/mocks/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGjC,MAAM,aAAa;IACV,KAAK,GAAW,CAAC,CAAA;IAExB,MAAM,CAAE,KAAa;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,SAAS,CAAE,QAAgB,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAA;IACrB,CAAC;IAED,SAAS,CAAE,QAAgB,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAA;IACrB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;IAChB,CAAC;IAED,KAAK;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAExB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAA;QACjC,CAAC,CAAA;IACH,CAAC;CACF;AAED,MAAM,kBAAkB;IACf,MAAM,GAA2B,EAAE,CAAA;IAE1C,MAAM,CAAE,MAA8B;QACpC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC9C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,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mB,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAE9B,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,GAAG,EAAE,CAAC,IAAI,WAAW,EAAE,CAAA;AAChC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,YAAY,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;iCAKvB,UAAU,MAAM,EAAE,UAAU,CAAC,KAAG,IAAI;AAA5D,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,YAAY,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;iCAKvB,UAAU,MAAM,EAAE,UAAU,CAAC,KAAG,IAAI;AAA5D,wBAmGC"}
|
package/dist/src/pubsub/api.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isStartable, start, stop } from '@libp2p/interface';
|
|
1
|
+
import { isPubSub, isStartable, start, stop } from '@libp2p/interface';
|
|
2
2
|
import { expect } from 'aegir/chai';
|
|
3
3
|
import delay from 'delay';
|
|
4
4
|
import pDefer from 'p-defer';
|
|
@@ -30,6 +30,9 @@ export default (common) => {
|
|
|
30
30
|
await common.teardown();
|
|
31
31
|
mockNetwork.reset();
|
|
32
32
|
});
|
|
33
|
+
it('is a PubSub implementation', () => {
|
|
34
|
+
expect(isPubSub(pubsub)).to.be.true();
|
|
35
|
+
});
|
|
33
36
|
it('can start correctly', async () => {
|
|
34
37
|
if (!isStartable(pubsub)) {
|
|
35
38
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAK7C,MAAM,KAAK,GAAG,KAAK,CAAA;AACnB,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAA;AAExC,eAAe,CAAC,MAAqC,EAAQ,EAAE;IAC7D,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,IAAI,MAAc,CAAA;QAClB,IAAI,UAA4B,CAAA;QAEhC,uBAAuB;QACvB,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,WAAW,CAAC,KAAK,EAAE,CAAA;YACnB,UAAU,GAAG,MAAM,gBAAgB,EAAE,CAAA;YAErC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG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UAAU,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;YACnD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAA;YAEtB,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;YAEzC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACvB,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE;gBACzC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;gBAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;gBAC7D,KAAK,CAAC,OAAO,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;YACF,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACjC,MAAM,KAAK,CAAC,OAAO,CAAA;YAEnB,MAAM,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface-compliance-tests",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1-21fe841f2",
|
|
4
4
|
"description": "Compliance tests for JS libp2p interfaces",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-compliance-tests#readme",
|
|
@@ -108,14 +108,14 @@
|
|
|
108
108
|
"test:electron-main": "aegir test -t electron-main"
|
|
109
109
|
},
|
|
110
110
|
"dependencies": {
|
|
111
|
-
"@libp2p/crypto": "
|
|
112
|
-
"@libp2p/interface": "
|
|
113
|
-
"@libp2p/interface-internal": "
|
|
114
|
-
"@libp2p/logger": "
|
|
115
|
-
"@libp2p/multistream-select": "
|
|
116
|
-
"@libp2p/peer-collections": "
|
|
117
|
-
"@libp2p/peer-id": "
|
|
118
|
-
"@libp2p/utils": "
|
|
111
|
+
"@libp2p/crypto": "5.0.1-21fe841f2",
|
|
112
|
+
"@libp2p/interface": "2.0.1-21fe841f2",
|
|
113
|
+
"@libp2p/interface-internal": "2.0.1-21fe841f2",
|
|
114
|
+
"@libp2p/logger": "5.0.1-21fe841f2",
|
|
115
|
+
"@libp2p/multistream-select": "6.0.1-21fe841f2",
|
|
116
|
+
"@libp2p/peer-collections": "6.0.1-21fe841f2",
|
|
117
|
+
"@libp2p/peer-id": "5.0.1-21fe841f2",
|
|
118
|
+
"@libp2p/utils": "6.0.1-21fe841f2",
|
|
119
119
|
"@multiformats/multiaddr": "^12.2.3",
|
|
120
120
|
"abortable-iterator": "^5.0.1",
|
|
121
121
|
"aegir": "^44.0.1",
|
|
@@ -138,10 +138,12 @@
|
|
|
138
138
|
"p-wait-for": "^5.0.2",
|
|
139
139
|
"protons-runtime": "^5.4.0",
|
|
140
140
|
"sinon": "^18.0.0",
|
|
141
|
+
"tdigest": "^0.1.2",
|
|
141
142
|
"uint8arraylist": "^2.4.8",
|
|
142
143
|
"uint8arrays": "^5.1.0"
|
|
143
144
|
},
|
|
144
145
|
"devDependencies": {
|
|
146
|
+
"@types/tdigest": "^0.1.4",
|
|
145
147
|
"protons": "^7.5.0"
|
|
146
148
|
}
|
|
147
149
|
}
|
package/src/mocks/metrics.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TDigest } from 'tdigest'
|
|
2
|
+
import type { MultiaddrConnection, Stream, Connection, Metric, MetricGroup, StopTimer, Metrics, CalculatedMetricOptions, MetricOptions, Histogram, HistogramOptions, HistogramGroup, Summary, SummaryOptions, SummaryGroup, CalculatedHistogramOptions, CalculatedSummaryOptions } from '@libp2p/interface'
|
|
2
3
|
|
|
3
4
|
class DefaultMetric implements Metric {
|
|
4
5
|
public value: number = 0
|
|
@@ -68,6 +69,153 @@ class DefaultGroupMetric implements MetricGroup {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
class DefaultHistogram implements Histogram {
|
|
73
|
+
public bucketValues = new Map<number, number>()
|
|
74
|
+
public countValue: number = 0
|
|
75
|
+
public sumValue: number = 0
|
|
76
|
+
|
|
77
|
+
constructor (opts: HistogramOptions) {
|
|
78
|
+
const buckets = [
|
|
79
|
+
...(opts.buckets ?? [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]),
|
|
80
|
+
Infinity
|
|
81
|
+
]
|
|
82
|
+
for (const bucket of buckets) {
|
|
83
|
+
this.bucketValues.set(bucket, 0)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
observe (value: number): void {
|
|
88
|
+
this.countValue++
|
|
89
|
+
this.sumValue += value
|
|
90
|
+
|
|
91
|
+
for (const [bucket, count] of this.bucketValues.entries()) {
|
|
92
|
+
if (value <= bucket) {
|
|
93
|
+
this.bucketValues.set(bucket, count + 1)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
reset (): void {
|
|
99
|
+
this.countValue = 0
|
|
100
|
+
this.sumValue = 0
|
|
101
|
+
for (const bucket of this.bucketValues.keys()) {
|
|
102
|
+
this.bucketValues.set(bucket, 0)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
timer (): StopTimer {
|
|
107
|
+
const start = Date.now()
|
|
108
|
+
|
|
109
|
+
return () => {
|
|
110
|
+
this.observe(Date.now() - start)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class DefaultHistogramGroup implements HistogramGroup {
|
|
116
|
+
public histograms: Record<string, DefaultHistogram> = {}
|
|
117
|
+
|
|
118
|
+
constructor (opts: HistogramOptions) {
|
|
119
|
+
this.histograms = {}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
observe (values: Partial<Record<string, number>>): void {
|
|
123
|
+
for (const [key, value] of Object.entries(values) as Array<[string, number]>) {
|
|
124
|
+
if (this.histograms[key] === undefined) {
|
|
125
|
+
this.histograms[key] = new DefaultHistogram({})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.histograms[key].observe(value)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
reset (): void {
|
|
133
|
+
for (const histogram of Object.values(this.histograms)) {
|
|
134
|
+
histogram.reset()
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
timer (key: string): StopTimer {
|
|
139
|
+
const start = Date.now()
|
|
140
|
+
|
|
141
|
+
return () => {
|
|
142
|
+
this.observe({ [key]: Date.now() - start })
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
class DefaultSummary implements Summary {
|
|
148
|
+
public sumValue: number = 0
|
|
149
|
+
public countValue: number = 0
|
|
150
|
+
public percentiles: number[]
|
|
151
|
+
public tdigest = new TDigest(0.01)
|
|
152
|
+
private readonly compressCount: number
|
|
153
|
+
|
|
154
|
+
constructor (opts: SummaryOptions) {
|
|
155
|
+
this.percentiles = opts.percentiles ?? [0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999]
|
|
156
|
+
this.compressCount = opts.compressCount ?? 1000
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
observe (value: number): void {
|
|
160
|
+
this.sumValue += value
|
|
161
|
+
this.countValue++
|
|
162
|
+
|
|
163
|
+
this.tdigest.push(value)
|
|
164
|
+
if (this.tdigest.size() > this.compressCount) {
|
|
165
|
+
this.tdigest.compress()
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
reset (): void {
|
|
170
|
+
this.sumValue = 0
|
|
171
|
+
this.countValue = 0
|
|
172
|
+
|
|
173
|
+
this.tdigest.reset()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
timer (): StopTimer {
|
|
177
|
+
const start = Date.now()
|
|
178
|
+
|
|
179
|
+
return () => {
|
|
180
|
+
this.observe(Date.now() - start)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class DefaultSummaryGroup implements SummaryGroup {
|
|
186
|
+
public summaries: Record<string, DefaultSummary> = {}
|
|
187
|
+
private readonly opts: SummaryOptions
|
|
188
|
+
|
|
189
|
+
constructor (opts: SummaryOptions) {
|
|
190
|
+
this.summaries = {}
|
|
191
|
+
this.opts = opts
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
observe (values: Record<string, number>): void {
|
|
195
|
+
for (const [key, value] of Object.entries(values)) {
|
|
196
|
+
if (this.summaries[key] === undefined) {
|
|
197
|
+
this.summaries[key] = new DefaultSummary(this.opts)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.summaries[key].observe(value)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
reset (): void {
|
|
205
|
+
for (const summary of Object.values(this.summaries)) {
|
|
206
|
+
summary.reset()
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
timer (key: string): StopTimer {
|
|
211
|
+
const start = Date.now()
|
|
212
|
+
|
|
213
|
+
return () => {
|
|
214
|
+
this.observe({ [key]: Date.now() - start })
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
71
219
|
class MockMetrics implements Metrics {
|
|
72
220
|
public metrics = new Map<string, any>()
|
|
73
221
|
|
|
@@ -154,6 +302,82 @@ class MockMetrics implements Metrics {
|
|
|
154
302
|
|
|
155
303
|
return metric
|
|
156
304
|
}
|
|
305
|
+
|
|
306
|
+
registerHistogram (name: string, opts: CalculatedHistogramOptions): void
|
|
307
|
+
registerHistogram (name: string, opts?: HistogramOptions): Histogram
|
|
308
|
+
registerHistogram (name: string, opts: any = {}): any {
|
|
309
|
+
if (name == null || name.trim() === '') {
|
|
310
|
+
throw new Error('Metric name is required')
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (opts?.calculate != null) {
|
|
314
|
+
// calculated metric
|
|
315
|
+
this.metrics.set(name, opts.calculate)
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const metric = new DefaultHistogram(opts)
|
|
320
|
+
this.metrics.set(name, metric)
|
|
321
|
+
|
|
322
|
+
return metric
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
registerHistogramGroup (name: string, opts: CalculatedHistogramOptions<Record<string, number>>): void
|
|
326
|
+
registerHistogramGroup (name: string, opts?: HistogramOptions): HistogramGroup
|
|
327
|
+
registerHistogramGroup (name: string, opts: any = {}): any {
|
|
328
|
+
if (name == null || name.trim() === '') {
|
|
329
|
+
throw new Error('Metric name is required')
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (opts?.calculate != null) {
|
|
333
|
+
// calculated metric
|
|
334
|
+
this.metrics.set(name, opts.calculate)
|
|
335
|
+
return
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const metric = new DefaultHistogramGroup(opts)
|
|
339
|
+
this.metrics.set(name, metric)
|
|
340
|
+
|
|
341
|
+
return metric
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
registerSummary (name: string, opts: CalculatedSummaryOptions): void
|
|
345
|
+
registerSummary (name: string, opts?: SummaryOptions): Summary
|
|
346
|
+
registerSummary (name: string, opts: any = {}): any {
|
|
347
|
+
if (name == null || name.trim() === '') {
|
|
348
|
+
throw new Error('Metric name is required')
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (opts?.calculate != null) {
|
|
352
|
+
// calculated metric
|
|
353
|
+
this.metrics.set(name, opts.calculate)
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const metric = new DefaultSummary(opts)
|
|
358
|
+
this.metrics.set(name, metric)
|
|
359
|
+
|
|
360
|
+
return metric
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
registerSummaryGroup (name: string, opts: CalculatedSummaryOptions<Record<string, number>>): void
|
|
364
|
+
registerSummaryGroup (name: string, opts?: SummaryOptions): SummaryGroup
|
|
365
|
+
registerSummaryGroup (name: string, opts: any = {}): any {
|
|
366
|
+
if (name == null || name.trim() === '') {
|
|
367
|
+
throw new Error('Metric name is required')
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (opts?.calculate != null) {
|
|
371
|
+
// calculated metric
|
|
372
|
+
this.metrics.set(name, opts.calculate)
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const metric = new DefaultSummaryGroup(opts)
|
|
377
|
+
this.metrics.set(name, metric)
|
|
378
|
+
|
|
379
|
+
return metric
|
|
380
|
+
}
|
|
157
381
|
}
|
|
158
382
|
|
|
159
383
|
export function mockMetrics (): () => Metrics {
|
package/src/pubsub/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isStartable, start, stop } from '@libp2p/interface'
|
|
1
|
+
import { isPubSub, isStartable, start, stop } from '@libp2p/interface'
|
|
2
2
|
import { expect } from 'aegir/chai'
|
|
3
3
|
import delay from 'delay'
|
|
4
4
|
import pDefer from 'p-defer'
|
|
@@ -39,6 +39,10 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {
|
|
|
39
39
|
mockNetwork.reset()
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
+
it('is a PubSub implementation', () => {
|
|
43
|
+
expect(isPubSub(pubsub)).to.be.true()
|
|
44
|
+
})
|
|
45
|
+
|
|
42
46
|
it('can start correctly', async () => {
|
|
43
47
|
if (!isStartable(pubsub)) {
|
|
44
48
|
return
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.connection.default.html",
|
|
3
|
-
"./connection:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.connection.default.html",
|
|
4
|
-
"ConnectionEncrypterSetupArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.connection_encryption.ConnectionEncrypterSetupArgs.html",
|
|
5
|
-
"./connection-encryption:ConnectionEncrypterSetupArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.connection_encryption.ConnectionEncrypterSetupArgs.html",
|
|
6
|
-
"./connection-encryption:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.connection_encryption.default.html",
|
|
7
|
-
"TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.index.TestSetup.html",
|
|
8
|
-
".:TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.index.TestSetup.html",
|
|
9
|
-
"isValidTick": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.is_valid_tick.isValidTick.html",
|
|
10
|
-
"./is-valid-tick:isValidTick": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.is_valid_tick.isValidTick.html",
|
|
11
|
-
"matchMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.matchers.matchMultiaddr.html",
|
|
12
|
-
"./matchers:matchMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.matchers.matchMultiaddr.html",
|
|
13
|
-
"matchPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.matchers.matchPeerId.html",
|
|
14
|
-
"./matchers:matchPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.matchers.matchPeerId.html",
|
|
15
|
-
"MockNetworkComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.mocks.MockNetworkComponents.html",
|
|
16
|
-
"MockUpgraderInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.mocks.MockUpgraderInit.html",
|
|
17
|
-
"mockNetwork": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface_compliance_tests.mocks.mockNetwork.html",
|
|
18
|
-
"connectionPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.connectionPair.html",
|
|
19
|
-
"mockConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnection.html",
|
|
20
|
-
"mockConnectionGater": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnectionGater.html",
|
|
21
|
-
"mockConnectionManager": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnectionManager.html",
|
|
22
|
-
"mockDuplex": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockDuplex.html",
|
|
23
|
-
"mockMetrics": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMetrics.html",
|
|
24
|
-
"mockMultiaddrConnPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMultiaddrConnPair.html",
|
|
25
|
-
"mockMultiaddrConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMultiaddrConnection.html",
|
|
26
|
-
"mockMuxer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMuxer.html",
|
|
27
|
-
"mockRegistrar": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockRegistrar.html",
|
|
28
|
-
"mockStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockStream.html",
|
|
29
|
-
"mockUpgrader": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockUpgrader.html",
|
|
30
|
-
"streamPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.streamPair.html",
|
|
31
|
-
"./peer-discovery:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.peer_discovery.default.html",
|
|
32
|
-
"PubSubArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubArgs.html",
|
|
33
|
-
"./pubsub:PubSubArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubArgs.html",
|
|
34
|
-
"PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubComponents.html",
|
|
35
|
-
"./pubsub:PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubComponents.html",
|
|
36
|
-
"./pubsub:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.pubsub.default.html",
|
|
37
|
-
"./stream-muxer:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.stream_muxer.default.html",
|
|
38
|
-
"Connector": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.Connector.html",
|
|
39
|
-
"./transport:Connector": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.Connector.html",
|
|
40
|
-
"TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.TransportTestFixtures.html",
|
|
41
|
-
"./transport:TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.TransportTestFixtures.html",
|
|
42
|
-
"./transport:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.transport.default.html"
|
|
43
|
-
}
|