-
Notifications
You must be signed in to change notification settings - Fork 50
Forward kernel telemetry options #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
0a8904e
8c661e6
4e64646
27e4f8e
4a7198d
9ece09b
90c154e
d88359b
7f512ca
c254d95
586df79
aa192f7
0240935
0a0586d
a7b7215
cd1573c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,17 @@ | |
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import os from 'os'; | ||
| import { ConnectionOptions } from '../contracts/IDBSQLClient'; | ||
| import { ClientConfig } from '../contracts/IClientContext'; | ||
| import { InternalConnectionOptions } from '../contracts/InternalConnectionOptions'; | ||
| import IDBSQLLogger, { LogLevel } from '../contracts/IDBSQLLogger'; | ||
| import AuthenticationError from '../errors/AuthenticationError'; | ||
| import HiveDriverError from '../errors/HiveDriverError'; | ||
| import { buildUserAgentString, normalizePemBytes } from '../utils'; | ||
| import driverVersion from '../version'; | ||
| import { DRIVER_NAME } from '../telemetry/types'; | ||
| import { sanitizeProcessName, isTelemetryDisabledByEnv } from '../telemetry/telemetryUtils'; | ||
|
|
||
| /** | ||
| * Default local listener port for the U2M authorization-code callback. | ||
|
|
@@ -131,6 +137,32 @@ export interface KernelSessionDefaults { | |
| retryOverallTimeoutSecs?: number; | ||
| } | ||
|
|
||
| export interface KernelTelemetryOptions { | ||
| /** Driver/runtime identity forwarded to kernel-owned telemetry. */ | ||
| driverName?: string; | ||
| driverVersion?: string; | ||
| runtimeName?: string; | ||
| runtimeVersion?: string; | ||
| runtimeVendor?: string; | ||
| osName?: string; | ||
| osVersion?: string; | ||
| osArch?: string; | ||
| clientAppName?: string; | ||
| localeName?: string; | ||
| charSetEncoding?: string; | ||
| processName?: string; | ||
| /** Kernel-owned telemetry switch and batching. */ | ||
| telemetryEnabled?: boolean; | ||
| telemetryBatchSize?: number; | ||
| telemetryFlushIntervalMs?: number; | ||
| telemetryMaxRetries?: number; | ||
| telemetryRetryDelayMs?: number; | ||
| telemetryCloseFlushTimeoutMs?: number; | ||
| telemetryCircuitBreakerEnabled?: boolean; | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| telemetryCircuitBreakerThreshold?: number; | ||
| telemetryCircuitBreakerTimeoutMs?: number; | ||
| } | ||
|
|
||
| /** | ||
| * TLS options shared across all auth-mode variants. Mirror the napi | ||
| * binding's `ConnectionOptions.checkServerCertificate` / `.customCaCert` | ||
|
|
@@ -227,6 +259,7 @@ export interface KernelFederationOptions { | |
| export type KernelNativeConnectionOptions = KernelSessionDefaults & | ||
| KernelTlsOptions & | ||
| KernelHttpOptions & | ||
| KernelTelemetryOptions & | ||
| KernelProxyOptions & | ||
| KernelFederationOptions & | ||
| ( | ||
|
|
@@ -588,6 +621,164 @@ export function buildKernelRetryOptions(config: { | |
| return out; | ||
| } | ||
|
|
||
| function getLocaleName(env: NodeJS.ProcessEnv = process.env): string { | ||
| try { | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| const lang = env.LC_ALL || env.LC_MESSAGES || env.LANG || ''; | ||
| const match = lang.match(/^([a-z]{2}_[A-Z]{2})/); | ||
| return match?.[1] ?? 'en_US'; | ||
| } catch { | ||
| return 'en_US'; | ||
| } | ||
| } | ||
|
|
||
| function getProcessName(): string { | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| try { | ||
| if (process.title && process.title !== 'node') { | ||
| return sanitizeProcessName(process.title) || 'node'; | ||
| } | ||
| const scriptPath = process.argv?.[1]; | ||
| if (scriptPath) { | ||
| return sanitizeProcessName(scriptPath).replace(/\.[^.]*$/, '') || 'node'; | ||
| } | ||
| return 'node'; | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| } catch { | ||
| return 'node'; | ||
| } | ||
| } | ||
|
|
||
| // Re-exported from the shared telemetry helper so the kernel opt-out and the | ||
| // Thrift-path opt-out (DBSQLClient) parse `DATABRICKS_TELEMETRY_DISABLED` | ||
| // through one implementation and can never drift. | ||
| export { isTelemetryDisabledByEnv }; | ||
|
|
||
| /** | ||
| * Build the kernel telemetry options block from the driver's `ClientConfig`. | ||
| * | ||
| * **Always-forward is intentional, mirroring `buildKernelRetryOptions`.** On the | ||
| * real `DBSQLClient` path `getDefaultConfig()` seeds every one of these knobs from | ||
| * `DEFAULT_TELEMETRY_CONFIG`, so they are never `undefined` and always propagate to | ||
| * the kernel's `openSession` — the driver's telemetry-tuning defaults deliberately | ||
| * govern both backends from one `ClientConfig` (same rationale as the retry knobs), | ||
| * rather than letting the kernel's independent defaults apply. The kernel's own | ||
| * `"Omitted ⇒ kernel default"` branch is therefore only reachable via a bare | ||
| * `configOverrides`-style config (e.g. unit tests), not the default-populated one a | ||
| * live client uses. The `Number.isFinite(...) && > 0` guards below are NOT an | ||
| * opt-in gate: they exist to reject a caller-supplied out-of-range value (warning | ||
| * via `warnRejected`) and to tolerate sparse test configs, not to compare against | ||
| * the default. | ||
| */ | ||
| export function buildKernelTelemetryOptions( | ||
| config: Pick< | ||
| ClientConfig, | ||
| // NOTE: `telemetryEnabled` is intentionally NOT in this Pick. On the kernel | ||
| // path the enable decision is opt-in via `ConnectionOptions.telemetryEnabled` | ||
| // (plus the `DATABRICKS_TELEMETRY_DISABLED` env kill-switch) — the driver's | ||
| // default-true `config.telemetryEnabled` does not propagate here, so leaving | ||
| // it out keeps the signature honest rather than advertising a knob we ignore. | ||
| | 'telemetryBatchSize' | ||
| | 'telemetryFlushIntervalMs' | ||
| | 'telemetryMaxRetries' | ||
| | 'telemetryBackoffBaseMs' | ||
| | 'telemetryCloseTimeoutMs' | ||
| | 'telemetryCircuitBreakerThreshold' | ||
| | 'telemetryCircuitBreakerTimeout' | ||
| >, | ||
| options: Pick<ConnectionOptions, 'telemetryEnabled'> = {}, | ||
| logger?: IDBSQLLogger, | ||
| ) { | ||
| // Surface a rejected telemetry knob for parity with the `DATABRICKS_TELEMETRY_DISABLED` | ||
| // misconfiguration warn in `DBSQLClient.connect`: a caller-supplied out-of-range value | ||
| // (e.g. `telemetryBatchSize: 0`) is silently dropped in favour of the kernel default, | ||
| // so without this the user gets no feedback that their setting was discarded. Only | ||
| // warns when the knob was actually supplied (`Number.isFinite`) but out of range — | ||
| // an unset knob (`undefined`) is never a misconfiguration. On the live `DBSQLClient` | ||
| // path these knobs are always populated from `DEFAULT_TELEMETRY_CONFIG`, so the | ||
| // `undefined` branch is the sparse-config (e.g. unit-test) case, not the norm. | ||
| const warnRejected = (name: string, value: number | undefined, constraint: string) => { | ||
| if (Number.isFinite(value)) { | ||
| logger?.log( | ||
| LogLevel.warn, | ||
| `Ignoring telemetry option '${name}'=${value}: value must be ${constraint}. ` + | ||
| `Falling back to the kernel default.`, | ||
| ); | ||
| } | ||
| }; | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| const telemetry: KernelTelemetryOptions = { | ||
| driverName: DRIVER_NAME, | ||
| driverVersion, | ||
| runtimeName: 'Node.js', | ||
| runtimeVersion: process.version, | ||
| runtimeVendor: 'Node.js Foundation', | ||
| osName: process.platform, | ||
| osVersion: os.release(), | ||
| osArch: os.arch(), | ||
| clientAppName: undefined, | ||
| localeName: getLocaleName(), | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| charSetEncoding: 'UTF-8', | ||
| processName: getProcessName(), | ||
| }; | ||
|
|
||
| const envDisabled = isTelemetryDisabledByEnv(); | ||
| if (options.telemetryEnabled !== undefined || envDisabled) { | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| telemetry.telemetryEnabled = (options.telemetryEnabled ?? true) && !envDisabled; | ||
| } | ||
|
|
||
| // `batchSize`, `flushIntervalMs`, and `closeFlushTimeoutMs` share the same napi | ||
| // contract constraint as the breaker fields below (`Must be greater than zero when | ||
| // supplied`), so a caller-supplied `0`/negative would forward verbatim and surface | ||
| // as a hard kernel `openSession` rejection. Treat any non-positive value as a | ||
| // misconfiguration and fall back to the kernel defaults, matching the breaker guard. | ||
| if (Number.isFinite(config.telemetryBatchSize) && config.telemetryBatchSize! > 0) { | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| telemetry.telemetryBatchSize = config.telemetryBatchSize; | ||
| } else { | ||
| warnRejected('telemetryBatchSize', config.telemetryBatchSize, 'greater than zero'); | ||
| } | ||
| if (Number.isFinite(config.telemetryFlushIntervalMs) && config.telemetryFlushIntervalMs! > 0) { | ||
| telemetry.telemetryFlushIntervalMs = config.telemetryFlushIntervalMs; | ||
| } else { | ||
| warnRejected('telemetryFlushIntervalMs', config.telemetryFlushIntervalMs, 'greater than zero'); | ||
| } | ||
| // `telemetryMaxRetries` and `telemetryRetryDelayMs` (from `telemetryBackoffBaseMs`) | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| // both document `0` as valid, so we don't require `> 0` like the fields above. Only | ||
| // `telemetryMaxRetries` is a user-settable `ConnectionOptions` knob (copied by | ||
| // `copyDefinedTelemetryOptions`); `telemetryBackoffBaseMs` is internal and only ever | ||
| // arrives from `DEFAULT_TELEMETRY_CONFIG.backoffBaseMs`, so it can't be user-negative | ||
| // today. We still guard both `>= 0` uniformly: a negative mapped onto the kernel's | ||
| // unsigned retry count would be rejected or wrap, so `>= 0` keeps `0` valid while | ||
| // falling back to the kernel default for negatives. | ||
| if (Number.isFinite(config.telemetryMaxRetries) && config.telemetryMaxRetries! >= 0) { | ||
| telemetry.telemetryMaxRetries = config.telemetryMaxRetries; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — The Those defaults were chosen for the JS HTTP exporter's batching/backoff, not the kernel's Rust telemetry pipeline. If that override is intended, the "Omitted ⇒ kernel default" wording and the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Confirmed the reviewer is correct: DBSQLClient.getDefaultConfig() (lib/DBSQLClient.ts:170-185) always populates every telemetry field from DEFAULT_TELEMETRY_CONFIG with finite values, so the Number.isFinite guards in buildKernelTelemetryOptions always pass in the normal client flow and the kernel never uses its own tuned defaults (the omit path is only reachable from hand-built configs like the unit tests). Resolving this is a design decision with two opposite outcomes — either (a) the override is intended and the "Omitted ⇒ kernel default" docs + isFinite guards should be reworded/removed, or (b) it's unintended and getDefaultConfig should stop populating these so the kernel keeps its Rust-pipeline tuning (a behavioral change to a widely-consumed connector). Which telemetry defaults should win (JS connector vs Rust kernel) is a product/design judgment I can't make from the code and can't verify here; needs a human to decide intent before either the docs/guards or getDefaultConfig are changed. |
||
| } else { | ||
| warnRejected('telemetryMaxRetries', config.telemetryMaxRetries, 'zero or greater'); | ||
| } | ||
| if (Number.isFinite(config.telemetryBackoffBaseMs) && config.telemetryBackoffBaseMs! >= 0) { | ||
|
peco-review-bot[bot] marked this conversation as resolved.
|
||
| telemetry.telemetryRetryDelayMs = config.telemetryBackoffBaseMs; | ||
| } else { | ||
| warnRejected('telemetryBackoffBaseMs', config.telemetryBackoffBaseMs, 'zero or greater'); | ||
| } | ||
| if (Number.isFinite(config.telemetryCloseTimeoutMs) && config.telemetryCloseTimeoutMs! > 0) { | ||
| telemetry.telemetryCloseFlushTimeoutMs = config.telemetryCloseTimeoutMs; | ||
| } else { | ||
| warnRejected('telemetryCloseTimeoutMs', config.telemetryCloseTimeoutMs, 'greater than zero'); | ||
| } | ||
| // The napi contract requires threshold/timeout to be strictly positive when | ||
| // supplied. A caller-supplied `0` (or negative) would otherwise be forwarded | ||
| // verbatim and surface as a hard kernel `openSession` rejection, so treat any | ||
| // non-positive value as a misconfiguration and delegate to the kernel default. | ||
| if (Number.isFinite(config.telemetryCircuitBreakerThreshold) && config.telemetryCircuitBreakerThreshold! > 0) { | ||
| telemetry.telemetryCircuitBreakerThreshold = config.telemetryCircuitBreakerThreshold; | ||
| } else { | ||
| warnRejected('telemetryCircuitBreakerThreshold', config.telemetryCircuitBreakerThreshold, 'greater than zero'); | ||
| } | ||
| if (Number.isFinite(config.telemetryCircuitBreakerTimeout) && config.telemetryCircuitBreakerTimeout! > 0) { | ||
| telemetry.telemetryCircuitBreakerTimeoutMs = config.telemetryCircuitBreakerTimeout; | ||
| } else { | ||
| warnRejected('telemetryCircuitBreakerTimeout', config.telemetryCircuitBreakerTimeout, 'greater than zero'); | ||
| } | ||
|
|
||
| return telemetry; | ||
| } | ||
|
|
||
| /** | ||
| * Map the public `ConnectionOptions.proxy` (`{protocol, host, port, auth}` — | ||
| * the same shape the Thrift backend accepts) onto the kernel's structured napi | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Low — This reorders the locale env-var precedence from
LANG > LC_ALL > LC_MESSAGESto POSIXLC_ALL > LC_MESSAGES > LANG. This isDBSQLClient.getLocaleName(), which feeds telemetryDriverConfiguration.localeNameon the Thrift path (kernel telemetry is disabled in the wrapper by this same PR). So beyond the stated "forward kernel telemetry options" scope, this silently changes the reportedlocaleNamefor existing Thrift users who haveLANGset to a different locale thanLC_ALL/LC_MESSAGES. The change is defensible (POSIX precedence is arguably more correct, and it makes the two backends report the same value), but it is a behavior change to a shipping path that isn't called out in the PR description. Flagging so reviewers are aware the impact isn't kernel-only.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is an informational flag ("Flagging so reviewers are aware"), not a request for a code change. The precedence reorder to POSIX (LC_ALL > LC_MESSAGES > LANG) in getLocaleName() is intentional — it aligns the Thrift path with the kernel path's getLocaleName so telemetry localeName is backend-invariant, as documented in the inline comment. The reviewer agrees this is defensible; the only open item is a human judgment call about accepting a behavior change to the shipping Thrift telemetry path (localeName for users whose LANG differs from LC_ALL/LC_MESSAGES) that is outside the PR's stated scope and not noted in the PR description. That needs a maintainer's decision on scope/PR-description, which cannot be actioned as a code edit in this file — escalating for human review.