@mark1russell7/otel-sink 0.1.0 → 0.1.1
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/CHANGELOG.md +6 -0
- package/dist/api.d.ts +37 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +169 -0
- package/dist/api.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +34 -0
- package/dist/main.js.map +1 -0
- package/dist/otlp.d.ts +173 -0
- package/dist/otlp.d.ts.map +1 -0
- package/dist/otlp.js +144 -0
- package/dist/otlp.js.map +1 -0
- package/dist/query.d.ts +74 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +78 -0
- package/dist/query.js.map +1 -0
- package/dist/retention.d.ts +27 -0
- package/dist/retention.d.ts.map +1 -0
- package/dist/retention.js +39 -0
- package/dist/retention.js.map +1 -0
- package/dist/store.d.ts +71 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +151 -0
- package/dist/store.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Version 0.1.0 has no `dist` folder, so its entry points and the command `otel-sink` do not work. The build of the repository did not start the build of this package. Use 0.1.1 or later.
|
|
8
|
+
|
|
3
9
|
## 0.1.0
|
|
4
10
|
|
|
5
11
|
### Added
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ServiceBuilder } from "@mark1russell7/service";
|
|
2
|
+
import { type RequestHandler } from "@mark1russell7/service/http";
|
|
3
|
+
import { type Window } from "./query.ts";
|
|
4
|
+
import type { Store } from "./store.ts";
|
|
5
|
+
/** These are the options of the API of the service. */
|
|
6
|
+
export interface ApiOptions {
|
|
7
|
+
/** This number is the port of the API. */
|
|
8
|
+
readonly port: number;
|
|
9
|
+
/** This function gives the store. It throws before the store opens. */
|
|
10
|
+
readonly store: () => Store;
|
|
11
|
+
/** This function gives the time in milliseconds since the epoch. The default is `Date.now`. */
|
|
12
|
+
readonly now?: (() => number) | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** The most bytes of the body of one export, after gzip: 8 MiB */
|
|
15
|
+
export declare const MAX_BODY_BYTES: number;
|
|
16
|
+
/** The window of a query without `since`: the last hour */
|
|
17
|
+
export declare const DEFAULT_WINDOW_MS: number;
|
|
18
|
+
/** The most rows of a query without `limit` */
|
|
19
|
+
export declare const DEFAULT_LIMIT = 50;
|
|
20
|
+
/** The routes of the queries. Each one is idempotent. */
|
|
21
|
+
export declare const QUERY_ROUTES: readonly ["GET /api/slowest", "GET /api/errors", "GET /api/services", "GET /api/trace", "GET /api/stats"];
|
|
22
|
+
/** The most bytes that the receiver reads and drops after a refusal. Past it, the receiver closes the connection. */
|
|
23
|
+
export declare const MAX_DISCARD_BYTES: number;
|
|
24
|
+
/**
|
|
25
|
+
* This function gives the handler of the OTLP/HTTP receiver: `POST /v1/traces`, `/v1/logs` and `/v1/metrics` with a
|
|
26
|
+
* body of OTLP JSON, with gzip or without it. It answers 415 to another type, 413 to a large body and 400 to a body
|
|
27
|
+
* that is not OTLP JSON. The handler writes its own status, so it is a mount of the transport, not a route of `handle`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const receiver: (store: () => Store) => RequestHandler;
|
|
30
|
+
/** This function gives the window of a query from the query string of its target. */
|
|
31
|
+
export declare const windowOf: (url: string | undefined, nowMs: number) => Window;
|
|
32
|
+
/**
|
|
33
|
+
* This function gives the API to the service of the entry: an HTTP server with the OTLP/HTTP receiver and the
|
|
34
|
+
* queries. The API is a component. It does not start the server, and it does not use `run()`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const attachApi: (svc: ServiceBuilder, options: ApiOptions) => ServiceBuilder;
|
|
37
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAiC,KAAK,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEjG,OAAO,EAA8D,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AACrG,OAAO,KAAK,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAC;AAI9C,uDAAuD;AACvD,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC;IAC5B,+FAA+F;IAC/F,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;CAC3C;AAED,kEAAkE;AAClE,eAAO,MAAM,cAAc,EAAE,MAAwB,CAAC;AAStD,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,EAAE,MAAuB,CAAC;AACxD,+CAA+C;AAC/C,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,yDAAyD;AACzD,eAAO,MAAM,YAAY,2GAA4G,CAAC;AAatI,qHAAqH;AACrH,eAAO,MAAM,iBAAiB,EAAE,MAA2B,CAAC;AA8C5D;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAK,KAAG,cA+B7C,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,GAAG,SAAS,EAAE,OAAO,MAAM,KAAG,MAUjE,CAAC;AAmBF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,cAAc,EAAE,SAAS,UAAU,KAAG,cAyBpE,CAAC"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { gunzip } from "node:zlib";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { handle, httpTransport, pathOf } from "@mark1russell7/service/http";
|
|
5
|
+
import { logRows, OtlpShapeError, pointRows, spanRows } from "./otlp.js";
|
|
6
|
+
import { errors, services, slowest, trace, TRACE_ID, windowProblems } from "./query.js";
|
|
7
|
+
const unzip = promisify(gunzip);
|
|
8
|
+
/** The most bytes of the body of one export, after gzip: 8 MiB */
|
|
9
|
+
export const MAX_BODY_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
/** The paths of the OTLP/HTTP receiver, and the rows of each body */
|
|
11
|
+
const RECEIVERS = {
|
|
12
|
+
"/v1/traces": (body) => ({ spans: spanRows(body) }),
|
|
13
|
+
"/v1/logs": (body) => ({ logs: logRows(body) }),
|
|
14
|
+
"/v1/metrics": (body) => ({ points: pointRows(body) }),
|
|
15
|
+
};
|
|
16
|
+
/** The window of a query without `since`: the last hour */
|
|
17
|
+
export const DEFAULT_WINDOW_MS = 60 * 60 * 1000;
|
|
18
|
+
/** The most rows of a query without `limit` */
|
|
19
|
+
export const DEFAULT_LIMIT = 50;
|
|
20
|
+
/** The routes of the queries. Each one is idempotent. */
|
|
21
|
+
export const QUERY_ROUTES = ["GET /api/slowest", "GET /api/errors", "GET /api/services", "GET /api/trace", "GET /api/stats"];
|
|
22
|
+
const s = (value) => ({ value, unit: "s" });
|
|
23
|
+
const reply = (res, status, body) => {
|
|
24
|
+
const text = JSON.stringify(body);
|
|
25
|
+
res.writeHead(status, { "content-type": "application/json", "content-length": Buffer.byteLength(text) });
|
|
26
|
+
res.end(text);
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
class TooLargeError extends Error {
|
|
30
|
+
}
|
|
31
|
+
/** The most bytes that the receiver reads and drops after a refusal. Past it, the receiver closes the connection. */
|
|
32
|
+
export const MAX_DISCARD_BYTES = 8 * MAX_BODY_BYTES;
|
|
33
|
+
/**
|
|
34
|
+
* This function reads the rest of a body and drops it, up to `MAX_DISCARD_BYTES`. Thus the client reads the refusal
|
|
35
|
+
* before the connection closes, and it does not get a reset. Past that size, it destroys the connection.
|
|
36
|
+
*/
|
|
37
|
+
const discard = (req, already = 0) => new Promise((resolve) => {
|
|
38
|
+
if (req.readableEnded)
|
|
39
|
+
return resolve();
|
|
40
|
+
let size = already;
|
|
41
|
+
req.removeAllListeners("data");
|
|
42
|
+
req.on("data", (part) => {
|
|
43
|
+
size += part.length;
|
|
44
|
+
if (size > MAX_DISCARD_BYTES) {
|
|
45
|
+
req.destroy();
|
|
46
|
+
resolve();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
req.once("end", () => resolve());
|
|
50
|
+
req.once("close", () => resolve());
|
|
51
|
+
req.once("error", () => resolve());
|
|
52
|
+
});
|
|
53
|
+
/** This function reads a body up to `MAX_BODY_BYTES`. Past that size, it drops the rest and rejects with a `TooLargeError`. */
|
|
54
|
+
const readBody = (req) => new Promise((resolve, reject) => {
|
|
55
|
+
const declared = Number(req.headers["content-length"] ?? 0);
|
|
56
|
+
if (declared > MAX_DISCARD_BYTES) {
|
|
57
|
+
req.destroy();
|
|
58
|
+
return reject(new TooLargeError());
|
|
59
|
+
}
|
|
60
|
+
if (declared > MAX_BODY_BYTES)
|
|
61
|
+
return void discard(req).then(() => reject(new TooLargeError()));
|
|
62
|
+
const parts = [];
|
|
63
|
+
let size = 0;
|
|
64
|
+
const onData = (part) => {
|
|
65
|
+
size += part.length;
|
|
66
|
+
if (size <= MAX_BODY_BYTES)
|
|
67
|
+
return void parts.push(part);
|
|
68
|
+
req.off("end", onEnd);
|
|
69
|
+
void discard(req, size).then(() => reject(new TooLargeError()));
|
|
70
|
+
};
|
|
71
|
+
const onEnd = () => resolve(Buffer.concat(parts));
|
|
72
|
+
req.on("data", onData);
|
|
73
|
+
req.once("end", onEnd);
|
|
74
|
+
req.once("error", reject);
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* This function gives the handler of the OTLP/HTTP receiver: `POST /v1/traces`, `/v1/logs` and `/v1/metrics` with a
|
|
78
|
+
* body of OTLP JSON, with gzip or without it. It answers 415 to another type, 413 to a large body and 400 to a body
|
|
79
|
+
* that is not OTLP JSON. The handler writes its own status, so it is a mount of the transport, not a route of `handle`.
|
|
80
|
+
*/
|
|
81
|
+
export const receiver = (store) => {
|
|
82
|
+
const handler = async (req, res) => {
|
|
83
|
+
const toRows = req.method === "POST" ? RECEIVERS[pathOf(req.url)] : undefined;
|
|
84
|
+
if (toRows === undefined)
|
|
85
|
+
return false;
|
|
86
|
+
const type = String(req.headers["content-type"] ?? "").split(";")[0]?.trim().toLowerCase();
|
|
87
|
+
if (type !== "application/json") {
|
|
88
|
+
await discard(req);
|
|
89
|
+
return reply(res, 415, { error: "the sink takes only OTLP JSON. Set OTEL_EXPORTER_OTLP_PROTOCOL=http/json in the sender." });
|
|
90
|
+
}
|
|
91
|
+
const encoding = String(req.headers["content-encoding"] ?? "identity").toLowerCase();
|
|
92
|
+
if (encoding !== "identity" && encoding !== "gzip") {
|
|
93
|
+
await discard(req);
|
|
94
|
+
return reply(res, 415, { error: `the sink takes no content encoding ${encoding}: only gzip or none` });
|
|
95
|
+
}
|
|
96
|
+
let rows;
|
|
97
|
+
try {
|
|
98
|
+
const raw = await readBody(req);
|
|
99
|
+
const text = encoding === "gzip" ? await unzip(raw, { maxOutputLength: MAX_BODY_BYTES }) : raw;
|
|
100
|
+
rows = toRows(JSON.parse(text.toString("utf8")));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof TooLargeError || error.code === "ERR_BUFFER_TOO_LARGE")
|
|
104
|
+
return reply(res, 413, { error: `the body is larger than ${MAX_BODY_BYTES} bytes` });
|
|
105
|
+
if (error instanceof SyntaxError || error instanceof OtlpShapeError || error.code === "Z_DATA_ERROR")
|
|
106
|
+
return reply(res, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
store().insert(rows);
|
|
110
|
+
// The success of OTLP/HTTP JSON: an empty response message, thus no partial success
|
|
111
|
+
return reply(res, 200, {});
|
|
112
|
+
};
|
|
113
|
+
return handler;
|
|
114
|
+
};
|
|
115
|
+
/** This function gives the window of a query from the query string of its target. */
|
|
116
|
+
export const windowOf = (url, nowMs) => {
|
|
117
|
+
const query = new URL(url ?? "/", "http://sink").searchParams;
|
|
118
|
+
const since = query.get("since");
|
|
119
|
+
const limit = query.get("limit");
|
|
120
|
+
const service = query.get("service");
|
|
121
|
+
return {
|
|
122
|
+
sinceMs: since === null ? nowMs - DEFAULT_WINDOW_MS : Number(since),
|
|
123
|
+
limit: limit === null ? DEFAULT_LIMIT : Number(limit),
|
|
124
|
+
...(service === null || service === "" ? {} : { service }),
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
const traceIdOf = (url) => new URL(url ?? "/", "http://sink").searchParams.get("id")?.toLowerCase() ?? "";
|
|
128
|
+
/**
|
|
129
|
+
* This function gives the handler that answers 400 to a query with bad parameters. It gives false for each other
|
|
130
|
+
* request, so the next handler gets it.
|
|
131
|
+
*/
|
|
132
|
+
const queryCheck = (now) => {
|
|
133
|
+
const handler = (req, res) => {
|
|
134
|
+
if (req.method !== "GET")
|
|
135
|
+
return false;
|
|
136
|
+
const path = pathOf(req.url);
|
|
137
|
+
if (!QUERY_ROUTES.includes(`GET ${path}`))
|
|
138
|
+
return false;
|
|
139
|
+
const problems = path === "/api/trace" ? (TRACE_ID.test(traceIdOf(req.url)) ? [] : ["id must be a trace id of 32 hex digits"]) : windowProblems(windowOf(req.url, now()));
|
|
140
|
+
return problems.length === 0 ? false : reply(res, 400, { problems });
|
|
141
|
+
};
|
|
142
|
+
return handler;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* This function gives the API to the service of the entry: an HTTP server with the OTLP/HTTP receiver and the
|
|
146
|
+
* queries. The API is a component. It does not start the server, and it does not use `run()`.
|
|
147
|
+
*/
|
|
148
|
+
export const attachApi = (svc, options) => {
|
|
149
|
+
const now = options.now ?? Date.now;
|
|
150
|
+
const store = options.store;
|
|
151
|
+
// The transport has no defaults: the idle close, the sweep of idle connections and the Retry-After of each 503.
|
|
152
|
+
const http = httpTransport(createServer(), { server_idle_close: s(65), server_idle_sweep_interval: s(1), server_retry_after: s(1) }, { listen: { port: options.port } });
|
|
153
|
+
http.mount(receiver(store));
|
|
154
|
+
http.mount(queryCheck(now));
|
|
155
|
+
// Each query goes through the service. Thus the drain waits for it, and the shutdown can cut it.
|
|
156
|
+
http.mount(handle("api", "GET /api/slowest", (req) => slowest(store().db, windowOf(req.url, now()))));
|
|
157
|
+
http.mount(handle("api", "GET /api/errors", (req) => errors(store().db, windowOf(req.url, now()))));
|
|
158
|
+
http.mount(handle("api", "GET /api/services", (req) => services(store().db, windowOf(req.url, now()))));
|
|
159
|
+
http.mount(handle("api", "GET /api/trace", (req) => trace(store().db, traceIdOf(req.url))));
|
|
160
|
+
http.mount(handle("api", "GET /api/stats", () => {
|
|
161
|
+
const opened = store();
|
|
162
|
+
return { sizes: opened.sizes(), fileBytes: opened.fileBytes(), rules: opened.rules };
|
|
163
|
+
}));
|
|
164
|
+
const api = svc.controller("api").requires("store");
|
|
165
|
+
for (const route of QUERY_ROUTES)
|
|
166
|
+
api.route(route, { idempotent: true });
|
|
167
|
+
return svc.server("http", http.knobs, http);
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM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OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Profile, ServiceBuilder } from "@mark1russell7/service";
|
|
2
|
+
import type { RetentionRules } from "./retention.ts";
|
|
3
|
+
export { attachApi, receiver, windowOf, MAX_BODY_BYTES, QUERY_ROUTES, type ApiOptions } from "./api.ts";
|
|
4
|
+
export * from "./otlp.ts";
|
|
5
|
+
export * from "./query.ts";
|
|
6
|
+
export * from "./retention.ts";
|
|
7
|
+
export * from "./store.ts";
|
|
8
|
+
/**
|
|
9
|
+
* These are the profiles of the shutdown, by name. `local` is for the computer of a developer.
|
|
10
|
+
* `pod` is for a pod of Kubernetes with a grace of 30 s and no preStop hook. Make `grace` equal to
|
|
11
|
+
* the `terminationGracePeriodSeconds` of the pod.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PROFILES: Readonly<Record<string, Profile>>;
|
|
14
|
+
/**
|
|
15
|
+
* This function tells if an OTLP endpoint is the receiver of this sink. A sink that exports its own spans to itself
|
|
16
|
+
* makes new spans at each export, without an end.
|
|
17
|
+
*/
|
|
18
|
+
export declare const isOwnEndpoint: (endpoint: string | undefined, port: number) => boolean;
|
|
19
|
+
/** The most deletes of one iteration of the retention worker. Each delete is one transaction of at most 5000 rows. */
|
|
20
|
+
export declare const PRUNE_BATCHES = 20;
|
|
21
|
+
/** These are the options of the service. */
|
|
22
|
+
export interface Options {
|
|
23
|
+
/** This number is the port of the API. */
|
|
24
|
+
readonly port: number;
|
|
25
|
+
/** This number is the port of the probes: `/startup`, `/readiness`, `/liveness` and `/report`. */
|
|
26
|
+
readonly probePort: number;
|
|
27
|
+
/** This profile gives the phases of the shutdown and the effect of a second signal. */
|
|
28
|
+
readonly profile: Profile;
|
|
29
|
+
/** This path is the SQLite file of the store, or `:memory:`. */
|
|
30
|
+
readonly path: string;
|
|
31
|
+
/** These rules give the age and the size of each signal. The default is `DEFAULT_RETENTION`. */
|
|
32
|
+
readonly rules?: RetentionRules | undefined;
|
|
33
|
+
/** This time is the sleep of the retention worker between two prunes, in seconds. The default is 60. */
|
|
34
|
+
readonly pruneEverySeconds?: number | undefined;
|
|
35
|
+
/** This function gives the time in milliseconds since the epoch. The default is `Date.now`. */
|
|
36
|
+
readonly now?: (() => number) | undefined;
|
|
37
|
+
/** This function gets each failure of a prune. The default does nothing: the next prune tries again after its backoff. */
|
|
38
|
+
readonly onPruneError?: ((error: unknown, failures: number) => void) | undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This function declares the one service of the process. It starts nothing. `describe()` gives the
|
|
42
|
+
* declaration as data, and `lint()` examines it. Only the entry (`main.ts`) uses `run()`.
|
|
43
|
+
* The store is a dependency: it opens before the servers start, and it closes after they stop.
|
|
44
|
+
*/
|
|
45
|
+
export declare const declare: (options: Options) => ServiceBuilder;
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACxG,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAK3B;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,GAAG,SAAS,EAAE,MAAM,MAAM,KAAG,OAW1E,CAAC;AAEF,sHAAsH;AACtH,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,4CAA4C;AAC5C,MAAM,WAAW,OAAO;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uFAAuF;IACvF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gGAAgG;IAChG,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAC5C,wGAAwG;IACxG,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,+FAA+F;IAC/F,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;IAC1C,0HAA0H;IAC1H,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAClF;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,KAAG,cA6C1C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { kubernetes, localDev, service, workerLoop } from "@mark1russell7/service";
|
|
2
|
+
import { probeServer } from "@mark1russell7/service/http";
|
|
3
|
+
import { attachApi } from "./api.js";
|
|
4
|
+
import { openStore } from "./store.js";
|
|
5
|
+
export { attachApi, receiver, windowOf, MAX_BODY_BYTES, QUERY_ROUTES } from "./api.js";
|
|
6
|
+
export * from "./otlp.js";
|
|
7
|
+
export * from "./query.js";
|
|
8
|
+
export * from "./retention.js";
|
|
9
|
+
export * from "./store.js";
|
|
10
|
+
const s = (value) => ({ value, unit: "s" });
|
|
11
|
+
const count = (value) => ({ value, unit: "count" });
|
|
12
|
+
/**
|
|
13
|
+
* These are the profiles of the shutdown, by name. `local` is for the computer of a developer.
|
|
14
|
+
* `pod` is for a pod of Kubernetes with a grace of 30 s and no preStop hook. Make `grace` equal to
|
|
15
|
+
* the `terminationGracePeriodSeconds` of the pod.
|
|
16
|
+
*/
|
|
17
|
+
export const PROFILES = {
|
|
18
|
+
local: localDev,
|
|
19
|
+
pod: kubernetes({ grace: s(30), preStop: s(0) }),
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* This function tells if an OTLP endpoint is the receiver of this sink. A sink that exports its own spans to itself
|
|
23
|
+
* makes new spans at each export, without an end.
|
|
24
|
+
*/
|
|
25
|
+
export const isOwnEndpoint = (endpoint, port) => {
|
|
26
|
+
if (endpoint === undefined || endpoint === "")
|
|
27
|
+
return false;
|
|
28
|
+
let url;
|
|
29
|
+
try {
|
|
30
|
+
url = new URL(endpoint);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const local = ["localhost", "127.0.0.1", "[::1]", "0.0.0.0"].includes(url.hostname);
|
|
36
|
+
const target = url.port === "" ? (url.protocol === "https:" ? 443 : 80) : Number(url.port);
|
|
37
|
+
return local && target === port;
|
|
38
|
+
};
|
|
39
|
+
/** The most deletes of one iteration of the retention worker. Each delete is one transaction of at most 5000 rows. */
|
|
40
|
+
export const PRUNE_BATCHES = 20;
|
|
41
|
+
/**
|
|
42
|
+
* This function declares the one service of the process. It starts nothing. `describe()` gives the
|
|
43
|
+
* declaration as data, and `lint()` examines it. Only the entry (`main.ts`) uses `run()`.
|
|
44
|
+
* The store is a dependency: it opens before the servers start, and it closes after they stop.
|
|
45
|
+
*/
|
|
46
|
+
export const declare = (options) => {
|
|
47
|
+
const now = options.now ?? Date.now;
|
|
48
|
+
let opened;
|
|
49
|
+
const store = () => {
|
|
50
|
+
if (opened === undefined)
|
|
51
|
+
throw new Error("the store is not open");
|
|
52
|
+
return opened;
|
|
53
|
+
};
|
|
54
|
+
// The prune of the store, on a loop. A throw is a failure, and the loop waits its backoff. Each iteration does at most
|
|
55
|
+
// PRUNE_BATCHES deletes, and gives "more" when the prune is not done. Thus the intake goes on between two parts, and
|
|
56
|
+
// each part ends in its bound, before the cap of the drain of each profile.
|
|
57
|
+
const retention = workerLoop({
|
|
58
|
+
worker_sleep: s(options.pruneEverySeconds ?? 60),
|
|
59
|
+
unit_processing_time: s(3),
|
|
60
|
+
retry_base: s(5),
|
|
61
|
+
retry_cap: s(300),
|
|
62
|
+
close_bound: s(0.5),
|
|
63
|
+
concurrency: count(1),
|
|
64
|
+
}, { iteration: () => (store().prune(now(), PRUNE_BATCHES).done ? undefined : "more"), onError: options.onPruneError });
|
|
65
|
+
const svc = service("otel-sink").dependency("store", { system: null, knobs: {}, operations: {} }, {
|
|
66
|
+
connect: () => {
|
|
67
|
+
opened = openStore(options.path, { rules: options.rules });
|
|
68
|
+
},
|
|
69
|
+
close: () => {
|
|
70
|
+
opened?.close();
|
|
71
|
+
opened = undefined;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return (attachApi(svc, { port: options.port, store, now })
|
|
75
|
+
.worker("retention", retention.knobs, retention)
|
|
76
|
+
// The probes have a port of their own. Thus they answer through the whole shutdown.
|
|
77
|
+
.healthServer(probeServer({ port: options.probePort, server_retry_after: s(1) }))
|
|
78
|
+
// The policies apply to the checks of the service. Add a check with `check(check, run)`.
|
|
79
|
+
.readiness({ type: "debounce", interval: s(5), failAfter: 3, recoverAfter: 1 })
|
|
80
|
+
.liveness({ type: "window", failAfter: s(45) })
|
|
81
|
+
.startup(s(30))
|
|
82
|
+
.profile(options.profile));
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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EAAE,CAAC,CAAC;SACd,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAC5B,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* This file is the entry of the process, and the only file that uses `run()`. The lifecycle owns the
|
|
4
|
+
* signals of the process. After SIGTERM or Ctrl-C, the service stops in its phases, and the process
|
|
5
|
+
* exits with 0 or 1.
|
|
6
|
+
*
|
|
7
|
+
* The environment gives `PORT` (4318), `PROBE_PORT` (9090), `SERVICE_PROFILE` (`local`) and `SINK_DB`
|
|
8
|
+
* (`otel-sink.db` in the home folder). The value in parentheses is the value without the variable.
|
|
9
|
+
*
|
|
10
|
+
* The run starts the context of otel-ts, so each log and each span of a request has its context. With a value in
|
|
11
|
+
* `OTEL_EXPORTER_OTLP_ENDPOINT`, the run also exports the spans.
|
|
12
|
+
*/
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { PROFILES, declare, isOwnEndpoint } from "./index.js";
|
|
16
|
+
/** This function gives a port from the environment, or the fallback when the variable is not set. */
|
|
17
|
+
const port = (name, fallback) => {
|
|
18
|
+
const text = process.env[name];
|
|
19
|
+
const value = text === undefined ? fallback : Number(text);
|
|
20
|
+
if (!Number.isInteger(value) || value < 0 || value > 65535)
|
|
21
|
+
throw new Error(`${name} is not a port: ${text}`);
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
const name = process.env["SERVICE_PROFILE"] ?? "local";
|
|
25
|
+
const profile = PROFILES[name];
|
|
26
|
+
if (profile === undefined)
|
|
27
|
+
throw new Error(`SERVICE_PROFILE is "${name}". The profiles are: ${Object.keys(PROFILES).join(", ")}.`);
|
|
28
|
+
const path = process.env["SINK_DB"] ?? join(homedir(), "otel-sink.db");
|
|
29
|
+
const api = port("PORT", 4318);
|
|
30
|
+
for (const name of ["OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"])
|
|
31
|
+
if (isOwnEndpoint(process.env[name], api))
|
|
32
|
+
throw new Error(`${name} is the receiver of this sink. The sink must not export its own telemetry to itself.`);
|
|
33
|
+
await declare({ port: api, probePort: port("PROBE_PORT", 9090), profile, path }).run();
|
|
34
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9D,qGAAqG;AACrG,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAU,EAAE;IACtD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mBAAmB,IAAI,EAAE,CAAC,CAAC;IAC9G,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAAC;AACvD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC/B,IAAI,OAAO,KAAK,SAAS;IAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,wBAAwB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEnI,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC,CAAC;AAEvE,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC/B,KAAK,MAAM,IAAI,IAAI,CAAC,6BAA6B,EAAE,oCAAoC,EAAE,kCAAkC,EAAE,qCAAqC,CAAC;IACjK,IAAI,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,sFAAsF,CAAC,CAAC;AAE5J,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC"}
|
package/dist/otlp.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rows of an OTLP/HTTP JSON export: each span, log record and metric point as one row of the store. The
|
|
3
|
+
* functions read only the parts of OTLP that the store keeps. They make no request and open no file.
|
|
4
|
+
*
|
|
5
|
+
* OTLP JSON gives the ids of a trace and a span in hex, and each time in nanoseconds as a string. A time of today
|
|
6
|
+
* is past 2^53, so each time stays a `bigint`.
|
|
7
|
+
*/
|
|
8
|
+
/** A value of an attribute, in the JSON of OTLP */
|
|
9
|
+
export interface AnyValue {
|
|
10
|
+
readonly stringValue?: string;
|
|
11
|
+
readonly boolValue?: boolean;
|
|
12
|
+
readonly intValue?: string | number;
|
|
13
|
+
readonly doubleValue?: number;
|
|
14
|
+
readonly arrayValue?: {
|
|
15
|
+
readonly values?: readonly AnyValue[];
|
|
16
|
+
};
|
|
17
|
+
readonly kvlistValue?: {
|
|
18
|
+
readonly values?: readonly KeyValue[];
|
|
19
|
+
};
|
|
20
|
+
readonly bytesValue?: string;
|
|
21
|
+
}
|
|
22
|
+
/** An attribute, in the JSON of OTLP */
|
|
23
|
+
export interface KeyValue {
|
|
24
|
+
readonly key: string;
|
|
25
|
+
readonly value?: AnyValue;
|
|
26
|
+
}
|
|
27
|
+
/** A resource, in the JSON of OTLP */
|
|
28
|
+
export interface OtlpResource {
|
|
29
|
+
readonly attributes?: readonly KeyValue[];
|
|
30
|
+
}
|
|
31
|
+
/** A time in nanoseconds since the epoch, as OTLP JSON gives it */
|
|
32
|
+
export type Nanos = string | number | undefined;
|
|
33
|
+
/** A span, in the JSON of OTLP */
|
|
34
|
+
export interface OtlpSpan {
|
|
35
|
+
readonly traceId: string;
|
|
36
|
+
readonly spanId: string;
|
|
37
|
+
readonly parentSpanId?: string;
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly kind?: number;
|
|
40
|
+
readonly startTimeUnixNano?: Nanos;
|
|
41
|
+
readonly endTimeUnixNano?: Nanos;
|
|
42
|
+
readonly attributes?: readonly KeyValue[];
|
|
43
|
+
readonly status?: {
|
|
44
|
+
readonly code?: number;
|
|
45
|
+
readonly message?: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** A log record, in the JSON of OTLP */
|
|
49
|
+
export interface OtlpLogRecord {
|
|
50
|
+
readonly timeUnixNano?: Nanos;
|
|
51
|
+
readonly observedTimeUnixNano?: Nanos;
|
|
52
|
+
readonly severityNumber?: number;
|
|
53
|
+
readonly body?: AnyValue;
|
|
54
|
+
readonly traceId?: string;
|
|
55
|
+
readonly spanId?: string;
|
|
56
|
+
readonly attributes?: readonly KeyValue[];
|
|
57
|
+
}
|
|
58
|
+
/** A point of a sum or a gauge, in the JSON of OTLP */
|
|
59
|
+
export interface OtlpNumberPoint {
|
|
60
|
+
readonly timeUnixNano?: Nanos;
|
|
61
|
+
readonly attributes?: readonly KeyValue[];
|
|
62
|
+
readonly asDouble?: number;
|
|
63
|
+
readonly asInt?: string | number;
|
|
64
|
+
}
|
|
65
|
+
/** A point of a histogram, in the JSON of OTLP */
|
|
66
|
+
export interface OtlpHistogramPoint {
|
|
67
|
+
readonly timeUnixNano?: Nanos;
|
|
68
|
+
readonly attributes?: readonly KeyValue[];
|
|
69
|
+
readonly count?: string | number;
|
|
70
|
+
readonly sum?: number;
|
|
71
|
+
readonly explicitBounds?: readonly number[];
|
|
72
|
+
readonly bucketCounts?: readonly (string | number)[];
|
|
73
|
+
}
|
|
74
|
+
/** A metric, in the JSON of OTLP. The store keeps sums, gauges and histograms. */
|
|
75
|
+
export interface OtlpMetric {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly sum?: {
|
|
78
|
+
readonly dataPoints?: readonly OtlpNumberPoint[];
|
|
79
|
+
};
|
|
80
|
+
readonly gauge?: {
|
|
81
|
+
readonly dataPoints?: readonly OtlpNumberPoint[];
|
|
82
|
+
};
|
|
83
|
+
readonly histogram?: {
|
|
84
|
+
readonly dataPoints?: readonly OtlpHistogramPoint[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** The body of an export of traces, in the JSON of OTLP */
|
|
88
|
+
export interface TracesExport {
|
|
89
|
+
readonly resourceSpans?: readonly {
|
|
90
|
+
readonly resource?: OtlpResource;
|
|
91
|
+
readonly scopeSpans?: readonly {
|
|
92
|
+
readonly spans?: readonly OtlpSpan[];
|
|
93
|
+
}[];
|
|
94
|
+
}[];
|
|
95
|
+
}
|
|
96
|
+
/** The body of an export of logs, in the JSON of OTLP */
|
|
97
|
+
export interface LogsExport {
|
|
98
|
+
readonly resourceLogs?: readonly {
|
|
99
|
+
readonly resource?: OtlpResource;
|
|
100
|
+
readonly scopeLogs?: readonly {
|
|
101
|
+
readonly logRecords?: readonly OtlpLogRecord[];
|
|
102
|
+
}[];
|
|
103
|
+
}[];
|
|
104
|
+
}
|
|
105
|
+
/** The body of an export of metrics, in the JSON of OTLP */
|
|
106
|
+
export interface MetricsExport {
|
|
107
|
+
readonly resourceMetrics?: readonly {
|
|
108
|
+
readonly resource?: OtlpResource;
|
|
109
|
+
readonly scopeMetrics?: readonly {
|
|
110
|
+
readonly metrics?: readonly OtlpMetric[];
|
|
111
|
+
}[];
|
|
112
|
+
}[];
|
|
113
|
+
}
|
|
114
|
+
/** The value of an attribute in the store */
|
|
115
|
+
export type Value = string | number | boolean | null | readonly Value[] | {
|
|
116
|
+
readonly [key: string]: Value;
|
|
117
|
+
};
|
|
118
|
+
/** A span as a row of the store */
|
|
119
|
+
export interface SpanRow {
|
|
120
|
+
readonly traceId: string;
|
|
121
|
+
readonly spanId: string;
|
|
122
|
+
readonly parentId: string | null;
|
|
123
|
+
readonly service: string;
|
|
124
|
+
readonly name: string;
|
|
125
|
+
/** The kind of OTLP: 1 internal, 2 server, 3 client, 4 producer, 5 consumer, or null when it is not given */
|
|
126
|
+
readonly kind: number | null;
|
|
127
|
+
readonly startNs: bigint;
|
|
128
|
+
readonly endNs: bigint;
|
|
129
|
+
/** The status code of OTLP: 0 unset, 1 ok, 2 error */
|
|
130
|
+
readonly status: number;
|
|
131
|
+
/** The attributes, as JSON text */
|
|
132
|
+
readonly attributes: string;
|
|
133
|
+
}
|
|
134
|
+
/** A log record as a row of the store */
|
|
135
|
+
export interface LogRow {
|
|
136
|
+
readonly timeNs: bigint;
|
|
137
|
+
readonly service: string;
|
|
138
|
+
readonly severity: number | null;
|
|
139
|
+
readonly body: string | null;
|
|
140
|
+
readonly traceId: string | null;
|
|
141
|
+
readonly spanId: string | null;
|
|
142
|
+
readonly attributes: string;
|
|
143
|
+
}
|
|
144
|
+
/** A metric point as a row of the store */
|
|
145
|
+
export interface PointRow {
|
|
146
|
+
readonly timeNs: bigint;
|
|
147
|
+
readonly service: string;
|
|
148
|
+
readonly metric: string;
|
|
149
|
+
readonly attributes: string;
|
|
150
|
+
/** The value of a sum or a gauge, or the sum of a histogram */
|
|
151
|
+
readonly value: number | null;
|
|
152
|
+
/** The count and the buckets of a histogram, as JSON text, or null for a sum or a gauge */
|
|
153
|
+
readonly histogram: string | null;
|
|
154
|
+
}
|
|
155
|
+
/** The service name of a resource without `service.name`, as in the SDK of OpenTelemetry */
|
|
156
|
+
export declare const UNKNOWN_SERVICE = "unknown_service";
|
|
157
|
+
/** This error tells that a body is not an export of OTLP JSON. The receiver answers it with 400. */
|
|
158
|
+
export declare class OtlpShapeError extends Error {
|
|
159
|
+
readonly name = "OtlpShapeError";
|
|
160
|
+
}
|
|
161
|
+
/** This function gives the value of an attribute of OTLP JSON. */
|
|
162
|
+
export declare const valueOf: (value: AnyValue | undefined) => Value;
|
|
163
|
+
/** This function gives the attributes of OTLP JSON as one object. */
|
|
164
|
+
export declare const attributesOf: (list?: readonly KeyValue[]) => {
|
|
165
|
+
readonly [key: string]: Value;
|
|
166
|
+
};
|
|
167
|
+
/** This function gives a row for each span of an export of traces. */
|
|
168
|
+
export declare const spanRows: (body: TracesExport) => SpanRow[];
|
|
169
|
+
/** This function gives a row for each log record of an export of logs. A record without a time gets its observed time. */
|
|
170
|
+
export declare const logRows: (body: LogsExport) => LogRow[];
|
|
171
|
+
/** This function gives a row for each point of a sum, a gauge or a histogram of an export of metrics. */
|
|
172
|
+
export declare const pointRows: (body: MetricsExport) => PointRow[];
|
|
173
|
+
//# sourceMappingURL=otlp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlp.d.ts","sourceRoot":"","sources":["../src/otlp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mDAAmD;AACnD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,WAAW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