Skip to content

Commit ce7723a

Browse files
committed
Fix prettier formatting
1 parent bfb8303 commit ce7723a

File tree

6 files changed

+30
-106
lines changed

6 files changed

+30
-106
lines changed

lib/telemetry/CircuitBreaker.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ export class CircuitBreaker {
7070

7171
private readonly config: CircuitBreakerConfig;
7272

73-
constructor(
74-
private context: IClientContext,
75-
config?: Partial<CircuitBreakerConfig>
76-
) {
73+
constructor(private context: IClientContext, config?: Partial<CircuitBreakerConfig>) {
7774
this.config = {
7875
...DEFAULT_CIRCUIT_BREAKER_CONFIG,
7976
...config,
@@ -145,7 +142,7 @@ export class CircuitBreaker {
145142
this.successCount += 1;
146143
logger.log(
147144
LogLevel.debug,
148-
`Circuit breaker success in HALF_OPEN (${this.successCount}/${this.config.successThreshold})`
145+
`Circuit breaker success in HALF_OPEN (${this.successCount}/${this.config.successThreshold})`,
149146
);
150147

151148
if (this.successCount >= this.config.successThreshold) {
@@ -167,19 +164,13 @@ export class CircuitBreaker {
167164
this.failureCount += 1;
168165
this.successCount = 0; // Reset success count on failure
169166

170-
logger.log(
171-
LogLevel.debug,
172-
`Circuit breaker failure (${this.failureCount}/${this.config.failureThreshold})`
173-
);
167+
logger.log(LogLevel.debug, `Circuit breaker failure (${this.failureCount}/${this.config.failureThreshold})`);
174168

175169
if (this.failureCount >= this.config.failureThreshold) {
176170
// Transition to OPEN
177171
this.state = CircuitBreakerState.OPEN;
178172
this.nextAttempt = new Date(Date.now() + this.config.timeout);
179-
logger.log(
180-
LogLevel.debug,
181-
`Circuit breaker transitioned to OPEN (will retry after ${this.config.timeout}ms)`
182-
);
173+
logger.log(LogLevel.debug, `Circuit breaker transitioned to OPEN (will retry after ${this.config.timeout}ms)`);
183174
}
184175
}
185176
}

lib/telemetry/DatabricksTelemetryExporter.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ interface DatabricksTelemetryLog {
7575
*/
7676
interface DatabricksTelemetryPayload {
7777
uploadTime: number;
78-
items: string[]; // Always empty - required field
79-
protoLogs: string[]; // JSON-stringified TelemetryFrontendLog objects
78+
items: string[]; // Always empty - required field
79+
protoLogs: string[]; // JSON-stringified TelemetryFrontendLog objects
8080
}
8181

8282
/**
@@ -104,7 +104,7 @@ export default class DatabricksTelemetryExporter {
104104
private context: IClientContext,
105105
private host: string,
106106
private circuitBreakerRegistry: CircuitBreakerRegistry,
107-
fetchFunction?: typeof fetch
107+
fetchFunction?: typeof fetch,
108108
) {
109109
this.circuitBreaker = circuitBreakerRegistry.getCircuitBreaker(host);
110110
this.fetchFn = fetchFunction || fetch;
@@ -177,13 +177,13 @@ export default class DatabricksTelemetryExporter {
177177
}
178178

179179
// Calculate backoff with exponential + jitter (100ms - 1000ms)
180-
const baseDelay = Math.min(100 * 2**attempt, 1000);
180+
const baseDelay = Math.min(100 * 2 ** attempt, 1000);
181181
const jitter = Math.random() * 100;
182182
const delay = baseDelay + jitter;
183183

184184
logger.log(
185185
LogLevel.debug,
186-
`Retrying telemetry export (attempt ${attempt + 1}/${maxRetries}) after ${Math.round(delay)}ms`
186+
`Retrying telemetry export (attempt ${attempt + 1}/${maxRetries}) after ${Math.round(delay)}ms`,
187187
);
188188

189189
await this.sleep(delay);
@@ -205,8 +205,7 @@ export default class DatabricksTelemetryExporter {
205205
const logger = this.context.getLogger();
206206

207207
// Determine endpoint based on authentication mode
208-
const authenticatedExport =
209-
config.telemetryAuthenticatedExport ?? DEFAULT_TELEMETRY_CONFIG.authenticatedExport;
208+
const authenticatedExport = config.telemetryAuthenticatedExport ?? DEFAULT_TELEMETRY_CONFIG.authenticatedExport;
210209
const endpoint = authenticatedExport
211210
? buildUrl(this.host, '/telemetry-ext')
212211
: buildUrl(this.host, '/telemetry-unauth');
@@ -217,13 +216,15 @@ export default class DatabricksTelemetryExporter {
217216

218217
const payload: DatabricksTelemetryPayload = {
219218
uploadTime: Date.now(),
220-
items: [], // Required but unused
219+
items: [], // Required but unused
221220
protoLogs,
222221
};
223222

224223
logger.log(
225224
LogLevel.debug,
226-
`Exporting ${metrics.length} telemetry metrics to ${authenticatedExport ? 'authenticated' : 'unauthenticated'} endpoint`
225+
`Exporting ${metrics.length} telemetry metrics to ${
226+
authenticatedExport ? 'authenticated' : 'unauthenticated'
227+
} endpoint`,
227228
);
228229

229230
// Get authentication headers if using authenticated endpoint

lib/telemetry/FeatureFlagCache.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ export default class FeatureFlagCache {
8989
return false;
9090
}
9191

92-
const isExpired = !ctx.lastFetched ||
93-
(Date.now() - ctx.lastFetched.getTime() > ctx.cacheDuration);
92+
const isExpired = !ctx.lastFetched || Date.now() - ctx.lastFetched.getTime() > ctx.cacheDuration;
9493

9594
if (isExpired) {
9695
try {
@@ -139,10 +138,7 @@ export default class FeatureFlagCache {
139138
});
140139

141140
if (!response.ok) {
142-
logger.log(
143-
LogLevel.debug,
144-
`Feature flag fetch failed: ${response.status} ${response.statusText}`
145-
);
141+
logger.log(LogLevel.debug, `Feature flag fetch failed: ${response.status} ${response.statusText}`);
146142
return false;
147143
}
148144

@@ -165,10 +161,7 @@ export default class FeatureFlagCache {
165161
// Parse boolean value (can be string "true"/"false")
166162
const value = String(flag.value).toLowerCase();
167163
const enabled = value === 'true';
168-
logger.log(
169-
LogLevel.debug,
170-
`Feature flag ${this.FEATURE_FLAG_NAME}: ${enabled}`
171-
);
164+
logger.log(LogLevel.debug, `Feature flag ${this.FEATURE_FLAG_NAME}: ${enabled}`);
172165
return enabled;
173166
}
174167
}

lib/telemetry/MetricsAggregator.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616

1717
import IClientContext from '../contracts/IClientContext';
1818
import { LogLevel } from '../contracts/IDBSQLLogger';
19-
import {
20-
TelemetryEvent,
21-
TelemetryEventType,
22-
TelemetryMetric,
23-
DEFAULT_TELEMETRY_CONFIG,
24-
} from './types';
19+
import { TelemetryEvent, TelemetryEventType, TelemetryMetric, DEFAULT_TELEMETRY_CONFIG } from './types';
2520
import DatabricksTelemetryExporter from './DatabricksTelemetryExporter';
2621
import ExceptionClassifier from './ExceptionClassifier';
2722

@@ -69,10 +64,7 @@ export default class MetricsAggregator {
6964

7065
private flushIntervalMs: number;
7166

72-
constructor(
73-
private context: IClientContext,
74-
private exporter: DatabricksTelemetryExporter
75-
) {
67+
constructor(private context: IClientContext, private exporter: DatabricksTelemetryExporter) {
7668
try {
7769
const config = context.getConfig();
7870
this.batchSize = config.telemetryBatchSize ?? DEFAULT_TELEMETRY_CONFIG.batchSize;

lib/telemetry/TelemetryEventEmitter.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ export default class TelemetryEventEmitter extends EventEmitter {
4545
*
4646
* @param data Connection event data including sessionId, workspaceId, and driverConfig
4747
*/
48-
emitConnectionOpen(data: {
49-
sessionId: string;
50-
workspaceId: string;
51-
driverConfig: DriverConfiguration;
52-
}): void {
48+
emitConnectionOpen(data: { sessionId: string; workspaceId: string; driverConfig: DriverConfiguration }): void {
5349
if (!this.enabled) return;
5450

5551
const logger = this.context.getLogger();
@@ -73,11 +69,7 @@ export default class TelemetryEventEmitter extends EventEmitter {
7369
*
7470
* @param data Statement start data including statementId, sessionId, and operationType
7571
*/
76-
emitStatementStart(data: {
77-
statementId: string;
78-
sessionId: string;
79-
operationType?: string;
80-
}): void {
72+
emitStatementStart(data: { statementId: string; sessionId: string; operationType?: string }): void {
8173
if (!this.enabled) return;
8274

8375
const logger = this.context.getLogger();

tests/unit/telemetry/CircuitBreaker.test.ts

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ describe('CircuitBreaker', () => {
137137

138138
expect(breaker.getState()).to.equal(CircuitBreakerState.OPEN);
139139
expect(breaker.getFailureCount()).to.equal(5);
140-
expect(
141-
logSpy.calledWith(
142-
LogLevel.debug,
143-
sinon.match(/Circuit breaker transitioned to OPEN/)
144-
)
145-
).to.be.true;
140+
expect(logSpy.calledWith(LogLevel.debug, sinon.match(/Circuit breaker transitioned to OPEN/))).to.be.true;
146141

147142
logSpy.restore();
148143
});
@@ -176,12 +171,7 @@ describe('CircuitBreaker', () => {
176171
} catch {}
177172
}
178173

179-
expect(
180-
logSpy.calledWith(
181-
LogLevel.debug,
182-
sinon.match(/Circuit breaker transitioned to OPEN/)
183-
)
184-
).to.be.true;
174+
expect(logSpy.calledWith(LogLevel.debug, sinon.match(/Circuit breaker transitioned to OPEN/))).to.be.true;
185175

186176
logSpy.restore();
187177
});
@@ -268,12 +258,7 @@ describe('CircuitBreaker', () => {
268258
const successOperation = sinon.stub().resolves('success');
269259
await breaker.execute(successOperation);
270260

271-
expect(
272-
logSpy.calledWith(
273-
LogLevel.debug,
274-
'Circuit breaker transitioned to HALF_OPEN'
275-
)
276-
).to.be.true;
261+
expect(logSpy.calledWith(LogLevel.debug, 'Circuit breaker transitioned to HALF_OPEN')).to.be.true;
277262

278263
logSpy.restore();
279264
});
@@ -358,12 +343,7 @@ describe('CircuitBreaker', () => {
358343
await breaker.execute(operation2);
359344
expect(breaker.getState()).to.equal(CircuitBreakerState.CLOSED);
360345
expect(breaker.getSuccessCount()).to.equal(0); // Reset after closing
361-
expect(
362-
logSpy.calledWith(
363-
LogLevel.debug,
364-
'Circuit breaker transitioned to CLOSED'
365-
)
366-
).to.be.true;
346+
expect(logSpy.calledWith(LogLevel.debug, 'Circuit breaker transitioned to CLOSED')).to.be.true;
367347

368348
logSpy.restore();
369349
});
@@ -442,12 +422,7 @@ describe('CircuitBreaker', () => {
442422
} catch {}
443423
}
444424

445-
expect(
446-
logSpy.calledWith(
447-
LogLevel.debug,
448-
sinon.match(/Circuit breaker transitioned to OPEN/)
449-
)
450-
).to.be.true;
425+
expect(logSpy.calledWith(LogLevel.debug, sinon.match(/Circuit breaker transitioned to OPEN/))).to.be.true;
451426

452427
// Wait for timeout
453428
clock.tick(60001);
@@ -456,22 +431,12 @@ describe('CircuitBreaker', () => {
456431
const successOp = sinon.stub().resolves('success');
457432
await breaker.execute(successOp);
458433

459-
expect(
460-
logSpy.calledWith(
461-
LogLevel.debug,
462-
'Circuit breaker transitioned to HALF_OPEN'
463-
)
464-
).to.be.true;
434+
expect(logSpy.calledWith(LogLevel.debug, 'Circuit breaker transitioned to HALF_OPEN')).to.be.true;
465435

466436
// Close circuit
467437
await breaker.execute(successOp);
468438

469-
expect(
470-
logSpy.calledWith(
471-
LogLevel.debug,
472-
'Circuit breaker transitioned to CLOSED'
473-
)
474-
).to.be.true;
439+
expect(logSpy.calledWith(LogLevel.debug, 'Circuit breaker transitioned to CLOSED')).to.be.true;
475440

476441
// Verify no console logging
477442
expect(logSpy.neverCalledWith(LogLevel.error, sinon.match.any)).to.be.true;
@@ -539,12 +504,7 @@ describe('CircuitBreakerRegistry', () => {
539504

540505
registry.getCircuitBreaker(host);
541506

542-
expect(
543-
logSpy.calledWith(
544-
LogLevel.debug,
545-
`Created circuit breaker for host: ${host}`
546-
)
547-
).to.be.true;
507+
expect(logSpy.calledWith(LogLevel.debug, `Created circuit breaker for host: ${host}`)).to.be.true;
548508

549509
logSpy.restore();
550510
});
@@ -656,12 +616,7 @@ describe('CircuitBreakerRegistry', () => {
656616
registry.getCircuitBreaker(host);
657617
registry.removeCircuitBreaker(host);
658618

659-
expect(
660-
logSpy.calledWith(
661-
LogLevel.debug,
662-
`Removed circuit breaker for host: ${host}`
663-
)
664-
).to.be.true;
619+
expect(logSpy.calledWith(LogLevel.debug, `Removed circuit breaker for host: ${host}`)).to.be.true;
665620

666621
logSpy.restore();
667622
});

0 commit comments

Comments
 (0)