@databricks/sql 1.13.0 → 1.15.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/README.md +12 -0
- package/dist/DBSQLClient.d.ts +107 -0
- package/dist/DBSQLClient.js +470 -0
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLOperation.d.ts +32 -1
- package/dist/DBSQLOperation.js +138 -29
- package/dist/DBSQLOperation.js.map +1 -1
- package/dist/DBSQLSession.d.ts +1 -0
- package/dist/DBSQLSession.js +43 -12
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +10 -6
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
- package/dist/contracts/IClientContext.d.ts +36 -0
- package/dist/contracts/IDBSQLClient.d.ts +90 -0
- package/dist/contracts/IDBSQLSession.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/result/CloudFetchResultHandler.d.ts +8 -1
- package/dist/result/CloudFetchResultHandler.js +28 -2
- package/dist/result/CloudFetchResultHandler.js.map +1 -1
- package/dist/result/RowSetProvider.d.ts +8 -1
- package/dist/result/RowSetProvider.js +110 -1
- package/dist/result/RowSetProvider.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 +358 -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 +214 -0
- package/dist/telemetry/FeatureFlagCache.js.map +1 -0
- package/dist/telemetry/MetricsAggregator.d.ts +110 -0
- package/dist/telemetry/MetricsAggregator.js +610 -0
- package/dist/telemetry/MetricsAggregator.js.map +1 -0
- package/dist/telemetry/TelemetryClient.d.ts +121 -0
- package/dist/telemetry/TelemetryClient.js +296 -0
- package/dist/telemetry/TelemetryClient.js.map +1 -0
- package/dist/telemetry/TelemetryClientProvider.d.ts +62 -0
- package/dist/telemetry/TelemetryClientProvider.js +154 -0
- package/dist/telemetry/TelemetryClientProvider.js.map +1 -0
- package/dist/telemetry/TelemetryEventEmitter.d.ts +119 -0
- package/dist/telemetry/TelemetryEventEmitter.js +151 -0
- package/dist/telemetry/TelemetryEventEmitter.js.map +1 -0
- package/dist/telemetry/telemetryTypeMappers.d.ts +25 -0
- package/dist/telemetry/telemetryTypeMappers.js +72 -0
- package/dist/telemetry/telemetryTypeMappers.js.map +1 -0
- package/dist/telemetry/telemetryUtils.d.ts +70 -0
- package/dist/telemetry/telemetryUtils.js +273 -0
- package/dist/telemetry/telemetryUtils.js.map +1 -0
- package/dist/telemetry/types.d.ts +70 -5
- package/dist/telemetry/types.js +19 -6
- package/dist/telemetry/types.js.map +1 -1
- 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 +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExceptionClassifier.js","sourceRoot":"","sources":["../../lib/telemetry/ExceptionClassifier.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,wFAAgE;AAChE,sEAA8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,SAAS,KAAK,YAAY;YAC1B,SAAS,KAAK,cAAc;YAC5B,SAAS,KAAK,WAAW;YACzB,SAAS,KAAK,WAAW,EACzB;YACA,OAAO,IAAI,CAAC;SACb;QAED,kDAAkD;QAClD,2EAA2E;QAC3E,MAAM,UAAU,GAAG,MAAC,KAAa,CAAC,UAAU,mCAAK,KAAa,CAAC,MAAM,CAAC;QAEtE,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,+BAA+B;YAC/B,0CAA0C;YAC1C,8BAA8B;YAC9B,oBAAoB;YACpB,4BAA4B;YAC5B,wBAAwB;YACxB,OAAO,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,CAAC;SACnH;QAED,2CAA2C;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtFD,sCAsFC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 IAuthentication from '../connection/contracts/IAuthentication';
|
|
18
|
+
export interface FeatureFlagContext {
|
|
19
|
+
telemetryEnabled?: boolean;
|
|
20
|
+
lastFetched?: Date;
|
|
21
|
+
refCount: number;
|
|
22
|
+
cacheDuration: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Per-host feature-flag cache used to gate telemetry emission. Responsibilities:
|
|
26
|
+
* - dedupe in-flight fetches (thundering-herd protection);
|
|
27
|
+
* - ref-count so context goes away when the last consumer closes;
|
|
28
|
+
* - clamp server-provided TTL into a safe band.
|
|
29
|
+
*
|
|
30
|
+
* Shares HTTP plumbing (agent, user agent) with DatabricksTelemetryExporter.
|
|
31
|
+
* Consumer wiring lands in a later PR in this stack (see PR description).
|
|
32
|
+
*/
|
|
33
|
+
export default class FeatureFlagCache {
|
|
34
|
+
private context;
|
|
35
|
+
private authProvider?;
|
|
36
|
+
private contexts;
|
|
37
|
+
private fetchPromises;
|
|
38
|
+
private readonly userAgent;
|
|
39
|
+
private readonly CACHE_DURATION_MS;
|
|
40
|
+
private readonly MIN_CACHE_DURATION_S;
|
|
41
|
+
private readonly MAX_CACHE_DURATION_S;
|
|
42
|
+
private readonly FEATURE_FLAG_NAME;
|
|
43
|
+
constructor(context: IClientContext, authProvider?: IAuthentication | undefined);
|
|
44
|
+
getOrCreateContext(host: string): FeatureFlagContext;
|
|
45
|
+
releaseContext(host: string): void;
|
|
46
|
+
isTelemetryEnabled(host: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Strips the `-oss` suffix the feature-flag API does not accept. The server
|
|
49
|
+
* keys off the SemVer triplet only, so anything appended would 404.
|
|
50
|
+
*/
|
|
51
|
+
private getDriverVersion;
|
|
52
|
+
private fetchFeatureFlag;
|
|
53
|
+
/**
|
|
54
|
+
* Retries transient network errors once before giving up. Without a retry
|
|
55
|
+
* a single hiccup would leave telemetry disabled for the full cache TTL
|
|
56
|
+
* (15 min). One retry gives an ephemeral DNS / connection-reset failure
|
|
57
|
+
* a second chance without pushing sustained load at a broken endpoint.
|
|
58
|
+
*/
|
|
59
|
+
private fetchWithRetry;
|
|
60
|
+
private getAuthHeaders;
|
|
61
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
const node_fetch_1 = __importStar(require("node-fetch"));
|
|
45
|
+
const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
|
|
46
|
+
const telemetryUtils_1 = require("./telemetryUtils");
|
|
47
|
+
const buildUserAgentString_1 = __importDefault(require("../utils/buildUserAgentString"));
|
|
48
|
+
const version_1 = __importDefault(require("../version"));
|
|
49
|
+
/**
|
|
50
|
+
* Per-host feature-flag cache used to gate telemetry emission. Responsibilities:
|
|
51
|
+
* - dedupe in-flight fetches (thundering-herd protection);
|
|
52
|
+
* - ref-count so context goes away when the last consumer closes;
|
|
53
|
+
* - clamp server-provided TTL into a safe band.
|
|
54
|
+
*
|
|
55
|
+
* Shares HTTP plumbing (agent, user agent) with DatabricksTelemetryExporter.
|
|
56
|
+
* Consumer wiring lands in a later PR in this stack (see PR description).
|
|
57
|
+
*/
|
|
58
|
+
class FeatureFlagCache {
|
|
59
|
+
constructor(context, authProvider) {
|
|
60
|
+
this.context = context;
|
|
61
|
+
this.authProvider = authProvider;
|
|
62
|
+
this.fetchPromises = new Map();
|
|
63
|
+
this.CACHE_DURATION_MS = 15 * 60 * 1000;
|
|
64
|
+
this.MIN_CACHE_DURATION_S = 60;
|
|
65
|
+
this.MAX_CACHE_DURATION_S = 3600;
|
|
66
|
+
this.FEATURE_FLAG_NAME = 'databricks.partnerplatform.clientConfigsFeatureFlags.enableTelemetryForNodeJs';
|
|
67
|
+
this.contexts = new Map();
|
|
68
|
+
this.userAgent = (0, buildUserAgentString_1.default)(this.context.getConfig().userAgentEntry);
|
|
69
|
+
}
|
|
70
|
+
getOrCreateContext(host) {
|
|
71
|
+
let ctx = this.contexts.get(host);
|
|
72
|
+
if (!ctx) {
|
|
73
|
+
ctx = {
|
|
74
|
+
refCount: 0,
|
|
75
|
+
cacheDuration: this.CACHE_DURATION_MS,
|
|
76
|
+
};
|
|
77
|
+
this.contexts.set(host, ctx);
|
|
78
|
+
}
|
|
79
|
+
ctx.refCount += 1;
|
|
80
|
+
return ctx;
|
|
81
|
+
}
|
|
82
|
+
releaseContext(host) {
|
|
83
|
+
const ctx = this.contexts.get(host);
|
|
84
|
+
if (ctx) {
|
|
85
|
+
ctx.refCount -= 1;
|
|
86
|
+
if (ctx.refCount <= 0) {
|
|
87
|
+
this.contexts.delete(host);
|
|
88
|
+
this.fetchPromises.delete(host);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async isTelemetryEnabled(host) {
|
|
93
|
+
var _a;
|
|
94
|
+
const logger = this.context.getLogger();
|
|
95
|
+
const ctx = this.contexts.get(host);
|
|
96
|
+
if (!ctx) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const isExpired = !ctx.lastFetched || Date.now() - ctx.lastFetched.getTime() > ctx.cacheDuration;
|
|
100
|
+
if (isExpired) {
|
|
101
|
+
if (!this.fetchPromises.has(host)) {
|
|
102
|
+
const fetchPromise = this.fetchFeatureFlag(host)
|
|
103
|
+
.then((enabled) => {
|
|
104
|
+
ctx.telemetryEnabled = enabled;
|
|
105
|
+
ctx.lastFetched = new Date();
|
|
106
|
+
return enabled;
|
|
107
|
+
})
|
|
108
|
+
.catch((error) => {
|
|
109
|
+
var _a;
|
|
110
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Error fetching feature flag: ${error.message}`);
|
|
111
|
+
return (_a = ctx.telemetryEnabled) !== null && _a !== void 0 ? _a : false;
|
|
112
|
+
})
|
|
113
|
+
.finally(() => {
|
|
114
|
+
this.fetchPromises.delete(host);
|
|
115
|
+
});
|
|
116
|
+
this.fetchPromises.set(host, fetchPromise);
|
|
117
|
+
}
|
|
118
|
+
await this.fetchPromises.get(host);
|
|
119
|
+
}
|
|
120
|
+
return (_a = ctx.telemetryEnabled) !== null && _a !== void 0 ? _a : false;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Strips the `-oss` suffix the feature-flag API does not accept. The server
|
|
124
|
+
* keys off the SemVer triplet only, so anything appended would 404.
|
|
125
|
+
*/
|
|
126
|
+
getDriverVersion() {
|
|
127
|
+
return version_1.default.replace(/-oss$/, '');
|
|
128
|
+
}
|
|
129
|
+
async fetchFeatureFlag(host) {
|
|
130
|
+
var _a;
|
|
131
|
+
const logger = this.context.getLogger();
|
|
132
|
+
try {
|
|
133
|
+
const endpoint = (0, telemetryUtils_1.buildTelemetryUrl)(host, `/api/2.0/connector-service/feature-flags/NODEJS/${this.getDriverVersion()}`);
|
|
134
|
+
if (!endpoint) {
|
|
135
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Feature flag fetch skipped: invalid host ${host}`);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const headers = {
|
|
139
|
+
'Content-Type': 'application/json',
|
|
140
|
+
'User-Agent': this.userAgent,
|
|
141
|
+
...((_a = this.context.getConfig().customHeaders) !== null && _a !== void 0 ? _a : {}),
|
|
142
|
+
...(await this.getAuthHeaders()),
|
|
143
|
+
};
|
|
144
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Fetching feature flags from ${endpoint}`);
|
|
145
|
+
const response = await this.fetchWithRetry(endpoint, {
|
|
146
|
+
method: 'GET',
|
|
147
|
+
headers,
|
|
148
|
+
timeout: 10000,
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
await response.text().catch(() => { });
|
|
152
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Feature flag fetch failed: ${response.status} ${response.statusText}`);
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const data = await response.json();
|
|
156
|
+
if (data && data.flags && Array.isArray(data.flags)) {
|
|
157
|
+
const ctx = this.contexts.get(host);
|
|
158
|
+
if (ctx && typeof data.ttl_seconds === 'number' && data.ttl_seconds > 0) {
|
|
159
|
+
const clampedTtl = Math.max(this.MIN_CACHE_DURATION_S, Math.min(this.MAX_CACHE_DURATION_S, data.ttl_seconds));
|
|
160
|
+
ctx.cacheDuration = clampedTtl * 1000;
|
|
161
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Updated cache duration to ${clampedTtl} seconds`);
|
|
162
|
+
}
|
|
163
|
+
const flag = data.flags.find((f) => f.name === this.FEATURE_FLAG_NAME);
|
|
164
|
+
if (flag) {
|
|
165
|
+
const enabled = String(flag.value).toLowerCase() === 'true';
|
|
166
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Feature flag ${this.FEATURE_FLAG_NAME}: ${enabled}`);
|
|
167
|
+
return enabled;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Feature flag ${this.FEATURE_FLAG_NAME} not found in response`);
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
logger.log(IDBSQLLogger_1.LogLevel.debug, `Error fetching feature flag from ${host}: ${error.message}`);
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Retries transient network errors once before giving up. Without a retry
|
|
180
|
+
* a single hiccup would leave telemetry disabled for the full cache TTL
|
|
181
|
+
* (15 min). One retry gives an ephemeral DNS / connection-reset failure
|
|
182
|
+
* a second chance without pushing sustained load at a broken endpoint.
|
|
183
|
+
*/
|
|
184
|
+
async fetchWithRetry(url, init) {
|
|
185
|
+
const connectionProvider = await this.context.getConnectionProvider();
|
|
186
|
+
const agent = await connectionProvider.getAgent();
|
|
187
|
+
const retryPolicy = await connectionProvider.getRetryPolicy();
|
|
188
|
+
const requestConfig = { agent, ...init };
|
|
189
|
+
const result = await retryPolicy.invokeWithRetry(() => {
|
|
190
|
+
const request = new node_fetch_1.Request(url, requestConfig);
|
|
191
|
+
return (0, node_fetch_1.default)(request).then((response) => ({ request, response }));
|
|
192
|
+
});
|
|
193
|
+
return result.response;
|
|
194
|
+
}
|
|
195
|
+
async getAuthHeaders() {
|
|
196
|
+
var _a, _b, _c, _d;
|
|
197
|
+
// Prefer the explicitly-injected auth provider; fall back to the context
|
|
198
|
+
// (used when a shared TelemetryClient resolves auth through its FIFO of
|
|
199
|
+
// registered DBSQLClients). Mirrors DatabricksTelemetryExporter.getAuthHeaders.
|
|
200
|
+
const authProvider = (_a = this.authProvider) !== null && _a !== void 0 ? _a : (_c = (_b = this.context).getAuthProvider) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
201
|
+
if (!authProvider) {
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
return (0, telemetryUtils_1.normalizeHeaders)(await authProvider.authenticate());
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Feature flag auth failed: ${(_d = error === null || error === void 0 ? void 0 : error.message) !== null && _d !== void 0 ? _d : error}`);
|
|
209
|
+
return {};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.default = FeatureFlagCache;
|
|
214
|
+
//# sourceMappingURL=FeatureFlagCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeatureFlagCache.js","sourceRoot":"","sources":["../../lib/telemetry/FeatureFlagCache.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yDAAmE;AAEnE,4DAAqD;AAErD,qDAAuE;AACvE,yFAAiE;AACjE,yDAAuC;AASvC;;;;;;;;GAQG;AACH,MAAqB,gBAAgB;IAenC,YAAoB,OAAuB,EAAU,YAA8B;QAA/D,YAAO,GAAP,OAAO,CAAgB;QAAU,iBAAY,GAAZ,YAAY,CAAkB;QAZ3E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;YACnB,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,6BAA6B,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,KAAK,EAAE,CAAC,CAAC;YACrG,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CACF;AAnLD,mCAmLC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 flushInFlight;
|
|
34
|
+
private closed;
|
|
35
|
+
private closing;
|
|
36
|
+
private batchSize;
|
|
37
|
+
private flushIntervalMs;
|
|
38
|
+
private maxPendingMetrics;
|
|
39
|
+
private maxErrorsPerStatement;
|
|
40
|
+
private statementTtlMs;
|
|
41
|
+
private maxStatementMetrics;
|
|
42
|
+
private beforeExitHandler;
|
|
43
|
+
private droppedMetrics;
|
|
44
|
+
private evictedStatements;
|
|
45
|
+
private lastReportedDrops;
|
|
46
|
+
private lastReportedEvictions;
|
|
47
|
+
constructor(context: IClientContext, exporter: DatabricksTelemetryExporter);
|
|
48
|
+
processEvent(event: TelemetryEvent): void;
|
|
49
|
+
private processConnectionEvent;
|
|
50
|
+
private processErrorEvent;
|
|
51
|
+
private pushBoundedError;
|
|
52
|
+
private processStatementEvent;
|
|
53
|
+
private getOrCreateStatementDetails;
|
|
54
|
+
/**
|
|
55
|
+
* Drop the oldest entry by insertion order to make room. Emits its buffered
|
|
56
|
+
* errors as standalone metrics first so the first-failure signal survives.
|
|
57
|
+
* Map iteration order is insertion order in JS.
|
|
58
|
+
*/
|
|
59
|
+
private evictOldestStatement;
|
|
60
|
+
/**
|
|
61
|
+
* Drop entries older than `statementTtlMs`, emitting their buffered error
|
|
62
|
+
* events as standalone metrics first so the first-failure signal survives
|
|
63
|
+
* the eviction. Called from the periodic flush timer so idle clients
|
|
64
|
+
* don't leak orphan entries.
|
|
65
|
+
*/
|
|
66
|
+
private evictExpiredStatements;
|
|
67
|
+
/**
|
|
68
|
+
* Operator-visible snapshot of aggregator state. Returned synchronously so
|
|
69
|
+
* a health-check endpoint or shutdown summary can include it without
|
|
70
|
+
* awaiting anything.
|
|
71
|
+
*
|
|
72
|
+
* - `pendingMetricsCount` : current buffer depth (0..maxPendingMetrics).
|
|
73
|
+
* - `inFlightStatements` : open statement aggregations (0..maxStatementMetrics).
|
|
74
|
+
* - `droppedMetrics` : cumulative count of metrics dropped due to
|
|
75
|
+
* buffer overflow since start.
|
|
76
|
+
* - `evictedStatements` : cumulative count of statements evicted due
|
|
77
|
+
* to TTL or map-cap, since start.
|
|
78
|
+
*/
|
|
79
|
+
getStats(): {
|
|
80
|
+
pendingMetricsCount: number;
|
|
81
|
+
inFlightStatements: number;
|
|
82
|
+
droppedMetrics: number;
|
|
83
|
+
evictedStatements: number;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Emit a warn-level summary if drops/evictions occurred since the last
|
|
87
|
+
* report. Operators running on `LogLevel.info` (the driver default) need
|
|
88
|
+
* to see capacity events without enabling debug.
|
|
89
|
+
*/
|
|
90
|
+
private maybeWarnOnCapacityEvents;
|
|
91
|
+
completeStatement(statementId: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Append `metric` to the pending buffer, enforcing `maxPendingMetrics`.
|
|
94
|
+
*
|
|
95
|
+
* Overflow drops the oldest non-error entry (single `splice` — no new
|
|
96
|
+
* allocation). Under an all-error buffer it falls back to dropping the
|
|
97
|
+
* oldest entry at index 0.
|
|
98
|
+
*/
|
|
99
|
+
private addPendingMetric;
|
|
100
|
+
private findDropIndex;
|
|
101
|
+
/**
|
|
102
|
+
* Drain the pending buffer and return a promise that resolves when the
|
|
103
|
+
* exporter finishes with the drained batch. `close()` awaits this so
|
|
104
|
+
* `process.exit()` after `client.close()` doesn't truncate the POST.
|
|
105
|
+
*/
|
|
106
|
+
flush(resetTimer?: boolean): Promise<void>;
|
|
107
|
+
private runFlush;
|
|
108
|
+
private startFlushTimer;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
}
|