-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
tracezApi.ts
96 lines (84 loc) · 3.16 KB
/
tracezApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import { fetchData } from "src/api";
import TakeTracingSnapshotRequest = cockroach.server.serverpb.TakeTracingSnapshotRequest;
export type ListTracingSnapshotsRequestMessage =
cockroach.server.serverpb.ListTracingSnapshotsRequest;
export type ListTracingSnapshotsResponseMessage =
cockroach.server.serverpb.ListTracingSnapshotsResponse;
export type TakeTracingSnapshotRequestMessage = TakeTracingSnapshotRequest;
export type TakeTracingSnapshotResponseMessage =
cockroach.server.serverpb.TakeTracingSnapshotResponse;
export type GetTracingSnapshotRequestMessage =
cockroach.server.serverpb.GetTracingSnapshotRequest;
export type GetTracingSnapshotResponseMessage =
cockroach.server.serverpb.GetTracingSnapshotResponse;
export type Span = cockroach.server.serverpb.ITracingSpan;
export type Snapshot = cockroach.server.serverpb.ITracingSnapshot;
export type GetTraceRequestMessage = cockroach.server.serverpb.GetTraceRequest;
export type GetTraceResponseMessage =
cockroach.server.serverpb.GetTraceResponse;
const API_PREFIX = "_admin/v1";
const proxyNonLocalNode = (path: string, nodeID: string): string => {
if (nodeID === "local") {
// While the server is clever enough to do the smart thing around proxying to node
// "local," it still queries gossip while doing it. We'd like to avoid a hard dependency
// on that to support malfunctioning clusters or nodes.
return path;
}
return path + `?remote_node_id=${nodeID}`;
};
export function listTracingSnapshots(
nodeID: string,
): Promise<ListTracingSnapshotsResponseMessage> {
return fetchData(
cockroach.server.serverpb.ListTracingSnapshotsResponse,
proxyNonLocalNode(`${API_PREFIX}/trace_snapshots`, nodeID),
null,
null,
);
}
export function takeTracingSnapshot(
nodeID: string,
): Promise<TakeTracingSnapshotResponseMessage> {
const req = new TakeTracingSnapshotRequest();
return fetchData(
cockroach.server.serverpb.TakeTracingSnapshotResponse,
proxyNonLocalNode(`${API_PREFIX}/trace_snapshots`, nodeID),
cockroach.server.serverpb.TakeTracingSnapshotRequest,
req as any,
);
}
export function getTracingSnapshot(req: {
nodeID: string;
snapshotID: number;
}): Promise<GetTracingSnapshotResponseMessage> {
return fetchData(
cockroach.server.serverpb.GetTracingSnapshotResponse,
proxyNonLocalNode(
`${API_PREFIX}/trace_snapshots/${req.snapshotID}`,
req.nodeID,
),
null,
null,
);
}
export function getTraceForSnapshot(req: {
nodeID: string;
req: GetTraceRequestMessage;
}): Promise<GetTraceResponseMessage> {
return fetchData(
cockroach.server.serverpb.GetTraceResponse,
proxyNonLocalNode(`${API_PREFIX}/traces`, req.nodeID),
cockroach.server.serverpb.GetTraceRequest,
req.req as any,
);
}