@procedures/sink 0.0.0-stage → 0.68.18
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 +13 -0
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/api.d.ts +95 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +170 -0
- package/dist/api.js.map +1 -0
- package/dist/call.d.ts +42 -0
- package/dist/call.d.ts.map +1 -0
- package/dist/call.js +44 -0
- package/dist/call.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +32 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +97 -0
- package/dist/module.js.map +1 -0
- package/dist/procedures/sink/errors.d.ts +8 -0
- package/dist/procedures/sink/errors.d.ts.map +1 -0
- package/dist/procedures/sink/errors.js +9 -0
- package/dist/procedures/sink/errors.js.map +1 -0
- package/dist/procedures/sink/index.d.ts +6 -0
- package/dist/procedures/sink/index.d.ts.map +1 -0
- package/dist/procedures/sink/index.js +6 -0
- package/dist/procedures/sink/index.js.map +1 -0
- package/dist/procedures/sink/services.d.ts +8 -0
- package/dist/procedures/sink/services.d.ts.map +1 -0
- package/dist/procedures/sink/services.js +9 -0
- package/dist/procedures/sink/services.js.map +1 -0
- package/dist/procedures/sink/slowest.d.ts +8 -0
- package/dist/procedures/sink/slowest.d.ts.map +1 -0
- package/dist/procedures/sink/slowest.js +9 -0
- package/dist/procedures/sink/slowest.js.map +1 -0
- package/dist/procedures/sink/stats.d.ts +8 -0
- package/dist/procedures/sink/stats.d.ts.map +1 -0
- package/dist/procedures/sink/stats.js +9 -0
- package/dist/procedures/sink/stats.js.map +1 -0
- package/dist/procedures/sink/trace.d.ts +8 -0
- package/dist/procedures/sink/trace.d.ts.map +1 -0
- package/dist/procedures/sink/trace.js +9 -0
- package/dist/procedures/sink/trace.js.map +1 -0
- package/dist/register.d.ts +6 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +8 -0
- package/dist/register.js.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +98 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -3
- package/src/api.ts +217 -0
- package/src/call.ts +69 -0
- package/src/index.ts +6 -0
- package/src/module.ts +150 -0
- package/src/procedures/sink/errors.ts +11 -0
- package/src/procedures/sink/index.ts +5 -0
- package/src/procedures/sink/services.ts +11 -0
- package/src/procedures/sink/slowest.ts +11 -0
- package/src/procedures/sink/stats.ts +11 -0
- package/src/procedures/sink/trace.ts +11 -0
- package/src/register.ts +10 -0
- package/src/types.ts +234 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The types and the Zod schemas of the procedures of this package: the inputs of the five queries, and the answers
|
|
3
|
+
* of the sink. Each time in an answer is in milliseconds since the epoch, and each duration is in milliseconds.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as z from "zod";
|
|
7
|
+
|
|
8
|
+
/** The base URL of the sink on this computer */
|
|
9
|
+
export const DEFAULT_SINK_URL = "http://127.0.0.1:4328";
|
|
10
|
+
|
|
11
|
+
/** The most rows of one answer of the sink */
|
|
12
|
+
export const MAX_LIMIT = 1000;
|
|
13
|
+
|
|
14
|
+
/** The most time of one query, in milliseconds */
|
|
15
|
+
export const MAX_TIMEOUT_MS = 120_000;
|
|
16
|
+
|
|
17
|
+
/** The time limit of a query without `timeoutMs`, in milliseconds */
|
|
18
|
+
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
19
|
+
|
|
20
|
+
/** The pattern of a trace id: 32 hex digits, in lowercase or in uppercase */
|
|
21
|
+
export const TRACE_ID_INPUT: RegExp = /^[0-9a-fA-F]{32}$/;
|
|
22
|
+
|
|
23
|
+
/** The attributes of a span or of a log record. Each value is a JSON value. */
|
|
24
|
+
export type Attributes = { readonly [key: string]: unknown };
|
|
25
|
+
|
|
26
|
+
/** A span in an answer of the sink */
|
|
27
|
+
export interface SpanView {
|
|
28
|
+
readonly traceId: string;
|
|
29
|
+
readonly spanId: string;
|
|
30
|
+
readonly parentId: string | null;
|
|
31
|
+
readonly service: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly kind: number | null;
|
|
34
|
+
readonly startMs: number;
|
|
35
|
+
readonly durationMs: number;
|
|
36
|
+
/** The status code of OTLP: 0 is unset, 1 is ok and 2 is error. */
|
|
37
|
+
readonly status: number;
|
|
38
|
+
readonly attributes: Attributes;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A log record in an answer of the sink */
|
|
42
|
+
export interface LogView {
|
|
43
|
+
readonly timeMs: number;
|
|
44
|
+
readonly service: string;
|
|
45
|
+
/** The severity number of OTLP. An error has 17 or more. */
|
|
46
|
+
readonly severity: number | null;
|
|
47
|
+
readonly body: string | null;
|
|
48
|
+
readonly traceId: string | null;
|
|
49
|
+
readonly spanId: string | null;
|
|
50
|
+
readonly attributes: Attributes;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The counts of the spans of one service */
|
|
54
|
+
export interface ServiceView {
|
|
55
|
+
readonly service: string;
|
|
56
|
+
readonly spans: number;
|
|
57
|
+
readonly failed: number;
|
|
58
|
+
/** The fraction of the spans with the status error */
|
|
59
|
+
readonly errorRate: number;
|
|
60
|
+
readonly slowestMs: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The rows and the bytes of one signal in the store */
|
|
64
|
+
export interface SignalSize {
|
|
65
|
+
readonly rows: number;
|
|
66
|
+
readonly bytes: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The retention rule of one signal: the oldest age and the most bytes */
|
|
70
|
+
export interface RetentionRule {
|
|
71
|
+
readonly maxAgeMs: number;
|
|
72
|
+
readonly maxBytes: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The three signals of the store */
|
|
76
|
+
export type Signal = "spans" | "logs" | "points";
|
|
77
|
+
|
|
78
|
+
/** The output of `sink.slowest`: the slowest spans that start in the window, the slowest first */
|
|
79
|
+
export interface SinkSlowestOutput {
|
|
80
|
+
readonly spans: readonly SpanView[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The output of `sink.errors`: the spans with the status error and the error logs, the newest first */
|
|
84
|
+
export interface SinkErrorsOutput {
|
|
85
|
+
readonly spans: readonly SpanView[];
|
|
86
|
+
readonly logs: readonly LogView[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The output of `sink.services`: the counts of each service, the most failed spans first */
|
|
90
|
+
export interface SinkServicesOutput {
|
|
91
|
+
readonly services: readonly ServiceView[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The output of `sink.trace`: the spans and the logs of one trace, in the order of their times */
|
|
95
|
+
export interface SinkTraceOutput {
|
|
96
|
+
readonly spans: readonly SpanView[];
|
|
97
|
+
readonly logs: readonly LogView[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The output of `sink.stats`: the size of each signal, the size of the file and the retention rules */
|
|
101
|
+
export interface SinkStatsOutput {
|
|
102
|
+
readonly sizes: { readonly [signal in Signal]: SignalSize };
|
|
103
|
+
readonly fileBytes: number;
|
|
104
|
+
readonly rules: { readonly [signal in Signal]: RetentionRule };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The input of `sink.slowest`, `sink.errors` and `sink.services`: a window of the store */
|
|
108
|
+
export interface SinkWindowInput {
|
|
109
|
+
readonly baseUrl?: string | undefined;
|
|
110
|
+
/** The start of the window, in milliseconds since the epoch. The sink uses the last hour without it. */
|
|
111
|
+
readonly since?: number | undefined;
|
|
112
|
+
/** The most rows of the answer. The sink uses 50 without it. */
|
|
113
|
+
readonly limit?: number | undefined;
|
|
114
|
+
/** Only the rows of this service */
|
|
115
|
+
readonly service?: string | undefined;
|
|
116
|
+
readonly timeoutMs: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The input of `sink.trace` */
|
|
120
|
+
export interface SinkTraceInput {
|
|
121
|
+
readonly baseUrl?: string | undefined;
|
|
122
|
+
/** The trace id: 32 hex digits */
|
|
123
|
+
readonly id: string;
|
|
124
|
+
readonly timeoutMs: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The input of `sink.stats` */
|
|
128
|
+
export interface SinkStatsInput {
|
|
129
|
+
readonly baseUrl?: string | undefined;
|
|
130
|
+
readonly timeoutMs: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type SinkSlowestInput = SinkWindowInput;
|
|
134
|
+
export type SinkErrorsInput = SinkWindowInput;
|
|
135
|
+
export type SinkServicesInput = SinkWindowInput;
|
|
136
|
+
|
|
137
|
+
/** The input of a procedure before the defaults */
|
|
138
|
+
type Given<T extends { timeoutMs: number }> = Omit<T, "timeoutMs"> & { readonly timeoutMs?: number | undefined };
|
|
139
|
+
|
|
140
|
+
const baseUrl = z
|
|
141
|
+
.url({ protocol: /^https?$/ })
|
|
142
|
+
.optional()
|
|
143
|
+
.describe(`The base URL of the sink, http: or https: (default: ${DEFAULT_SINK_URL}). The host must allow its host and port.`);
|
|
144
|
+
|
|
145
|
+
const timeoutMs = z
|
|
146
|
+
.number()
|
|
147
|
+
.int()
|
|
148
|
+
.positive()
|
|
149
|
+
.max(MAX_TIMEOUT_MS)
|
|
150
|
+
.default(DEFAULT_TIMEOUT_MS)
|
|
151
|
+
.describe(`The time limit, in milliseconds (default: ${DEFAULT_TIMEOUT_MS})`);
|
|
152
|
+
|
|
153
|
+
const windowShape = {
|
|
154
|
+
baseUrl,
|
|
155
|
+
since: z.number().int().min(0).optional().describe("The start of the window, in milliseconds since the epoch (default: one hour ago)"),
|
|
156
|
+
limit: z.number().int().min(1).max(MAX_LIMIT).optional().describe(`The most rows of the answer, from 1 to ${MAX_LIMIT} (default: 50)`),
|
|
157
|
+
service: z.string().min(1).optional().describe("Only the rows of this service (default: each service)"),
|
|
158
|
+
timeoutMs,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const SinkSlowestInputSchema: z.ZodType<SinkSlowestInput, Given<SinkSlowestInput>> = z.object(windowShape);
|
|
162
|
+
export const SinkErrorsInputSchema: z.ZodType<SinkErrorsInput, Given<SinkErrorsInput>> = z.object(windowShape);
|
|
163
|
+
export const SinkServicesInputSchema: z.ZodType<SinkServicesInput, Given<SinkServicesInput>> = z.object(windowShape);
|
|
164
|
+
|
|
165
|
+
export const SinkTraceInputSchema: z.ZodType<SinkTraceInput, Given<SinkTraceInput>> = z.object({
|
|
166
|
+
baseUrl,
|
|
167
|
+
id: z.string().regex(TRACE_ID_INPUT, "The id must be a trace id of 32 hex digits").describe("The trace id: 32 hex digits"),
|
|
168
|
+
timeoutMs,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
export const SinkStatsInputSchema: z.ZodType<SinkStatsInput, Given<SinkStatsInput>> = z.object({ baseUrl, timeoutMs });
|
|
172
|
+
|
|
173
|
+
const attributes = z.record(z.string(), z.unknown());
|
|
174
|
+
|
|
175
|
+
const span: z.ZodType<SpanView> = z.object({
|
|
176
|
+
traceId: z.string(),
|
|
177
|
+
spanId: z.string(),
|
|
178
|
+
parentId: z.string().nullable(),
|
|
179
|
+
service: z.string(),
|
|
180
|
+
name: z.string(),
|
|
181
|
+
kind: z.number().nullable(),
|
|
182
|
+
startMs: z.number(),
|
|
183
|
+
durationMs: z.number(),
|
|
184
|
+
status: z.number(),
|
|
185
|
+
attributes,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const log: z.ZodType<LogView> = z.object({
|
|
189
|
+
timeMs: z.number(),
|
|
190
|
+
service: z.string(),
|
|
191
|
+
severity: z.number().nullable(),
|
|
192
|
+
body: z.string().nullable(),
|
|
193
|
+
traceId: z.string().nullable(),
|
|
194
|
+
spanId: z.string().nullable(),
|
|
195
|
+
attributes,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const serviceView: z.ZodType<ServiceView> = z.object({
|
|
199
|
+
service: z.string(),
|
|
200
|
+
spans: z.number(),
|
|
201
|
+
failed: z.number(),
|
|
202
|
+
errorRate: z.number(),
|
|
203
|
+
slowestMs: z.number(),
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const signalSize = z.object({ rows: z.number(), bytes: z.number() });
|
|
207
|
+
const retentionRule = z.object({ maxAgeMs: z.number(), maxBytes: z.number() });
|
|
208
|
+
|
|
209
|
+
export const SpanViewSchema: z.ZodType<SpanView> = span;
|
|
210
|
+
export const LogViewSchema: z.ZodType<LogView> = log;
|
|
211
|
+
export const ServiceViewSchema: z.ZodType<ServiceView> = serviceView;
|
|
212
|
+
|
|
213
|
+
const spans = z.array(span);
|
|
214
|
+
const logs = z.array(log);
|
|
215
|
+
|
|
216
|
+
export const SinkSlowestOutputSchema: z.ZodType<SinkSlowestOutput> = z.object({
|
|
217
|
+
spans: spans.describe("The slowest spans of the window, the slowest first"),
|
|
218
|
+
});
|
|
219
|
+
export const SinkErrorsOutputSchema: z.ZodType<SinkErrorsOutput> = z.object({
|
|
220
|
+
spans: spans.describe("The failed spans of the window (status 2), the newest first"),
|
|
221
|
+
logs: logs.describe("The error logs of the window (severity 17 or more), the newest first"),
|
|
222
|
+
});
|
|
223
|
+
export const SinkServicesOutputSchema: z.ZodType<SinkServicesOutput> = z.object({
|
|
224
|
+
services: z.array(serviceView).describe("Each service of the window, with its span count, its failed spans, its error rate and its slowest span"),
|
|
225
|
+
});
|
|
226
|
+
export const SinkTraceOutputSchema: z.ZodType<SinkTraceOutput> = z.object({
|
|
227
|
+
spans: spans.describe("The spans of the trace, in the order of their start times"),
|
|
228
|
+
logs: logs.describe("The logs of the trace, in the order of their times"),
|
|
229
|
+
});
|
|
230
|
+
export const SinkStatsOutputSchema: z.ZodType<SinkStatsOutput> = z.object({
|
|
231
|
+
sizes: z.object({ spans: signalSize, logs: signalSize, points: signalSize }).describe("The rows and bytes of each signal: spans, logs and metric points"),
|
|
232
|
+
fileBytes: z.number().describe("The size of the database file of the sink, in bytes"),
|
|
233
|
+
rules: z.object({ spans: retentionRule, logs: retentionRule, points: retentionRule }).describe("The retention rule of each signal: the most age and the most bytes"),
|
|
234
|
+
});
|