@databricks/sql 1.13.0 → 1.14.0
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/DBSQLClient.d.ts +8 -0
- package/dist/DBSQLClient.js +25 -0
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLSession.js +4 -0
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/contracts/IClientContext.d.ts +7 -0
- package/dist/contracts/IDBSQLClient.d.ts +6 -0
- package/dist/contracts/IDBSQLSession.d.ts +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/telemetry/CircuitBreaker.d.ts +73 -0
- package/dist/telemetry/CircuitBreaker.js +176 -0
- package/dist/telemetry/CircuitBreaker.js.map +1 -0
- package/dist/telemetry/DatabricksTelemetryExporter.d.ts +76 -0
- package/dist/telemetry/DatabricksTelemetryExporter.js +324 -0
- package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -0
- package/dist/telemetry/ExceptionClassifier.js +12 -0
- package/dist/telemetry/ExceptionClassifier.js.map +1 -1
- package/dist/telemetry/FeatureFlagCache.d.ts +61 -0
- package/dist/telemetry/FeatureFlagCache.js +208 -0
- package/dist/telemetry/FeatureFlagCache.js.map +1 -0
- package/dist/telemetry/MetricsAggregator.d.ts +72 -0
- package/dist/telemetry/MetricsAggregator.js +375 -0
- package/dist/telemetry/MetricsAggregator.js.map +1 -0
- package/dist/telemetry/TelemetryClient.d.ts +41 -0
- package/dist/telemetry/TelemetryClient.js +64 -0
- package/dist/telemetry/TelemetryClient.js.map +1 -0
- package/dist/telemetry/TelemetryClientProvider.d.ts +67 -0
- package/dist/telemetry/TelemetryClientProvider.js +148 -0
- package/dist/telemetry/TelemetryClientProvider.js.map +1 -0
- package/dist/telemetry/TelemetryEventEmitter.d.ts +93 -0
- package/dist/telemetry/TelemetryEventEmitter.js +172 -0
- package/dist/telemetry/TelemetryEventEmitter.js.map +1 -0
- package/dist/telemetry/telemetryUtils.d.ts +56 -0
- package/dist/telemetry/telemetryUtils.js +222 -0
- package/dist/telemetry/telemetryUtils.js.map +1 -0
- package/dist/telemetry/types.d.ts +37 -4
- package/dist/telemetry/types.js +15 -5
- package/dist/telemetry/types.js.map +1 -1
- package/dist/telemetry/urlUtils.d.ts +22 -0
- package/dist/telemetry/urlUtils.js +35 -0
- package/dist/telemetry/urlUtils.js.map +1 -0
- package/dist/utils/agentDetector.d.ts +20 -0
- package/dist/utils/agentDetector.js +39 -0
- package/dist/utils/agentDetector.js.map +1 -0
- package/dist/utils/buildUserAgentString.js +7 -1
- package/dist/utils/buildUserAgentString.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/queryTags.d.ts +12 -0
- package/dist/utils/queryTags.js +35 -0
- package/dist/utils/queryTags.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Databricks Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import IClientContext from '../contracts/IClientContext';
|
|
17
|
+
import { TelemetryEvent } from './types';
|
|
18
|
+
import DatabricksTelemetryExporter from './DatabricksTelemetryExporter';
|
|
19
|
+
/**
|
|
20
|
+
* Aggregates telemetry events by statement_id and manages batching/flushing.
|
|
21
|
+
*
|
|
22
|
+
* Overflow policy — when the pending buffer hits `maxPendingMetrics`, error
|
|
23
|
+
* metrics are preserved preferentially over connection/statement metrics.
|
|
24
|
+
* The first-failure error is usually the most valuable signal in post-mortem
|
|
25
|
+
* debugging; dropping it FIFO would defeat the purpose of capture.
|
|
26
|
+
*/
|
|
27
|
+
export default class MetricsAggregator {
|
|
28
|
+
private context;
|
|
29
|
+
private exporter;
|
|
30
|
+
private statementMetrics;
|
|
31
|
+
private pendingMetrics;
|
|
32
|
+
private flushTimer;
|
|
33
|
+
private closed;
|
|
34
|
+
private closing;
|
|
35
|
+
private batchSize;
|
|
36
|
+
private flushIntervalMs;
|
|
37
|
+
private maxPendingMetrics;
|
|
38
|
+
private maxErrorsPerStatement;
|
|
39
|
+
private statementTtlMs;
|
|
40
|
+
constructor(context: IClientContext, exporter: DatabricksTelemetryExporter);
|
|
41
|
+
processEvent(event: TelemetryEvent): void;
|
|
42
|
+
private processConnectionEvent;
|
|
43
|
+
private processErrorEvent;
|
|
44
|
+
private pushBoundedError;
|
|
45
|
+
private processStatementEvent;
|
|
46
|
+
private getOrCreateStatementDetails;
|
|
47
|
+
/**
|
|
48
|
+
* Drop entries older than `statementTtlMs`, emitting their buffered error
|
|
49
|
+
* events as standalone metrics first so the first-failure signal survives
|
|
50
|
+
* the eviction. Called from the periodic flush timer so idle clients
|
|
51
|
+
* don't leak orphan entries.
|
|
52
|
+
*/
|
|
53
|
+
private evictExpiredStatements;
|
|
54
|
+
completeStatement(statementId: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Append `metric` to the pending buffer, enforcing `maxPendingMetrics`.
|
|
57
|
+
*
|
|
58
|
+
* Overflow drops the oldest non-error entry (single `splice` — no new
|
|
59
|
+
* allocation). Under an all-error buffer it falls back to dropping the
|
|
60
|
+
* oldest entry at index 0.
|
|
61
|
+
*/
|
|
62
|
+
private addPendingMetric;
|
|
63
|
+
private findDropIndex;
|
|
64
|
+
/**
|
|
65
|
+
* Drain the pending buffer and return a promise that resolves when the
|
|
66
|
+
* exporter finishes with the drained batch. `close()` awaits this so
|
|
67
|
+
* `process.exit()` after `client.close()` doesn't truncate the POST.
|
|
68
|
+
*/
|
|
69
|
+
flush(resetTimer?: boolean): Promise<void>;
|
|
70
|
+
private startFlushTimer;
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Databricks Contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
|
|
19
|
+
const types_1 = require("./types");
|
|
20
|
+
/**
|
|
21
|
+
* Aggregates telemetry events by statement_id and manages batching/flushing.
|
|
22
|
+
*
|
|
23
|
+
* Overflow policy — when the pending buffer hits `maxPendingMetrics`, error
|
|
24
|
+
* metrics are preserved preferentially over connection/statement metrics.
|
|
25
|
+
* The first-failure error is usually the most valuable signal in post-mortem
|
|
26
|
+
* debugging; dropping it FIFO would defeat the purpose of capture.
|
|
27
|
+
*/
|
|
28
|
+
class MetricsAggregator {
|
|
29
|
+
constructor(context, exporter) {
|
|
30
|
+
var _a, _b, _c, _d, _e;
|
|
31
|
+
this.context = context;
|
|
32
|
+
this.exporter = exporter;
|
|
33
|
+
this.statementMetrics = new Map();
|
|
34
|
+
this.pendingMetrics = [];
|
|
35
|
+
this.flushTimer = null;
|
|
36
|
+
this.closed = false;
|
|
37
|
+
this.closing = false;
|
|
38
|
+
try {
|
|
39
|
+
const config = context.getConfig();
|
|
40
|
+
this.batchSize = (_a = config.telemetryBatchSize) !== null && _a !== void 0 ? _a : types_1.DEFAULT_TELEMETRY_CONFIG.batchSize;
|
|
41
|
+
this.flushIntervalMs = (_b = config.telemetryFlushIntervalMs) !== null && _b !== void 0 ? _b : types_1.DEFAULT_TELEMETRY_CONFIG.flushIntervalMs;
|
|
42
|
+
this.maxPendingMetrics = (_c = config.telemetryMaxPendingMetrics) !== null && _c !== void 0 ? _c : types_1.DEFAULT_TELEMETRY_CONFIG.maxPendingMetrics;
|
|
43
|
+
this.maxErrorsPerStatement =
|
|
44
|
+
(_d = config.telemetryMaxErrorsPerStatement) !== null && _d !== void 0 ? _d : types_1.DEFAULT_TELEMETRY_CONFIG.maxErrorsPerStatement;
|
|
45
|
+
this.statementTtlMs = (_e = config.telemetryStatementTtlMs) !== null && _e !== void 0 ? _e : types_1.DEFAULT_TELEMETRY_CONFIG.statementTtlMs;
|
|
46
|
+
this.startFlushTimer();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const logger = this.context.getLogger();
|
|
50
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `MetricsAggregator constructor error: ${error.message}`);
|
|
51
|
+
this.batchSize = types_1.DEFAULT_TELEMETRY_CONFIG.batchSize;
|
|
52
|
+
this.flushIntervalMs = types_1.DEFAULT_TELEMETRY_CONFIG.flushIntervalMs;
|
|
53
|
+
this.maxPendingMetrics = types_1.DEFAULT_TELEMETRY_CONFIG.maxPendingMetrics;
|
|
54
|
+
this.maxErrorsPerStatement = types_1.DEFAULT_TELEMETRY_CONFIG.maxErrorsPerStatement;
|
|
55
|
+
this.statementTtlMs = types_1.DEFAULT_TELEMETRY_CONFIG.statementTtlMs;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
processEvent(event) {
|
|
59
|
+
if (this.closed)
|
|
60
|
+
return;
|
|
61
|
+
const logger = this.context.getLogger();
|
|
62
|
+
try {
|
|
63
|
+
if (event.eventType === types_1.TelemetryEventType.CONNECTION_OPEN) {
|
|
64
|
+
this.processConnectionEvent(event);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (event.eventType === types_1.TelemetryEventType.ERROR) {
|
|
68
|
+
this.processErrorEvent(event);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (event.statementId) {
|
|
72
|
+
this.processStatementEvent(event);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `MetricsAggregator.processEvent error: ${error.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
processConnectionEvent(event) {
|
|
80
|
+
const metric = {
|
|
81
|
+
metricType: 'connection',
|
|
82
|
+
timestamp: event.timestamp,
|
|
83
|
+
sessionId: event.sessionId,
|
|
84
|
+
workspaceId: event.workspaceId,
|
|
85
|
+
driverConfig: event.driverConfig,
|
|
86
|
+
};
|
|
87
|
+
this.addPendingMetric(metric);
|
|
88
|
+
}
|
|
89
|
+
processErrorEvent(event) {
|
|
90
|
+
const logger = this.context.getLogger();
|
|
91
|
+
// `isTerminal` is carried on the event by the emitter (it knows the
|
|
92
|
+
// call site's taxonomy). If callers ever drop it we default to
|
|
93
|
+
// retryable — buffering by statement is the safer choice.
|
|
94
|
+
const isTerminal = event.isTerminal === true;
|
|
95
|
+
if (isTerminal) {
|
|
96
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, 'Terminal error detected - flushing immediately');
|
|
97
|
+
if (event.statementId && this.statementMetrics.has(event.statementId)) {
|
|
98
|
+
const details = this.statementMetrics.get(event.statementId);
|
|
99
|
+
this.pushBoundedError(details, event);
|
|
100
|
+
this.completeStatement(event.statementId);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const metric = {
|
|
104
|
+
metricType: 'error',
|
|
105
|
+
timestamp: event.timestamp,
|
|
106
|
+
sessionId: event.sessionId,
|
|
107
|
+
statementId: event.statementId,
|
|
108
|
+
workspaceId: event.workspaceId,
|
|
109
|
+
errorName: event.errorName,
|
|
110
|
+
errorMessage: event.errorMessage,
|
|
111
|
+
errorStack: event.errorStack,
|
|
112
|
+
};
|
|
113
|
+
this.addPendingMetric(metric);
|
|
114
|
+
}
|
|
115
|
+
// Fire-and-forget on the terminal-error path so customer code doesn't
|
|
116
|
+
// stall on telemetry HTTP. Do NOT reset the periodic flush timer:
|
|
117
|
+
// under burst failures that would keep the tail-drain timer from
|
|
118
|
+
// ever firing.
|
|
119
|
+
Promise.resolve(this.flush(false)).catch((err) => {
|
|
120
|
+
var _a;
|
|
121
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Terminal-error flush failed: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else if (event.statementId) {
|
|
125
|
+
const details = this.getOrCreateStatementDetails(event);
|
|
126
|
+
this.pushBoundedError(details, event);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
pushBoundedError(details, event) {
|
|
130
|
+
if (details.errors.length >= this.maxErrorsPerStatement) {
|
|
131
|
+
details.errors.shift();
|
|
132
|
+
}
|
|
133
|
+
details.errors.push(event);
|
|
134
|
+
}
|
|
135
|
+
processStatementEvent(event) {
|
|
136
|
+
var _a, _b, _c, _d;
|
|
137
|
+
const details = this.getOrCreateStatementDetails(event);
|
|
138
|
+
switch (event.eventType) {
|
|
139
|
+
case types_1.TelemetryEventType.STATEMENT_START:
|
|
140
|
+
details.operationType = event.operationType;
|
|
141
|
+
details.startTime = event.timestamp;
|
|
142
|
+
break;
|
|
143
|
+
case types_1.TelemetryEventType.STATEMENT_COMPLETE:
|
|
144
|
+
details.executionLatencyMs = event.latencyMs;
|
|
145
|
+
details.resultFormat = event.resultFormat;
|
|
146
|
+
details.chunkCount = (_a = event.chunkCount) !== null && _a !== void 0 ? _a : 0;
|
|
147
|
+
details.bytesDownloaded = (_b = event.bytesDownloaded) !== null && _b !== void 0 ? _b : 0;
|
|
148
|
+
details.pollCount = (_c = event.pollCount) !== null && _c !== void 0 ? _c : 0;
|
|
149
|
+
break;
|
|
150
|
+
case types_1.TelemetryEventType.CLOUDFETCH_CHUNK:
|
|
151
|
+
details.chunkCount += 1;
|
|
152
|
+
details.bytesDownloaded += (_d = event.bytes) !== null && _d !== void 0 ? _d : 0;
|
|
153
|
+
if (event.compressed !== undefined) {
|
|
154
|
+
details.compressionEnabled = event.compressed;
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
getOrCreateStatementDetails(event) {
|
|
162
|
+
const statementId = event.statementId;
|
|
163
|
+
if (!this.statementMetrics.has(statementId)) {
|
|
164
|
+
this.statementMetrics.set(statementId, {
|
|
165
|
+
statementId,
|
|
166
|
+
sessionId: event.sessionId,
|
|
167
|
+
workspaceId: event.workspaceId,
|
|
168
|
+
startTime: event.timestamp,
|
|
169
|
+
chunkCount: 0,
|
|
170
|
+
bytesDownloaded: 0,
|
|
171
|
+
pollCount: 0,
|
|
172
|
+
errors: [],
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return this.statementMetrics.get(statementId);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Drop entries older than `statementTtlMs`, emitting their buffered error
|
|
179
|
+
* events as standalone metrics first so the first-failure signal survives
|
|
180
|
+
* the eviction. Called from the periodic flush timer so idle clients
|
|
181
|
+
* don't leak orphan entries.
|
|
182
|
+
*/
|
|
183
|
+
evictExpiredStatements() {
|
|
184
|
+
const cutoff = Date.now() - this.statementTtlMs;
|
|
185
|
+
let evicted = 0;
|
|
186
|
+
for (const [id, details] of this.statementMetrics) {
|
|
187
|
+
if (details.startTime < cutoff) {
|
|
188
|
+
for (const errorEvent of details.errors) {
|
|
189
|
+
this.addPendingMetric({
|
|
190
|
+
metricType: 'error',
|
|
191
|
+
timestamp: errorEvent.timestamp,
|
|
192
|
+
sessionId: details.sessionId,
|
|
193
|
+
statementId: details.statementId,
|
|
194
|
+
workspaceId: details.workspaceId,
|
|
195
|
+
errorName: errorEvent.errorName,
|
|
196
|
+
errorMessage: errorEvent.errorMessage,
|
|
197
|
+
errorStack: errorEvent.errorStack,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
this.statementMetrics.delete(id);
|
|
201
|
+
evicted += 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (evicted > 0) {
|
|
205
|
+
this.context
|
|
206
|
+
.getLogger()
|
|
207
|
+
.log(IDBSQLLogger_1.LogLevel.debug, `Evicted ${evicted} abandoned statement(s) past ${this.statementTtlMs}ms TTL`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
completeStatement(statementId) {
|
|
211
|
+
if (this.closed)
|
|
212
|
+
return;
|
|
213
|
+
const logger = this.context.getLogger();
|
|
214
|
+
try {
|
|
215
|
+
const details = this.statementMetrics.get(statementId);
|
|
216
|
+
if (!details) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const metric = {
|
|
220
|
+
metricType: 'statement',
|
|
221
|
+
timestamp: details.startTime,
|
|
222
|
+
sessionId: details.sessionId,
|
|
223
|
+
statementId: details.statementId,
|
|
224
|
+
workspaceId: details.workspaceId,
|
|
225
|
+
latencyMs: details.executionLatencyMs,
|
|
226
|
+
resultFormat: details.resultFormat,
|
|
227
|
+
chunkCount: details.chunkCount,
|
|
228
|
+
bytesDownloaded: details.bytesDownloaded,
|
|
229
|
+
pollCount: details.pollCount,
|
|
230
|
+
};
|
|
231
|
+
this.addPendingMetric(metric);
|
|
232
|
+
for (const errorEvent of details.errors) {
|
|
233
|
+
const errorMetric = {
|
|
234
|
+
metricType: 'error',
|
|
235
|
+
timestamp: errorEvent.timestamp,
|
|
236
|
+
sessionId: details.sessionId,
|
|
237
|
+
statementId: details.statementId,
|
|
238
|
+
workspaceId: details.workspaceId,
|
|
239
|
+
errorName: errorEvent.errorName,
|
|
240
|
+
errorMessage: errorEvent.errorMessage,
|
|
241
|
+
errorStack: errorEvent.errorStack,
|
|
242
|
+
};
|
|
243
|
+
this.addPendingMetric(errorMetric);
|
|
244
|
+
}
|
|
245
|
+
this.statementMetrics.delete(statementId);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `MetricsAggregator.completeStatement error: ${error.message}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Append `metric` to the pending buffer, enforcing `maxPendingMetrics`.
|
|
253
|
+
*
|
|
254
|
+
* Overflow drops the oldest non-error entry (single `splice` — no new
|
|
255
|
+
* allocation). Under an all-error buffer it falls back to dropping the
|
|
256
|
+
* oldest entry at index 0.
|
|
257
|
+
*/
|
|
258
|
+
addPendingMetric(metric) {
|
|
259
|
+
if (this.closed)
|
|
260
|
+
return;
|
|
261
|
+
this.pendingMetrics.push(metric);
|
|
262
|
+
if (this.pendingMetrics.length > this.maxPendingMetrics) {
|
|
263
|
+
const dropIndex = this.findDropIndex();
|
|
264
|
+
this.pendingMetrics.splice(dropIndex, 1);
|
|
265
|
+
const logger = this.context.getLogger();
|
|
266
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Dropped 1 oldest non-error telemetry metric (buffer full at ${this.maxPendingMetrics})`);
|
|
267
|
+
}
|
|
268
|
+
if (this.pendingMetrics.length >= this.batchSize && !this.closing) {
|
|
269
|
+
// resetTimer=false so the periodic tail-drain keeps its cadence even
|
|
270
|
+
// under sustained batch-size bursts.
|
|
271
|
+
const logger = this.context.getLogger();
|
|
272
|
+
Promise.resolve(this.flush(false)).catch((err) => {
|
|
273
|
+
var _a;
|
|
274
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Batch-trigger flush failed: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
findDropIndex() {
|
|
279
|
+
for (let i = 0; i < this.pendingMetrics.length; i += 1) {
|
|
280
|
+
if (this.pendingMetrics[i].metricType !== 'error') {
|
|
281
|
+
return i;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Drain the pending buffer and return a promise that resolves when the
|
|
288
|
+
* exporter finishes with the drained batch. `close()` awaits this so
|
|
289
|
+
* `process.exit()` after `client.close()` doesn't truncate the POST.
|
|
290
|
+
*/
|
|
291
|
+
async flush(resetTimer = true) {
|
|
292
|
+
var _a;
|
|
293
|
+
const logger = this.context.getLogger();
|
|
294
|
+
let exportPromise = null;
|
|
295
|
+
try {
|
|
296
|
+
if (this.pendingMetrics.length === 0) {
|
|
297
|
+
if (resetTimer && !this.closed) {
|
|
298
|
+
this.startFlushTimer();
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const metricsToExport = this.pendingMetrics;
|
|
303
|
+
this.pendingMetrics = [];
|
|
304
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Flushing ${metricsToExport.length} telemetry metrics`);
|
|
305
|
+
exportPromise = this.exporter.export(metricsToExport);
|
|
306
|
+
if (resetTimer && !this.closed) {
|
|
307
|
+
this.startFlushTimer();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `MetricsAggregator.flush error: ${error.message}`);
|
|
312
|
+
}
|
|
313
|
+
if (exportPromise) {
|
|
314
|
+
try {
|
|
315
|
+
await exportPromise;
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Unexpected export error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
startFlushTimer() {
|
|
323
|
+
if (this.closed)
|
|
324
|
+
return;
|
|
325
|
+
const logger = this.context.getLogger();
|
|
326
|
+
try {
|
|
327
|
+
if (this.flushTimer) {
|
|
328
|
+
clearInterval(this.flushTimer);
|
|
329
|
+
}
|
|
330
|
+
this.flushTimer = setInterval(() => {
|
|
331
|
+
var _a;
|
|
332
|
+
// Idle eviction: run before the flush so orphan-error metrics have
|
|
333
|
+
// a chance to batch into this drain rather than wait for the next.
|
|
334
|
+
try {
|
|
335
|
+
this.evictExpiredStatements();
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `evictExpiredStatements error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
|
|
339
|
+
}
|
|
340
|
+
Promise.resolve(this.flush(false)).catch((err) => {
|
|
341
|
+
var _a;
|
|
342
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Periodic flush failed: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
|
|
343
|
+
});
|
|
344
|
+
}, this.flushIntervalMs);
|
|
345
|
+
this.flushTimer.unref();
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `MetricsAggregator.startFlushTimer error: ${error.message}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async close() {
|
|
352
|
+
const logger = this.context.getLogger();
|
|
353
|
+
try {
|
|
354
|
+
// Suppress batch-triggered fire-and-forget flushes from addPendingMetric
|
|
355
|
+
// so no promises escape past the single awaited flush below.
|
|
356
|
+
this.closing = true;
|
|
357
|
+
if (this.flushTimer) {
|
|
358
|
+
clearInterval(this.flushTimer);
|
|
359
|
+
this.flushTimer = null;
|
|
360
|
+
}
|
|
361
|
+
// closed is still false here so completeStatement → addPendingMetric works normally.
|
|
362
|
+
const remainingStatements = [...this.statementMetrics.keys()];
|
|
363
|
+
for (const statementId of remainingStatements) {
|
|
364
|
+
this.completeStatement(statementId);
|
|
365
|
+
}
|
|
366
|
+
this.closed = true;
|
|
367
|
+
await this.flush(false);
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `MetricsAggregator.close error: ${error.message}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
exports.default = MetricsAggregator;
|
|
375
|
+
//# sourceMappingURL=MetricsAggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetricsAggregator.js","sourceRoot":"","sources":["../../lib/telemetry/MetricsAggregator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAGH,4DAAqD;AACrD,mCAAwG;AAkBxG;;;;;;;GAOG;AACH,MAAqB,iBAAiB;IAqBpC,YAAoB,OAAuB,EAAU,QAAqC;;QAAtE,YAAO,GAAP,OAAO,CAAgB;QAAU,aAAQ,GAAR,QAAQ,CAA6B;QApBlF,qBAAgB,GAA2C,IAAI,GAAG,EAAE,CAAC;QAErE,mBAAc,GAAsB,EAAE,CAAC;QAEvC,eAAU,GAA0B,IAAI,CAAC;QAEzC,WAAM,GAAG,KAAK,CAAC;QAEf,YAAO,GAAG,KAAK,CAAC;QAatB,IAAI;YACF,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,CAAC,kBAAkB,mCAAI,gCAAwB,CAAC,SAAS,CAAC;YACjF,IAAI,CAAC,eAAe,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AAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QAExC,IAAI;YACF,yEAAyE;YACzE,6DAA6D;YAC7D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;aACxB;YAED,qFAAqF;YACrF,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;YAC9D,KAAK,MAAM,WAAW,IAAI,mBAAmB,EAAE;gBAC7C,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;aACrC;YAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACzB;QAAC,OAAO,KAAU,EAAE;YACnB,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SAC/E;IACH,CAAC;CACF;AArYD,oCAqYC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Databricks Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import IClientContext from '../contracts/IClientContext';
|
|
17
|
+
/**
|
|
18
|
+
* Telemetry client for a specific host.
|
|
19
|
+
* Managed by TelemetryClientProvider with reference counting.
|
|
20
|
+
* One client instance is shared across all connections to the same host.
|
|
21
|
+
*/
|
|
22
|
+
declare class TelemetryClient {
|
|
23
|
+
private context;
|
|
24
|
+
private host;
|
|
25
|
+
private closed;
|
|
26
|
+
constructor(context: IClientContext, host: string);
|
|
27
|
+
/**
|
|
28
|
+
* Gets the host associated with this client.
|
|
29
|
+
*/
|
|
30
|
+
getHost(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the client has been closed.
|
|
33
|
+
*/
|
|
34
|
+
isClosed(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Closes the telemetry client and releases resources.
|
|
37
|
+
* Should only be called by TelemetryClientProvider when reference count reaches zero.
|
|
38
|
+
*/
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
export default TelemetryClient;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Databricks Contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
|
|
19
|
+
/**
|
|
20
|
+
* Telemetry client for a specific host.
|
|
21
|
+
* Managed by TelemetryClientProvider with reference counting.
|
|
22
|
+
* One client instance is shared across all connections to the same host.
|
|
23
|
+
*/
|
|
24
|
+
class TelemetryClient {
|
|
25
|
+
constructor(context, host) {
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.host = host;
|
|
28
|
+
this.closed = false;
|
|
29
|
+
const logger = context.getLogger();
|
|
30
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Created TelemetryClient for host: ${host}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the host associated with this client.
|
|
34
|
+
*/
|
|
35
|
+
getHost() {
|
|
36
|
+
return this.host;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the client has been closed.
|
|
40
|
+
*/
|
|
41
|
+
isClosed() {
|
|
42
|
+
return this.closed;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Closes the telemetry client and releases resources.
|
|
46
|
+
* Should only be called by TelemetryClientProvider when reference count reaches zero.
|
|
47
|
+
*/
|
|
48
|
+
close() {
|
|
49
|
+
if (this.closed) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Closing TelemetryClient for host: ${this.host}`);
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
// swallow
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
this.closed = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.default = TelemetryClient;
|
|
64
|
+
//# sourceMappingURL=TelemetryClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TelemetryClient.js","sourceRoot":"","sources":["../../lib/telemetry/TelemetryClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAGH,4DAAqD;AAErD;;;;GAIG;AACH,MAAM,eAAe;IAGnB,YAAoB,OAAuB,EAAU,IAAY;QAA7C,YAAO,GAAP,OAAO,CAAgB;QAAU,SAAI,GAAJ,IAAI,CAAQ;QAFzD,WAAM,GAAY,KAAK,CAAC;QAG9B,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,qCAAqC,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO;SACR;QACD,IAAI;YACF,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,qCAAqC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;SAChG;QAAC,WAAM;YACN,UAAU;SACX;gBAAS;YACR,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACpB;IACH,CAAC;CACF;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Databricks Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import IClientContext from '../contracts/IClientContext';
|
|
17
|
+
import TelemetryClient from './TelemetryClient';
|
|
18
|
+
/**
|
|
19
|
+
* Manages one telemetry client per host.
|
|
20
|
+
* Prevents rate limiting by sharing clients across connections to the same host.
|
|
21
|
+
* Instance-based (not singleton), stored in DBSQLClient.
|
|
22
|
+
*
|
|
23
|
+
* Reference counts are incremented and decremented synchronously, and
|
|
24
|
+
* `close()` is sync today, so there is no await between map mutation and
|
|
25
|
+
* client teardown. The map entry is removed before `close()` runs so a
|
|
26
|
+
* concurrent `getOrCreateClient` call for the same host gets a fresh
|
|
27
|
+
* instance rather than receiving this closing one. When `close()` becomes
|
|
28
|
+
* async (e.g. HTTP flush in [5/7]) the flow will need to `await` after the
|
|
29
|
+
* delete to preserve the same invariant.
|
|
30
|
+
*/
|
|
31
|
+
declare class TelemetryClientProvider {
|
|
32
|
+
private context;
|
|
33
|
+
private clients;
|
|
34
|
+
private softLimitWarned;
|
|
35
|
+
constructor(context: IClientContext);
|
|
36
|
+
/**
|
|
37
|
+
* Canonicalize host so aliases (scheme, default port, trailing slash, case,
|
|
38
|
+
* trailing dot, surrounding whitespace) map to the same entry. Kept to a
|
|
39
|
+
* lightweight lexical normalization — `buildTelemetryUrl` still performs
|
|
40
|
+
* the strict security validation when a request is actually built.
|
|
41
|
+
*/
|
|
42
|
+
private static normalizeHostKey;
|
|
43
|
+
/**
|
|
44
|
+
* Gets or creates a telemetry client for the specified host.
|
|
45
|
+
* Increments the reference count for the client.
|
|
46
|
+
*
|
|
47
|
+
* @param host The host identifier (e.g., "workspace.cloud.databricks.com")
|
|
48
|
+
* @returns The telemetry client for the host
|
|
49
|
+
*/
|
|
50
|
+
getOrCreateClient(host: string): TelemetryClient;
|
|
51
|
+
/**
|
|
52
|
+
* Releases a telemetry client for the specified host.
|
|
53
|
+
* Decrements the reference count and closes the client when it reaches zero.
|
|
54
|
+
*
|
|
55
|
+
* @param host The host identifier
|
|
56
|
+
*/
|
|
57
|
+
releaseClient(host: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* @internal Exposed for testing only.
|
|
60
|
+
*/
|
|
61
|
+
getRefCount(host: string): number;
|
|
62
|
+
/**
|
|
63
|
+
* @internal Exposed for testing only.
|
|
64
|
+
*/
|
|
65
|
+
getActiveClients(): Map<string, TelemetryClient>;
|
|
66
|
+
}
|
|
67
|
+
export default TelemetryClientProvider;
|