|
| 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 | + |
| 17 | +/** |
| 18 | + * Event types emitted by the telemetry system |
| 19 | + */ |
| 20 | +export enum TelemetryEventType { |
| 21 | + CONNECTION_OPEN = 'connection.open', |
| 22 | + STATEMENT_START = 'statement.start', |
| 23 | + STATEMENT_COMPLETE = 'statement.complete', |
| 24 | + CLOUDFETCH_CHUNK = 'cloudfetch.chunk', |
| 25 | + ERROR = 'error', |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Configuration for telemetry components |
| 30 | + */ |
| 31 | +export interface TelemetryConfiguration { |
| 32 | + /** Whether telemetry is enabled */ |
| 33 | + enabled?: boolean; |
| 34 | + |
| 35 | + /** Maximum number of metrics to batch before flushing */ |
| 36 | + batchSize?: number; |
| 37 | + |
| 38 | + /** Interval in milliseconds to flush metrics */ |
| 39 | + flushIntervalMs?: number; |
| 40 | + |
| 41 | + /** Maximum retry attempts for export */ |
| 42 | + maxRetries?: number; |
| 43 | + |
| 44 | + /** Whether to use authenticated export endpoint */ |
| 45 | + authenticatedExport?: boolean; |
| 46 | + |
| 47 | + /** Circuit breaker failure threshold */ |
| 48 | + circuitBreakerThreshold?: number; |
| 49 | + |
| 50 | + /** Circuit breaker timeout in milliseconds */ |
| 51 | + circuitBreakerTimeout?: number; |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Default telemetry configuration values |
| 56 | + */ |
| 57 | +export const DEFAULT_TELEMETRY_CONFIG: Required<TelemetryConfiguration> = { |
| 58 | + enabled: false, // Initially disabled for safe rollout |
| 59 | + batchSize: 100, |
| 60 | + flushIntervalMs: 5000, |
| 61 | + maxRetries: 3, |
| 62 | + authenticatedExport: true, |
| 63 | + circuitBreakerThreshold: 5, |
| 64 | + circuitBreakerTimeout: 60000, // 1 minute |
| 65 | +}; |
| 66 | + |
| 67 | +/** |
| 68 | + * Runtime telemetry event emitted by the driver |
| 69 | + */ |
| 70 | +export interface TelemetryEvent { |
| 71 | + /** Type of the event */ |
| 72 | + eventType: TelemetryEventType | string; |
| 73 | + |
| 74 | + /** Timestamp when the event occurred (milliseconds since epoch) */ |
| 75 | + timestamp: number; |
| 76 | + |
| 77 | + /** Session ID for correlation */ |
| 78 | + sessionId?: string; |
| 79 | + |
| 80 | + /** Statement ID for correlation */ |
| 81 | + statementId?: string; |
| 82 | + |
| 83 | + // Connection-specific fields |
| 84 | + /** Workspace ID */ |
| 85 | + workspaceId?: string; |
| 86 | + |
| 87 | + /** Driver configuration */ |
| 88 | + driverConfig?: DriverConfiguration; |
| 89 | + |
| 90 | + // Statement-specific fields |
| 91 | + /** Type of operation (SELECT, INSERT, etc.) */ |
| 92 | + operationType?: string; |
| 93 | + |
| 94 | + /** Execution latency in milliseconds */ |
| 95 | + latencyMs?: number; |
| 96 | + |
| 97 | + /** Result format (inline, cloudfetch, arrow) */ |
| 98 | + resultFormat?: string; |
| 99 | + |
| 100 | + /** Number of result chunks */ |
| 101 | + chunkCount?: number; |
| 102 | + |
| 103 | + /** Total bytes downloaded */ |
| 104 | + bytesDownloaded?: number; |
| 105 | + |
| 106 | + /** Number of poll operations */ |
| 107 | + pollCount?: number; |
| 108 | + |
| 109 | + // CloudFetch-specific fields |
| 110 | + /** Chunk index in the result set */ |
| 111 | + chunkIndex?: number; |
| 112 | + |
| 113 | + /** Number of bytes in this chunk */ |
| 114 | + bytes?: number; |
| 115 | + |
| 116 | + /** Whether compression was used */ |
| 117 | + compressed?: boolean; |
| 118 | + |
| 119 | + // Error-specific fields |
| 120 | + /** Error name/type */ |
| 121 | + errorName?: string; |
| 122 | + |
| 123 | + /** Error message */ |
| 124 | + errorMessage?: string; |
| 125 | + |
| 126 | + /** Whether the error is terminal (non-retryable) */ |
| 127 | + isTerminal?: boolean; |
| 128 | +} |
| 129 | + |
| 130 | +/** |
| 131 | + * Aggregated telemetry metric for export to Databricks |
| 132 | + */ |
| 133 | +export interface TelemetryMetric { |
| 134 | + /** Type of metric */ |
| 135 | + metricType: 'connection' | 'statement' | 'error'; |
| 136 | + |
| 137 | + /** Timestamp when the metric was created (milliseconds since epoch) */ |
| 138 | + timestamp: number; |
| 139 | + |
| 140 | + /** Session ID for correlation */ |
| 141 | + sessionId?: string; |
| 142 | + |
| 143 | + /** Statement ID for correlation */ |
| 144 | + statementId?: string; |
| 145 | + |
| 146 | + /** Workspace ID */ |
| 147 | + workspaceId?: string; |
| 148 | + |
| 149 | + /** Driver configuration (for connection metrics) */ |
| 150 | + driverConfig?: DriverConfiguration; |
| 151 | + |
| 152 | + /** Execution latency in milliseconds */ |
| 153 | + latencyMs?: number; |
| 154 | + |
| 155 | + /** Result format (inline, cloudfetch, arrow) */ |
| 156 | + resultFormat?: string; |
| 157 | + |
| 158 | + /** Number of result chunks */ |
| 159 | + chunkCount?: number; |
| 160 | + |
| 161 | + /** Total bytes downloaded */ |
| 162 | + bytesDownloaded?: number; |
| 163 | + |
| 164 | + /** Number of poll operations */ |
| 165 | + pollCount?: number; |
| 166 | + |
| 167 | + /** Error name/type */ |
| 168 | + errorName?: string; |
| 169 | + |
| 170 | + /** Error message */ |
| 171 | + errorMessage?: string; |
| 172 | +} |
| 173 | + |
| 174 | +/** |
| 175 | + * Driver configuration metadata collected once per connection |
| 176 | + */ |
| 177 | +export interface DriverConfiguration { |
| 178 | + /** Driver version */ |
| 179 | + driverVersion: string; |
| 180 | + |
| 181 | + /** Driver name */ |
| 182 | + driverName: string; |
| 183 | + |
| 184 | + /** Node.js version */ |
| 185 | + nodeVersion: string; |
| 186 | + |
| 187 | + /** Platform (linux, darwin, win32) */ |
| 188 | + platform: string; |
| 189 | + |
| 190 | + /** OS version */ |
| 191 | + osVersion: string; |
| 192 | + |
| 193 | + // Feature flags |
| 194 | + /** Whether CloudFetch is enabled */ |
| 195 | + cloudFetchEnabled: boolean; |
| 196 | + |
| 197 | + /** Whether LZ4 compression is enabled */ |
| 198 | + lz4Enabled: boolean; |
| 199 | + |
| 200 | + /** Whether Arrow format is enabled */ |
| 201 | + arrowEnabled: boolean; |
| 202 | + |
| 203 | + /** Whether direct results are enabled */ |
| 204 | + directResultsEnabled: boolean; |
| 205 | + |
| 206 | + // Configuration values |
| 207 | + /** Socket timeout in milliseconds */ |
| 208 | + socketTimeout: number; |
| 209 | + |
| 210 | + /** Maximum retry attempts */ |
| 211 | + retryMaxAttempts: number; |
| 212 | + |
| 213 | + /** Number of concurrent CloudFetch downloads */ |
| 214 | + cloudFetchConcurrentDownloads: number; |
| 215 | +} |
| 216 | + |
| 217 | +/** |
| 218 | + * Per-statement metrics aggregated from multiple events |
| 219 | + */ |
| 220 | +export interface StatementMetrics { |
| 221 | + /** Statement ID */ |
| 222 | + statementId: string; |
| 223 | + |
| 224 | + /** Session ID */ |
| 225 | + sessionId: string; |
| 226 | + |
| 227 | + /** Type of operation */ |
| 228 | + operationType?: string; |
| 229 | + |
| 230 | + /** Start timestamp (milliseconds since epoch) */ |
| 231 | + startTime: number; |
| 232 | + |
| 233 | + /** Total execution latency in milliseconds */ |
| 234 | + executionLatencyMs?: number; |
| 235 | + |
| 236 | + /** Number of poll operations */ |
| 237 | + pollCount: number; |
| 238 | + |
| 239 | + /** Total poll latency in milliseconds */ |
| 240 | + pollLatencyMs: number; |
| 241 | + |
| 242 | + /** Result format (inline, cloudfetch, arrow) */ |
| 243 | + resultFormat?: string; |
| 244 | + |
| 245 | + /** Number of CloudFetch chunks downloaded */ |
| 246 | + chunkCount: number; |
| 247 | + |
| 248 | + /** Total bytes downloaded */ |
| 249 | + totalBytesDownloaded: number; |
| 250 | + |
| 251 | + /** Whether compression was used */ |
| 252 | + compressionEnabled?: boolean; |
| 253 | +} |
0 commit comments