-
Notifications
You must be signed in to change notification settings - Fork 85
chore: reinstate telemetry/docker change after revert MCP-49 #339
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 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||||
import { EventCache } from "./eventCache.js"; | ||||||
import nodeMachineId from "node-machine-id"; | ||||||
import { getDeviceId } from "@mongodb-js/device-id"; | ||||||
import fs from "fs/promises"; | ||||||
|
||||||
type EventResult = { | ||||||
success: boolean; | ||||||
|
@@ -18,7 +19,7 @@ | |||||
export class Telemetry { | ||||||
private isBufferingEvents: boolean = true; | ||||||
/** Resolves when the device ID is retrieved or timeout occurs */ | ||||||
public deviceIdPromise: Promise<string> | undefined; | ||||||
public dataPromise: Promise<[string, boolean]> | undefined; | ||||||
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.
Suggested change
super nit, just may be a nicer name |
||||||
private deviceIdAbortController = new AbortController(); | ||||||
private eventCache: EventCache; | ||||||
private getRawMachineId: () => Promise<string>; | ||||||
|
@@ -52,12 +53,33 @@ | |||||
return instance; | ||||||
} | ||||||
|
||||||
private async isContainerEnv(): Promise<boolean> { | ||||||
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. [nitpick] Consider using Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. wouldn't have thought of this myself but that is a good point 🤖 |
||||||
if (process.platform !== "linux") { | ||||||
return false; // we only support linux containers for now | ||||||
} | ||||||
|
||||||
if (process.env.container) { | ||||||
return true; | ||||||
} | ||||||
|
||||||
const exists = await Promise.all(["/.dockerenv", "/run/.containerenv", "/var/run/.containerenv"].map(async (file) => { | ||||||
try { | ||||||
await fs.access(file); | ||||||
return true; | ||||||
} catch { | ||||||
return false; | ||||||
} | ||||||
})); | ||||||
|
||||||
return exists.includes(true); | ||||||
} | ||||||
|
||||||
private async start(): Promise<void> { | ||||||
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.
Suggested change
|
||||||
if (!this.isTelemetryEnabled()) { | ||||||
return; | ||||||
} | ||||||
this.deviceIdPromise = getDeviceId({ | ||||||
this.dataPromise = Promise.all([getDeviceId({ | ||||||
getMachineId: () => this.getRawMachineId(), | ||||||
onError: (reason, error) => { | ||||||
switch (reason) { | ||||||
case "resolutionError": | ||||||
|
@@ -72,9 +94,12 @@ | |||||
} | ||||||
}, | ||||||
abortSignal: this.deviceIdAbortController.signal, | ||||||
}); | ||||||
}), this.isContainerEnv()]); | ||||||
|
||||||
const [deviceId, containerEnv] = await this.dataPromise; | ||||||
|
||||||
this.commonProperties.device_id = await this.deviceIdPromise; | ||||||
this.commonProperties.device_id = deviceId; | ||||||
this.commonProperties.is_container_env = containerEnv; | ||||||
|
||||||
this.isBufferingEvents = false; | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -219,7 +219,7 @@ describe("Telemetry", () => { | |||||
expect(telemetry["isBufferingEvents"]).toBe(true); | ||||||
expect(telemetry.getCommonProperties().device_id).toBe(undefined); | ||||||
|
||||||
await telemetry.deviceIdPromise; | ||||||
await telemetry.dataPromise; | ||||||
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.
Suggested change
|
||||||
|
||||||
expect(telemetry["isBufferingEvents"]).toBe(false); | ||||||
expect(telemetry.getCommonProperties().device_id).toBe(hashedMachineId); | ||||||
|
@@ -235,7 +235,7 @@ describe("Telemetry", () => { | |||||
expect(telemetry["isBufferingEvents"]).toBe(true); | ||||||
expect(telemetry.getCommonProperties().device_id).toBe(undefined); | ||||||
|
||||||
await telemetry.deviceIdPromise; | ||||||
await telemetry.dataPromise; | ||||||
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.
Suggested change
|
||||||
|
||||||
expect(telemetry["isBufferingEvents"]).toBe(false); | ||||||
expect(telemetry.getCommonProperties().device_id).toBe("unknown"); | ||||||
|
@@ -263,7 +263,7 @@ describe("Telemetry", () => { | |||||
|
||||||
jest.advanceTimersByTime(DEVICE_ID_TIMEOUT); | ||||||
|
||||||
await telemetry.deviceIdPromise; | ||||||
await telemetry.dataPromise; | ||||||
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.
Suggested change
|
||||||
|
||||||
expect(telemetry.getCommonProperties().device_id).toBe("unknown"); | ||||||
expect(telemetry["isBufferingEvents"]).toBe(false); | ||||||
|
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.