@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710
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/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
- package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
- package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
- package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
- package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
- package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
- package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +22 -9
- package/skills/fedify/SKILL.md +10 -0
- package/dist/accept-CPVqki78.mjs +0 -145
- package/dist/activity-listener-CELFAodc.mjs +0 -44
- package/dist/assert-D1Eafmd_.mjs +0 -23
- package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
- package/dist/assert_exists-cffSpJ7X.mjs +0 -28
- package/dist/assert_false-CPdRnc3E.mjs +0 -23
- package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
- package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
- package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
- package/dist/assert_rejects-CTptdYck.mjs +0 -39
- package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
- package/dist/assert_throws-BYITOvPO.mjs +0 -74
- package/dist/assertion_error-B-cx0fFA.mjs +0 -31
- package/dist/audience-CHQ-FlLD.mjs +0 -95
- package/dist/builder-D1FP_5nQ.mjs +0 -911
- package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
- package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
- package/dist/client-5SIFzW3q.mjs +0 -441
- package/dist/codec-C6rTrpIp.mjs +0 -147
- package/dist/collection-CnnP1UAv.mjs +0 -44
- package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
- package/dist/compat/outgoing-jsonld.test.mjs +0 -257
- package/dist/compat/public-audience.test.d.mts +0 -2
- package/dist/compat/public-audience.test.mjs +0 -187
- package/dist/compat/secured-document.test.d.mts +0 -2
- package/dist/compat/secured-document.test.mjs +0 -58
- package/dist/compat/transformers.test.d.mts +0 -2
- package/dist/compat/transformers.test.mjs +0 -62
- package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
- package/dist/context-LgGFFSz7.mjs +0 -146
- package/dist/deno-C50ikGBU.mjs +0 -8
- package/dist/dist-_geWsuaI.mjs +0 -189
- package/dist/docloader-BY-SEID0.mjs +0 -136
- package/dist/esm-BHXXx4Wx.mjs +0 -1233
- package/dist/exporter-DVG68ozH.mjs +0 -263
- package/dist/federation/audience.test.d.mts +0 -2
- package/dist/federation/audience.test.mjs +0 -130
- package/dist/federation/builder.test.d.mts +0 -2
- package/dist/federation/builder.test.mjs +0 -396
- package/dist/federation/circuit-breaker.test.d.mts +0 -2
- package/dist/federation/circuit-breaker.test.mjs +0 -1277
- package/dist/federation/collection.test.d.mts +0 -2
- package/dist/federation/collection.test.mjs +0 -21
- package/dist/federation/compound-fanout.test.d.mts +0 -2
- package/dist/federation/compound-fanout.test.mjs +0 -231
- package/dist/federation/handler-compound-proof.test.d.mts +0 -2
- package/dist/federation/handler-compound-proof.test.mjs +0 -384
- package/dist/federation/handler.test.d.mts +0 -2
- package/dist/federation/handler.test.mjs +0 -5445
- package/dist/federation/hashlink-media.test.d.mts +0 -2
- package/dist/federation/hashlink-media.test.mjs +0 -422
- package/dist/federation/idempotency.test.d.mts +0 -2
- package/dist/federation/idempotency.test.mjs +0 -207
- package/dist/federation/inbox-actorless.test.d.mts +0 -2
- package/dist/federation/inbox-actorless.test.mjs +0 -522
- package/dist/federation/inbox-authentication.test.d.mts +0 -2
- package/dist/federation/inbox-authentication.test.mjs +0 -220
- package/dist/federation/inbox-report.test.d.mts +0 -2
- package/dist/federation/inbox-report.test.mjs +0 -719
- package/dist/federation/inbox-view.test.d.mts +0 -2
- package/dist/federation/inbox-view.test.mjs +0 -369
- package/dist/federation/inbox.test.d.mts +0 -2
- package/dist/federation/inbox.test.mjs +0 -139
- package/dist/federation/keycache.test.d.mts +0 -2
- package/dist/federation/keycache.test.mjs +0 -337
- package/dist/federation/kv.test.d.mts +0 -2
- package/dist/federation/kv.test.mjs +0 -88
- package/dist/federation/metrics.test.d.mts +0 -2
- package/dist/federation/metrics.test.mjs +0 -634
- package/dist/federation/middleware.test.d.mts +0 -2
- package/dist/federation/middleware.test.mjs +0 -9314
- package/dist/federation/mq.test.d.mts +0 -2
- package/dist/federation/mq.test.mjs +0 -591
- package/dist/federation/negotiation.test.d.mts +0 -2
- package/dist/federation/negotiation.test.mjs +0 -18
- package/dist/federation/outbound-body.test.d.mts +0 -2
- package/dist/federation/outbound-body.test.mjs +0 -149
- package/dist/federation/outbound-capture.test.d.mts +0 -2
- package/dist/federation/outbound-capture.test.mjs +0 -394
- package/dist/federation/outbound-dispatch.test.d.mts +0 -2
- package/dist/federation/outbound-dispatch.test.mjs +0 -368
- package/dist/federation/outbound-document.test.d.mts +0 -2
- package/dist/federation/outbound-document.test.mjs +0 -171
- package/dist/federation/outbound-provenance.test.d.mts +0 -2
- package/dist/federation/outbound-provenance.test.mjs +0 -543
- package/dist/federation/outbound-report.test.d.mts +0 -2
- package/dist/federation/outbound-report.test.mjs +0 -5475
- package/dist/federation/outbound-workers.test.d.mts +0 -2
- package/dist/federation/outbound-workers.test.mjs +0 -64
- package/dist/federation/outbound-workflow.test.d.mts +0 -2
- package/dist/federation/outbound-workflow.test.mjs +0 -154
- package/dist/federation/outgoing-proof.test.d.mts +0 -2
- package/dist/federation/outgoing-proof.test.mjs +0 -933
- package/dist/federation/portable-actor.test.d.mts +0 -2
- package/dist/federation/portable-actor.test.mjs +0 -496
- package/dist/federation/portable-chain.test.d.mts +0 -2
- package/dist/federation/portable-chain.test.mjs +0 -370
- package/dist/federation/portable-collection.test.d.mts +0 -2
- package/dist/federation/portable-collection.test.mjs +0 -832
- package/dist/federation/portable-delivery.test.d.mts +0 -2
- package/dist/federation/portable-delivery.test.mjs +0 -845
- package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
- package/dist/federation/portable-gateway-keys.test.mjs +0 -692
- package/dist/federation/portable-inbox.test.d.mts +0 -2
- package/dist/federation/portable-inbox.test.mjs +0 -1960
- package/dist/federation/portable-parse-uri.test.d.mts +0 -2
- package/dist/federation/portable-parse-uri.test.mjs +0 -348
- package/dist/federation/portable-route-activity.test.d.mts +0 -2
- package/dist/federation/portable-route-activity.test.mjs +0 -259
- package/dist/federation/portable.test.d.mts +0 -2
- package/dist/federation/portable.test.mjs +0 -1072
- package/dist/federation/retry.test.d.mts +0 -2
- package/dist/federation/retry.test.mjs +0 -42
- package/dist/federation/router.test.d.mts +0 -2
- package/dist/federation/router.test.mjs +0 -123
- package/dist/federation/send.test.d.mts +0 -2
- package/dist/federation/send.test.mjs +0 -1421
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -302
- package/dist/federation/tasks/enqueue.test.d.mts +0 -2
- package/dist/federation/tasks/enqueue.test.mjs +0 -1095
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -1229
- package/dist/federation/temporal.test.d.mts +0 -2
- package/dist/federation/temporal.test.mjs +0 -71
- package/dist/federation/webfinger.test.d.mts +0 -2
- package/dist/federation/webfinger.test.mjs +0 -944
- package/dist/http-BXbQQZDM.mjs +0 -1449
- package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
- package/dist/inbox-cS97XzOD.mjs +0 -399
- package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
- package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
- package/dist/keycache-N2opu4-3.mjs +0 -221
- package/dist/keys-DIJNHW-Y.mjs +0 -120
- package/dist/kv-DBRWVx3Q.mjs +0 -104
- package/dist/kv-DCHkaJ9-.mjs +0 -92
- package/dist/kv-cache-fgbLHGVL.mjs +0 -121
- package/dist/ld-BpkhkDGj.mjs +0 -1752
- package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
- package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
- package/dist/metrics-Uqf8GomB.mjs +0 -818
- package/dist/middleware-DcXzz-YK.mjs +0 -9971
- package/dist/middleware-DgwZkvJR.mjs +0 -5
- package/dist/mq-eF96QxUT.mjs +0 -288
- package/dist/negotiation-BAKO9nih.mjs +0 -96
- package/dist/nodeinfo/client.test.d.mts +0 -2
- package/dist/nodeinfo/client.test.mjs +0 -1364
- package/dist/nodeinfo/handler.test.d.mts +0 -2
- package/dist/nodeinfo/handler.test.mjs +0 -94
- package/dist/nodeinfo/types.test.d.mts +0 -2
- package/dist/nodeinfo/types.test.mjs +0 -192
- package/dist/otel/exporter.test.d.mts +0 -2
- package/dist/otel/exporter.test.mjs +0 -887
- package/dist/outbound-body-CckPA5gc.mjs +0 -83
- package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
- package/dist/outbound-document-BMgwLXTY.mjs +0 -179
- package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
- package/dist/owner-BVenIFg1.mjs +0 -267
- package/dist/portable-collection-DIk9gpjL.mjs +0 -418
- package/dist/portable-key-C7pVaHNR.mjs +0 -549
- package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
- package/dist/proof-BlfZ95--.mjs +0 -1420
- package/dist/public-audience--klBIOk1.mjs +0 -197
- package/dist/retry-zX5xw5e0.mjs +0 -34
- package/dist/router-u5O5KCQr.mjs +0 -156
- package/dist/secured-document-CxzZZ9nL.mjs +0 -35
- package/dist/send-DEGHPGFk.mjs +0 -710
- package/dist/sig/accept.test.d.mts +0 -2
- package/dist/sig/accept.test.mjs +0 -416
- package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
- package/dist/sig/compound-proof-discovery.test.mjs +0 -331
- package/dist/sig/compound-proof-producer.test.d.mts +0 -2
- package/dist/sig/compound-proof-producer.test.mjs +0 -107
- package/dist/sig/compound-proof-verification.test.d.mts +0 -2
- package/dist/sig/compound-proof-verification.test.mjs +0 -1017
- package/dist/sig/compound-proof.test.d.mts +0 -2
- package/dist/sig/compound-proof.test.mjs +0 -411
- package/dist/sig/http.test.d.mts +0 -2
- package/dist/sig/http.test.mjs +0 -3328
- package/dist/sig/key-owner-evidence.test.d.mts +0 -2
- package/dist/sig/key-owner-evidence.test.mjs +0 -100
- package/dist/sig/key.test.d.mts +0 -2
- package/dist/sig/key.test.mjs +0 -1250
- package/dist/sig/ld.test.d.mts +0 -2
- package/dist/sig/ld.test.mjs +0 -1044
- package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
- package/dist/sig/mitra-receive-interop.test.mjs +0 -260
- package/dist/sig/mitra-send-interop.test.d.mts +0 -2
- package/dist/sig/mitra-send-interop.test.mjs +0 -461
- package/dist/sig/owner.test.d.mts +0 -2
- package/dist/sig/owner.test.mjs +0 -202
- package/dist/sig/portable-collection.test.d.mts +0 -2
- package/dist/sig/portable-collection.test.mjs +0 -697
- package/dist/sig/portable-interop.test.d.mts +0 -2
- package/dist/sig/portable-interop.test.mjs +0 -156
- package/dist/sig/portable-key-id.test.d.mts +0 -2
- package/dist/sig/portable-key-id.test.mjs +0 -67
- package/dist/sig/portable-key.test.d.mts +0 -2
- package/dist/sig/portable-key.test.mjs +0 -1438
- package/dist/sig/proof.test.d.mts +0 -2
- package/dist/sig/proof.test.mjs +0 -2638
- package/dist/sig/tootik-request-interop.test.d.mts +0 -2
- package/dist/sig/tootik-request-interop.test.mjs +0 -190
- package/dist/sig/tootik-send-interop.test.d.mts +0 -2
- package/dist/sig/tootik-send-interop.test.mjs +0 -331
- package/dist/sig/verification.test.d.mts +0 -2
- package/dist/sig/verification.test.mjs +0 -310
- package/dist/std__assert-DvMDRPes.mjs +0 -8
- package/dist/tasks-BCUmQbbz.mjs +0 -77
- package/dist/temporal-B4oQ8HpW.mjs +0 -95
- package/dist/testing/context.test.d.mts +0 -2
- package/dist/testing/context.test.mjs +0 -19
- package/dist/testing/kv.test.d.mts +0 -2
- package/dist/testing/kv.test.mjs +0 -101
- package/dist/testing/mod.d.mts +0 -6099
- package/dist/testing/mod.mjs +0 -9
- package/dist/testing-vrnD5Uaa.mjs +0 -8
- package/dist/types-DE_LV1JB.mjs +0 -46
- package/dist/utils/docloader.test.d.mts +0 -2
- package/dist/utils/docloader.test.mjs +0 -1076
- package/dist/utils/kv-cache.test.d.mts +0 -2
- package/dist/utils/kv-cache.test.mjs +0 -261
- package/dist/verification-C3954hQh.mjs +0 -5
- package/dist/verification-Dpfcw8ml.mjs +0 -105
- package/dist/vocab/cjs.test.d.mts +0 -2
- package/dist/vocab/cjs.test.mjs +0 -27
|
@@ -1,634 +0,0 @@
|
|
|
1
|
-
import "temporal-polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
5
|
-
import "../std__assert-DvMDRPes.mjs";
|
|
6
|
-
import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
|
|
7
|
-
import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-Uqf8GomB.mjs";
|
|
8
|
-
import { FetchError } from "@fedify/vocab-runtime";
|
|
9
|
-
import { createTestMeterProvider, test } from "@fedify/fixture";
|
|
10
|
-
import { DataPointType, MeterProvider, MetricReader } from "@opentelemetry/sdk-metrics";
|
|
11
|
-
//#region src/federation/metrics.test.ts
|
|
12
|
-
var TestMetricReader = class extends MetricReader {
|
|
13
|
-
onShutdown() {
|
|
14
|
-
return Promise.resolve();
|
|
15
|
-
}
|
|
16
|
-
onForceFlush() {
|
|
17
|
-
return Promise.resolve();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const noopQueue = {
|
|
21
|
-
enqueue() {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
},
|
|
24
|
-
listen() {
|
|
25
|
-
return Promise.resolve();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
test("getRemoteHost() includes non-default ports", () => {
|
|
29
|
-
assertEquals(getRemoteHost(new URL("https://example.com/inbox")), "example.com");
|
|
30
|
-
assertEquals(getRemoteHost(new URL("https://example.com:8443/inbox")), "example.com:8443");
|
|
31
|
-
assertEquals(getRemoteHost(new URL("https://example.com:443/inbox")), "example.com");
|
|
32
|
-
});
|
|
33
|
-
test("recordFanoutRecipients() records the recipient count with activity type", () => {
|
|
34
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
35
|
-
recordFanoutRecipients(meterProvider, 7, "https://www.w3.org/ns/activitystreams#Create");
|
|
36
|
-
const measurements = recorder.getMeasurements("activitypub.fanout.recipients");
|
|
37
|
-
assertEquals(measurements.length, 1);
|
|
38
|
-
assertEquals(measurements[0].type, "histogram");
|
|
39
|
-
assertEquals(measurements[0].value, 7);
|
|
40
|
-
assertEquals(measurements[0].attributes["activitypub.activity.type"], "https://www.w3.org/ns/activitystreams#Create");
|
|
41
|
-
});
|
|
42
|
-
test("recordFanoutRecipients() omits activity type when unknown", () => {
|
|
43
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
44
|
-
recordFanoutRecipients(meterProvider, 0);
|
|
45
|
-
const measurements = recorder.getMeasurements("activitypub.fanout.recipients");
|
|
46
|
-
assertEquals(measurements.length, 1);
|
|
47
|
-
assertEquals(measurements[0].value, 0);
|
|
48
|
-
assertEquals("activitypub.activity.type" in measurements[0].attributes, false);
|
|
49
|
-
});
|
|
50
|
-
test("signature verification duration uses explicit low-latency buckets", async () => {
|
|
51
|
-
const reader = new TestMetricReader();
|
|
52
|
-
const meterProvider = new MeterProvider({ readers: [reader] });
|
|
53
|
-
try {
|
|
54
|
-
getFederationMetrics(meterProvider).recordSignatureVerificationDuration(7, "http", "verified");
|
|
55
|
-
const metric = (await reader.collect()).resourceMetrics.scopeMetrics.flatMap((scope) => scope.metrics).find((metric) => metric.descriptor.name === "activitypub.signature.verification.duration");
|
|
56
|
-
assertEquals(metric?.dataPointType, DataPointType.HISTOGRAM);
|
|
57
|
-
assertEquals(metric?.dataPoints[0].value.buckets.boundaries, [
|
|
58
|
-
.1,
|
|
59
|
-
.25,
|
|
60
|
-
.5,
|
|
61
|
-
1,
|
|
62
|
-
2.5,
|
|
63
|
-
5,
|
|
64
|
-
10,
|
|
65
|
-
25,
|
|
66
|
-
50,
|
|
67
|
-
100,
|
|
68
|
-
250,
|
|
69
|
-
500,
|
|
70
|
-
1e3
|
|
71
|
-
]);
|
|
72
|
-
} finally {
|
|
73
|
-
await meterProvider.shutdown();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
test("registerQueueDepthGauge() skips unavailable depth snapshots", async () => {
|
|
77
|
-
const reader = new TestMetricReader();
|
|
78
|
-
const meterProvider = new MeterProvider({ readers: [reader] });
|
|
79
|
-
try {
|
|
80
|
-
registerQueueDepthGauge(meterProvider, [
|
|
81
|
-
{
|
|
82
|
-
role: "inbox",
|
|
83
|
-
queue: {
|
|
84
|
-
enqueue() {
|
|
85
|
-
return Promise.resolve();
|
|
86
|
-
},
|
|
87
|
-
listen() {
|
|
88
|
-
return Promise.resolve();
|
|
89
|
-
},
|
|
90
|
-
getDepth() {
|
|
91
|
-
throw new TypeError("backend unavailable");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
role: "outbox",
|
|
97
|
-
queue: {
|
|
98
|
-
enqueue() {
|
|
99
|
-
return Promise.resolve();
|
|
100
|
-
},
|
|
101
|
-
listen() {
|
|
102
|
-
return Promise.resolve();
|
|
103
|
-
},
|
|
104
|
-
getDepth() {
|
|
105
|
-
return Promise.resolve(null);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
role: "fanout",
|
|
111
|
-
queue: {
|
|
112
|
-
enqueue() {
|
|
113
|
-
return Promise.resolve();
|
|
114
|
-
},
|
|
115
|
-
listen() {
|
|
116
|
-
return Promise.resolve();
|
|
117
|
-
},
|
|
118
|
-
getDepth() {
|
|
119
|
-
return Promise.resolve({ queued: 7 });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
]);
|
|
124
|
-
const result = await reader.collect();
|
|
125
|
-
assertEquals(result.errors, []);
|
|
126
|
-
const queueDepth = result.resourceMetrics.scopeMetrics.flatMap((scope) => scope.metrics).find((metric) => metric.descriptor.name === "fedify.queue.depth");
|
|
127
|
-
assertEquals(queueDepth?.dataPointType, DataPointType.GAUGE);
|
|
128
|
-
assertEquals(queueDepth?.dataPoints.map((point) => ({
|
|
129
|
-
state: point.attributes["fedify.queue.depth.state"],
|
|
130
|
-
role: point.attributes["fedify.queue.role"],
|
|
131
|
-
value: point.value
|
|
132
|
-
})), [{
|
|
133
|
-
state: "queued",
|
|
134
|
-
role: "fanout",
|
|
135
|
-
value: 7
|
|
136
|
-
}]);
|
|
137
|
-
} finally {
|
|
138
|
-
await meterProvider.shutdown();
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
test("registerQueueDepthGauge() queries queue depths in parallel", async () => {
|
|
142
|
-
const reader = new TestMetricReader();
|
|
143
|
-
const meterProvider = new MeterProvider({ readers: [reader] });
|
|
144
|
-
let releaseSlowDepth;
|
|
145
|
-
let fastDepthStarted = false;
|
|
146
|
-
try {
|
|
147
|
-
registerQueueDepthGauge(meterProvider, [{
|
|
148
|
-
role: "inbox",
|
|
149
|
-
queue: {
|
|
150
|
-
enqueue() {
|
|
151
|
-
return Promise.resolve();
|
|
152
|
-
},
|
|
153
|
-
listen() {
|
|
154
|
-
return Promise.resolve();
|
|
155
|
-
},
|
|
156
|
-
getDepth() {
|
|
157
|
-
return new Promise((resolve) => {
|
|
158
|
-
releaseSlowDepth = resolve;
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}, {
|
|
163
|
-
role: "outbox",
|
|
164
|
-
queue: {
|
|
165
|
-
enqueue() {
|
|
166
|
-
return Promise.resolve();
|
|
167
|
-
},
|
|
168
|
-
listen() {
|
|
169
|
-
return Promise.resolve();
|
|
170
|
-
},
|
|
171
|
-
getDepth() {
|
|
172
|
-
fastDepthStarted = true;
|
|
173
|
-
return Promise.resolve({ queued: 5 });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}]);
|
|
177
|
-
const collection = reader.collect();
|
|
178
|
-
await Promise.resolve();
|
|
179
|
-
assertEquals(fastDepthStarted, true);
|
|
180
|
-
releaseSlowDepth?.({ queued: 3 });
|
|
181
|
-
assertEquals((await collection).resourceMetrics.scopeMetrics.flatMap((scope) => scope.metrics).find((metric) => metric.descriptor.name === "fedify.queue.depth")?.dataPoints.map((point) => point.value).sort(), [3, 5]);
|
|
182
|
-
} finally {
|
|
183
|
-
releaseSlowDepth?.({ queued: 0 });
|
|
184
|
-
await meterProvider.shutdown();
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
test("recordInboxActivity() records counter with result and activity type", () => {
|
|
188
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
189
|
-
for (const result of [
|
|
190
|
-
"queued",
|
|
191
|
-
"processed",
|
|
192
|
-
"retried",
|
|
193
|
-
"rejected",
|
|
194
|
-
"abandoned"
|
|
195
|
-
]) recordInboxActivity(meterProvider, result, "https://www.w3.org/ns/activitystreams#Follow");
|
|
196
|
-
const measurements = recorder.getMeasurements("activitypub.inbox.activity");
|
|
197
|
-
assertEquals(measurements.length, 5);
|
|
198
|
-
for (const m of measurements) {
|
|
199
|
-
assertEquals(m.type, "counter");
|
|
200
|
-
assertEquals(m.value, 1);
|
|
201
|
-
assertEquals(m.attributes["activitypub.activity.type"], "https://www.w3.org/ns/activitystreams#Follow");
|
|
202
|
-
}
|
|
203
|
-
assertEquals(measurements.map((m) => m.attributes["activitypub.processing.result"]), [
|
|
204
|
-
"queued",
|
|
205
|
-
"processed",
|
|
206
|
-
"retried",
|
|
207
|
-
"rejected",
|
|
208
|
-
"abandoned"
|
|
209
|
-
]);
|
|
210
|
-
});
|
|
211
|
-
test("recordInboxActivity() omits activity type when unknown", () => {
|
|
212
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
213
|
-
recordInboxActivity(meterProvider, "rejected");
|
|
214
|
-
const measurements = recorder.getMeasurements("activitypub.inbox.activity");
|
|
215
|
-
assertEquals(measurements.length, 1);
|
|
216
|
-
assertEquals(measurements[0].attributes["activitypub.processing.result"], "rejected");
|
|
217
|
-
assertEquals("activitypub.activity.type" in measurements[0].attributes, false);
|
|
218
|
-
});
|
|
219
|
-
test("recordOutboxEnqueue() also records activitypub.outbox.activity{queued} on initial enqueue", () => {
|
|
220
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
221
|
-
recordOutboxEnqueue(meterProvider, noopQueue, {
|
|
222
|
-
activityType: "https://www.w3.org/ns/activitystreams#Create",
|
|
223
|
-
attempt: 0
|
|
224
|
-
});
|
|
225
|
-
const queued = recorder.getMeasurements("activitypub.outbox.activity");
|
|
226
|
-
assertEquals(queued.length, 1);
|
|
227
|
-
assertEquals(queued[0].type, "counter");
|
|
228
|
-
assertEquals(queued[0].attributes["activitypub.processing.result"], "queued");
|
|
229
|
-
assertEquals(queued[0].attributes["activitypub.activity.type"], "https://www.w3.org/ns/activitystreams#Create");
|
|
230
|
-
});
|
|
231
|
-
test("recordOutboxEnqueue() does not record outbox.activity{queued} on retry enqueues", () => {
|
|
232
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
233
|
-
recordOutboxEnqueue(meterProvider, noopQueue, {
|
|
234
|
-
activityType: "https://www.w3.org/ns/activitystreams#Create",
|
|
235
|
-
attempt: 1
|
|
236
|
-
});
|
|
237
|
-
assertEquals(recorder.getMeasurements("activitypub.outbox.activity").length, 0);
|
|
238
|
-
});
|
|
239
|
-
test("recordOutboxActivity() records counter with result and activity type", () => {
|
|
240
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
241
|
-
for (const result of [
|
|
242
|
-
"queued",
|
|
243
|
-
"retried",
|
|
244
|
-
"abandoned"
|
|
245
|
-
]) recordOutboxActivity(meterProvider, result, "https://www.w3.org/ns/activitystreams#Announce");
|
|
246
|
-
const measurements = recorder.getMeasurements("activitypub.outbox.activity");
|
|
247
|
-
assertEquals(measurements.length, 3);
|
|
248
|
-
for (const m of measurements) {
|
|
249
|
-
assertEquals(m.type, "counter");
|
|
250
|
-
assertEquals(m.value, 1);
|
|
251
|
-
assertEquals(m.attributes["activitypub.activity.type"], "https://www.w3.org/ns/activitystreams#Announce");
|
|
252
|
-
}
|
|
253
|
-
assertEquals(measurements.map((m) => m.attributes["activitypub.processing.result"]), [
|
|
254
|
-
"queued",
|
|
255
|
-
"retried",
|
|
256
|
-
"abandoned"
|
|
257
|
-
]);
|
|
258
|
-
});
|
|
259
|
-
test("recordCircuitBreakerStateChange() records counter with bounded attributes", () => {
|
|
260
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
261
|
-
recordCircuitBreakerStateChange(meterProvider, "remote.example", "half_open");
|
|
262
|
-
const measurements = recorder.getMeasurements("activitypub.circuit_breaker.state_change");
|
|
263
|
-
assertEquals(measurements.length, 1);
|
|
264
|
-
assertEquals(measurements[0].type, "counter");
|
|
265
|
-
assertEquals(measurements[0].value, 1);
|
|
266
|
-
assertEquals(measurements[0].attributes["activitypub.remote.host"], "remote.example");
|
|
267
|
-
assertEquals(measurements[0].attributes["activitypub.circuit_breaker.state"], "half_open");
|
|
268
|
-
});
|
|
269
|
-
test("recordKeyLookup() records counter and duration with all attributes", () => {
|
|
270
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
271
|
-
recordKeyLookup(meterProvider, {
|
|
272
|
-
durationMs: 42,
|
|
273
|
-
result: "fetched",
|
|
274
|
-
remoteUrl: new URL("https://example.com/users/alice#main-key"),
|
|
275
|
-
cacheEnabled: true,
|
|
276
|
-
statusCode: 200
|
|
277
|
-
});
|
|
278
|
-
const counters = recorder.getMeasurements("activitypub.key.lookup");
|
|
279
|
-
assertEquals(counters.length, 1);
|
|
280
|
-
assertEquals(counters[0].type, "counter");
|
|
281
|
-
assertEquals(counters[0].value, 1);
|
|
282
|
-
assertEquals(counters[0].attributes["activitypub.lookup.kind"], "public_key");
|
|
283
|
-
assertEquals(counters[0].attributes["activitypub.lookup.result"], "fetched");
|
|
284
|
-
assertEquals(counters[0].attributes["activitypub.remote.host"], "example.com");
|
|
285
|
-
assertEquals(counters[0].attributes["activitypub.cache.enabled"], true);
|
|
286
|
-
assertEquals(counters[0].attributes["http.response.status_code"], 200);
|
|
287
|
-
const durations = recorder.getMeasurements("activitypub.key.lookup.duration");
|
|
288
|
-
assertEquals(durations.length, 1);
|
|
289
|
-
assertEquals(durations[0].type, "histogram");
|
|
290
|
-
assertEquals(durations[0].value, 42);
|
|
291
|
-
assertEquals(durations[0].attributes["activitypub.lookup.kind"], "public_key");
|
|
292
|
-
assertEquals(durations[0].attributes["activitypub.lookup.result"], "fetched");
|
|
293
|
-
assertEquals(durations[0].attributes["activitypub.remote.host"], "example.com");
|
|
294
|
-
assertEquals(durations[0].attributes["activitypub.cache.enabled"], true);
|
|
295
|
-
assertEquals(durations[0].attributes["http.response.status_code"], 200);
|
|
296
|
-
});
|
|
297
|
-
test("recordKeyLookup() omits optional attributes when not provided", () => {
|
|
298
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
299
|
-
recordKeyLookup(meterProvider, {
|
|
300
|
-
durationMs: 0,
|
|
301
|
-
result: "error",
|
|
302
|
-
cacheEnabled: false
|
|
303
|
-
});
|
|
304
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
305
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "error");
|
|
306
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
|
|
307
|
-
assertEquals("activitypub.remote.host" in counter.attributes, false);
|
|
308
|
-
assertEquals("http.response.status_code" in counter.attributes, false);
|
|
309
|
-
const duration = recorder.getMeasurement("activitypub.key.lookup.duration");
|
|
310
|
-
assertEquals("activitypub.remote.host" in duration.attributes, false);
|
|
311
|
-
assertEquals("http.response.status_code" in duration.attributes, false);
|
|
312
|
-
});
|
|
313
|
-
test("recordDocumentFetch() records counter and duration with all attributes", () => {
|
|
314
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
315
|
-
recordDocumentFetch(meterProvider, {
|
|
316
|
-
durationMs: 123,
|
|
317
|
-
kind: "object",
|
|
318
|
-
result: "not_found",
|
|
319
|
-
remoteUrl: new URL("https://remote.test/objects/123"),
|
|
320
|
-
cacheEnabled: true,
|
|
321
|
-
statusCode: 404
|
|
322
|
-
});
|
|
323
|
-
const counter = recorder.getMeasurement("activitypub.document.fetch");
|
|
324
|
-
assertEquals(counter?.type, "counter");
|
|
325
|
-
assertEquals(counter?.value, 1);
|
|
326
|
-
assertEquals(counter?.attributes["activitypub.lookup.kind"], "object");
|
|
327
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "not_found");
|
|
328
|
-
assertEquals(counter?.attributes["activitypub.remote.host"], "remote.test");
|
|
329
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], true);
|
|
330
|
-
assertEquals(counter?.attributes["http.response.status_code"], 404);
|
|
331
|
-
const duration = recorder.getMeasurement("activitypub.document.fetch.duration");
|
|
332
|
-
assertEquals(duration?.type, "histogram");
|
|
333
|
-
assertEquals(duration?.value, 123);
|
|
334
|
-
assertEquals(duration?.attributes["activitypub.lookup.kind"], "object");
|
|
335
|
-
assertEquals(duration?.attributes["activitypub.lookup.result"], "not_found");
|
|
336
|
-
});
|
|
337
|
-
test("recordDocumentFetch() omits optional attributes when not provided", () => {
|
|
338
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
339
|
-
recordDocumentFetch(meterProvider, {
|
|
340
|
-
durationMs: 5,
|
|
341
|
-
kind: "context",
|
|
342
|
-
result: "fetched"
|
|
343
|
-
});
|
|
344
|
-
const counter = recorder.getMeasurement("activitypub.document.fetch");
|
|
345
|
-
assertEquals(counter?.attributes["activitypub.lookup.kind"], "context");
|
|
346
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
|
|
347
|
-
assertEquals("activitypub.remote.host" in counter.attributes, false);
|
|
348
|
-
assertEquals("activitypub.cache.enabled" in counter.attributes, false);
|
|
349
|
-
assertEquals("http.response.status_code" in counter.attributes, false);
|
|
350
|
-
assertEquals(recorder.getMeasurement("activitypub.document.fetch.duration")?.value, 5);
|
|
351
|
-
});
|
|
352
|
-
test("recordDocumentCache() records hit and miss as a counter", () => {
|
|
353
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
354
|
-
recordDocumentCache(meterProvider, {
|
|
355
|
-
kind: "object",
|
|
356
|
-
result: "hit",
|
|
357
|
-
remoteUrl: new URL("https://remote.test/objects/1")
|
|
358
|
-
});
|
|
359
|
-
recordDocumentCache(meterProvider, {
|
|
360
|
-
kind: "context",
|
|
361
|
-
result: "miss",
|
|
362
|
-
remoteUrl: new URL("https://w3id.org/security/v1")
|
|
363
|
-
});
|
|
364
|
-
const measurements = recorder.getMeasurements("activitypub.document.cache");
|
|
365
|
-
assertEquals(measurements.length, 2);
|
|
366
|
-
for (const m of measurements) {
|
|
367
|
-
assertEquals(m.type, "counter");
|
|
368
|
-
assertEquals(m.value, 1);
|
|
369
|
-
}
|
|
370
|
-
assertEquals(measurements[0].attributes["activitypub.lookup.kind"], "object");
|
|
371
|
-
assertEquals(measurements[0].attributes["activitypub.lookup.result"], "hit");
|
|
372
|
-
assertEquals(measurements[0].attributes["activitypub.remote.host"], "remote.test");
|
|
373
|
-
assertEquals(measurements[1].attributes["activitypub.lookup.kind"], "context");
|
|
374
|
-
assertEquals(measurements[1].attributes["activitypub.lookup.result"], "miss");
|
|
375
|
-
assertEquals(measurements[1].attributes["activitypub.remote.host"], "w3id.org");
|
|
376
|
-
});
|
|
377
|
-
test("recordWebFingerHandle() records counter and duration with all attributes", () => {
|
|
378
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
379
|
-
recordWebFingerHandle(meterProvider, {
|
|
380
|
-
durationMs: 17,
|
|
381
|
-
result: "resolved",
|
|
382
|
-
scheme: "acct",
|
|
383
|
-
statusCode: 200
|
|
384
|
-
});
|
|
385
|
-
const counters = recorder.getMeasurements("webfinger.handle");
|
|
386
|
-
assertEquals(counters.length, 1);
|
|
387
|
-
assertEquals(counters[0].type, "counter");
|
|
388
|
-
assertEquals(counters[0].value, 1);
|
|
389
|
-
assertEquals(counters[0].attributes["webfinger.handle.result"], "resolved");
|
|
390
|
-
assertEquals(counters[0].attributes["webfinger.resource.scheme"], "acct");
|
|
391
|
-
assertEquals(counters[0].attributes["http.response.status_code"], 200);
|
|
392
|
-
const durations = recorder.getMeasurements("webfinger.handle.duration");
|
|
393
|
-
assertEquals(durations.length, 1);
|
|
394
|
-
assertEquals(durations[0].type, "histogram");
|
|
395
|
-
assertEquals(durations[0].value, 17);
|
|
396
|
-
assertEquals(durations[0].attributes["webfinger.handle.result"], "resolved");
|
|
397
|
-
assertEquals(durations[0].attributes["webfinger.resource.scheme"], "acct");
|
|
398
|
-
assertEquals(durations[0].attributes["http.response.status_code"], 200);
|
|
399
|
-
});
|
|
400
|
-
test("recordWebFingerHandle() records each non-resolved result with the matching status code", () => {
|
|
401
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
402
|
-
for (const [result, statusCode] of [
|
|
403
|
-
["invalid", 400],
|
|
404
|
-
["not_found", 404],
|
|
405
|
-
["tombstoned", 410]
|
|
406
|
-
]) recordWebFingerHandle(meterProvider, {
|
|
407
|
-
durationMs: 1,
|
|
408
|
-
result,
|
|
409
|
-
scheme: "acct",
|
|
410
|
-
statusCode
|
|
411
|
-
});
|
|
412
|
-
const counters = recorder.getMeasurements("webfinger.handle");
|
|
413
|
-
assertEquals(counters.length, 3);
|
|
414
|
-
assertEquals(counters.map((m) => m.attributes["webfinger.handle.result"]), [
|
|
415
|
-
"invalid",
|
|
416
|
-
"not_found",
|
|
417
|
-
"tombstoned"
|
|
418
|
-
]);
|
|
419
|
-
assertEquals(counters.map((m) => m.attributes["http.response.status_code"]), [
|
|
420
|
-
400,
|
|
421
|
-
404,
|
|
422
|
-
410
|
|
423
|
-
]);
|
|
424
|
-
});
|
|
425
|
-
test("recordWebFingerHandle() omits optional attributes when not provided", () => {
|
|
426
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
427
|
-
recordWebFingerHandle(meterProvider, {
|
|
428
|
-
durationMs: 0,
|
|
429
|
-
result: "error"
|
|
430
|
-
});
|
|
431
|
-
const counter = recorder.getMeasurement("webfinger.handle");
|
|
432
|
-
assertEquals(counter?.attributes["webfinger.handle.result"], "error");
|
|
433
|
-
assertEquals("webfinger.resource.scheme" in (counter?.attributes ?? {}), false);
|
|
434
|
-
assertEquals("http.response.status_code" in (counter?.attributes ?? {}), false);
|
|
435
|
-
});
|
|
436
|
-
test("recordCollectionRequest() records counter with bounded attributes", () => {
|
|
437
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
438
|
-
recordCollectionRequest(meterProvider, {
|
|
439
|
-
kind: "followers",
|
|
440
|
-
page: true,
|
|
441
|
-
dispatcher: "built_in",
|
|
442
|
-
result: "served",
|
|
443
|
-
statusCode: 200
|
|
444
|
-
});
|
|
445
|
-
const counter = recorder.getMeasurement("activitypub.collection.request");
|
|
446
|
-
assertEquals(counter?.type, "counter");
|
|
447
|
-
assertEquals(counter?.value, 1);
|
|
448
|
-
assertEquals(counter?.attributes["activitypub.collection.kind"], "followers");
|
|
449
|
-
assertEquals(counter?.attributes["activitypub.collection.page"], true);
|
|
450
|
-
assertEquals(counter?.attributes["fedify.collection.dispatcher"], "built_in");
|
|
451
|
-
assertEquals(counter?.attributes["activitypub.collection.result"], "served");
|
|
452
|
-
assertEquals(counter?.attributes["http.response.status_code"], 200);
|
|
453
|
-
});
|
|
454
|
-
test("recordCollectionRequest() omits status code when unavailable", () => {
|
|
455
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
456
|
-
recordCollectionRequest(meterProvider, {
|
|
457
|
-
kind: "custom",
|
|
458
|
-
page: false,
|
|
459
|
-
dispatcher: "custom",
|
|
460
|
-
result: "error"
|
|
461
|
-
});
|
|
462
|
-
const counter = recorder.getMeasurement("activitypub.collection.request");
|
|
463
|
-
assertEquals(counter?.attributes["activitypub.collection.kind"], "custom");
|
|
464
|
-
assertEquals(counter?.attributes["activitypub.collection.page"], false);
|
|
465
|
-
assertEquals(counter?.attributes["fedify.collection.dispatcher"], "custom");
|
|
466
|
-
assertEquals(counter?.attributes["activitypub.collection.result"], "error");
|
|
467
|
-
assertEquals("http.response.status_code" in (counter?.attributes ?? {}), false);
|
|
468
|
-
});
|
|
469
|
-
test("recordCollectionDispatchDuration() records histogram", () => {
|
|
470
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
471
|
-
recordCollectionDispatchDuration(meterProvider, 12, {
|
|
472
|
-
kind: "outbox",
|
|
473
|
-
page: false,
|
|
474
|
-
dispatcher: "built_in",
|
|
475
|
-
result: "served"
|
|
476
|
-
});
|
|
477
|
-
const duration = recorder.getMeasurement("activitypub.collection.dispatch.duration");
|
|
478
|
-
assertEquals(duration?.type, "histogram");
|
|
479
|
-
assertEquals(duration?.value, 12);
|
|
480
|
-
assertEquals(duration?.attributes["activitypub.collection.kind"], "outbox");
|
|
481
|
-
assertEquals(duration?.attributes["activitypub.collection.page"], false);
|
|
482
|
-
assertEquals(duration?.attributes["fedify.collection.dispatcher"], "built_in");
|
|
483
|
-
assertEquals(duration?.attributes["activitypub.collection.result"], "served");
|
|
484
|
-
});
|
|
485
|
-
test("recordCollectionPageItems() records item count histogram", () => {
|
|
486
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
487
|
-
recordCollectionPageItems(meterProvider, 3, {
|
|
488
|
-
kind: "featured_tags",
|
|
489
|
-
page: true,
|
|
490
|
-
dispatcher: "built_in",
|
|
491
|
-
result: "served",
|
|
492
|
-
statusCode: 200
|
|
493
|
-
});
|
|
494
|
-
const items = recorder.getMeasurement("activitypub.collection.page.items");
|
|
495
|
-
assertEquals(items?.type, "histogram");
|
|
496
|
-
assertEquals(items?.value, 3);
|
|
497
|
-
assertEquals(items?.attributes["activitypub.collection.kind"], "featured_tags");
|
|
498
|
-
assertEquals(items?.attributes["activitypub.collection.page"], true);
|
|
499
|
-
assertEquals(items?.attributes["http.response.status_code"], 200);
|
|
500
|
-
});
|
|
501
|
-
test("recordCollectionTotalItems() records total item histogram", () => {
|
|
502
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
503
|
-
recordCollectionTotalItems(meterProvider, 42, {
|
|
504
|
-
kind: "liked",
|
|
505
|
-
page: false,
|
|
506
|
-
dispatcher: "built_in",
|
|
507
|
-
result: "served"
|
|
508
|
-
});
|
|
509
|
-
const total = recorder.getMeasurement("activitypub.collection.total_items");
|
|
510
|
-
assertEquals(total?.type, "histogram");
|
|
511
|
-
assertEquals(total?.value, 42);
|
|
512
|
-
assertEquals(total?.attributes["activitypub.collection.kind"], "liked");
|
|
513
|
-
assertEquals(total?.attributes["activitypub.collection.page"], false);
|
|
514
|
-
});
|
|
515
|
-
test("classifyFetchError() classifies FetchError with 404 as not_found", () => {
|
|
516
|
-
assertEquals(classifyFetchError(new FetchError("https://example.com/k", "not found", new Response("", { status: 404 }))), {
|
|
517
|
-
result: "not_found",
|
|
518
|
-
statusCode: 404
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
test("classifyFetchError() classifies FetchError with 410 as not_found", () => {
|
|
522
|
-
assertEquals(classifyFetchError(new FetchError("https://example.com/k", "gone", new Response("", { status: 410 }))), {
|
|
523
|
-
result: "not_found",
|
|
524
|
-
statusCode: 410
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
test("classifyFetchError() classifies FetchError with 500 as error", () => {
|
|
528
|
-
assertEquals(classifyFetchError(new FetchError("https://example.com/k", "server error", new Response("", { status: 500 }))), {
|
|
529
|
-
result: "error",
|
|
530
|
-
statusCode: 500
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
test("classifyFetchError() classifies FetchError without response as network_error", () => {
|
|
534
|
-
assertEquals(classifyFetchError(new FetchError("https://example.com/k", "boom")), { result: "network_error" });
|
|
535
|
-
});
|
|
536
|
-
test("classifyFetchError() classifies a bare TypeError as network_error", () => {
|
|
537
|
-
assertEquals(classifyFetchError(/* @__PURE__ */ new TypeError("connect failed")), { result: "network_error" });
|
|
538
|
-
});
|
|
539
|
-
test("classifyFetchError() classifies an AbortError as network_error", () => {
|
|
540
|
-
const abort = /* @__PURE__ */ new Error("aborted");
|
|
541
|
-
abort.name = "AbortError";
|
|
542
|
-
assertEquals(classifyFetchError(abort), { result: "network_error" });
|
|
543
|
-
});
|
|
544
|
-
test("classifyFetchError() classifies any other thrown value as error", () => {
|
|
545
|
-
assertEquals(classifyFetchError(/* @__PURE__ */ new Error("nope")), { result: "error" });
|
|
546
|
-
assertEquals(classifyFetchError("string error"), { result: "error" });
|
|
547
|
-
assertEquals(classifyFetchError(void 0), { result: "error" });
|
|
548
|
-
});
|
|
549
|
-
test("instrumentDocumentLoader() records fetched on success", async () => {
|
|
550
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
551
|
-
const inner = (url) => Promise.resolve({
|
|
552
|
-
contextUrl: null,
|
|
553
|
-
documentUrl: url,
|
|
554
|
-
document: { ok: true }
|
|
555
|
-
});
|
|
556
|
-
assertEquals((await instrumentDocumentLoader(inner, {
|
|
557
|
-
meterProvider,
|
|
558
|
-
kind: "object",
|
|
559
|
-
cacheEnabled: true
|
|
560
|
-
})("https://example.com/o")).document, { ok: true });
|
|
561
|
-
const counter = recorder.getMeasurement("activitypub.document.fetch");
|
|
562
|
-
assertEquals(counter?.attributes["activitypub.lookup.kind"], "object");
|
|
563
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
|
|
564
|
-
assertEquals(counter?.attributes["activitypub.remote.host"], "example.com");
|
|
565
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], true);
|
|
566
|
-
assertEquals("http.response.status_code" in counter.attributes, false);
|
|
567
|
-
const duration = recorder.getMeasurement("activitypub.document.fetch.duration");
|
|
568
|
-
assertEquals(duration?.type, "histogram");
|
|
569
|
-
assertEquals(duration?.attributes["activitypub.lookup.result"], "fetched");
|
|
570
|
-
});
|
|
571
|
-
test("instrumentDocumentLoader() records not_found on FetchError 404", async () => {
|
|
572
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
573
|
-
const inner = (url) => Promise.reject(new FetchError(url, "HTTP 404", new Response("", { status: 404 })));
|
|
574
|
-
const wrapped = instrumentDocumentLoader(inner, {
|
|
575
|
-
meterProvider,
|
|
576
|
-
kind: "context",
|
|
577
|
-
cacheEnabled: false
|
|
578
|
-
});
|
|
579
|
-
await assertRejects(() => wrapped("https://example.com/missing"), FetchError);
|
|
580
|
-
const counter = recorder.getMeasurement("activitypub.document.fetch");
|
|
581
|
-
assertEquals(counter?.attributes["activitypub.lookup.kind"], "context");
|
|
582
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "not_found");
|
|
583
|
-
assertEquals(counter?.attributes["activitypub.remote.host"], "example.com");
|
|
584
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
|
|
585
|
-
assertEquals(counter?.attributes["http.response.status_code"], 404);
|
|
586
|
-
});
|
|
587
|
-
test("instrumentDocumentLoader() records network_error on TypeError", async () => {
|
|
588
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
589
|
-
const inner = () => Promise.reject(/* @__PURE__ */ new TypeError("fetch failed"));
|
|
590
|
-
const wrapped = instrumentDocumentLoader(inner, {
|
|
591
|
-
meterProvider,
|
|
592
|
-
kind: "object"
|
|
593
|
-
});
|
|
594
|
-
await assertRejects(() => wrapped("https://example.com/o"), TypeError);
|
|
595
|
-
const counter = recorder.getMeasurement("activitypub.document.fetch");
|
|
596
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "network_error");
|
|
597
|
-
assertEquals("activitypub.cache.enabled" in counter.attributes, false);
|
|
598
|
-
});
|
|
599
|
-
test("instrumentDocumentLoader() returns inner loader unchanged when meterProvider is omitted", async () => {
|
|
600
|
-
const [, recorder] = createTestMeterProvider();
|
|
601
|
-
let callCount = 0;
|
|
602
|
-
const inner = (url) => {
|
|
603
|
-
callCount++;
|
|
604
|
-
return Promise.resolve({
|
|
605
|
-
contextUrl: null,
|
|
606
|
-
documentUrl: url,
|
|
607
|
-
document: { ok: true }
|
|
608
|
-
});
|
|
609
|
-
};
|
|
610
|
-
const wrapped = instrumentDocumentLoader(inner, { kind: "object" });
|
|
611
|
-
assertEquals(wrapped, inner);
|
|
612
|
-
await wrapped("https://example.com/o");
|
|
613
|
-
assertEquals(callCount, 1);
|
|
614
|
-
assertEquals(recorder.getMeasurements("activitypub.document.fetch").length, 0);
|
|
615
|
-
assertEquals(recorder.getMeasurements("activitypub.document.fetch.duration").length, 0);
|
|
616
|
-
});
|
|
617
|
-
test("instrumentDocumentLoader() omits remote.host when URL is unparseable", async () => {
|
|
618
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
619
|
-
const inner = (url) => Promise.resolve({
|
|
620
|
-
contextUrl: null,
|
|
621
|
-
documentUrl: url,
|
|
622
|
-
document: {}
|
|
623
|
-
});
|
|
624
|
-
await instrumentDocumentLoader(inner, {
|
|
625
|
-
meterProvider,
|
|
626
|
-
kind: "other"
|
|
627
|
-
})("not a url");
|
|
628
|
-
const counter = recorder.getMeasurement("activitypub.document.fetch");
|
|
629
|
-
assertEquals(counter?.attributes["activitypub.lookup.kind"], "other");
|
|
630
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
|
|
631
|
-
assertEquals("activitypub.remote.host" in counter.attributes, false);
|
|
632
|
-
});
|
|
633
|
-
//#endregion
|
|
634
|
-
export {};
|