-
Notifications
You must be signed in to change notification settings - Fork 31
chore: defer machine ID resolution #161
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
80e71af
fix
gagik 9022a61
fix: use non-native dependency and defer machine ID resolution
gagik 2dfb0a1
fix: always handle process rejections
gagik ab2909e
fix: close telemetry
gagik 79c8d16
fix: remove UUID check
gagik cbb905c
fix: resolve instead of reject in case of timeout
gagik 9be3e12
fix: remove ESLint warnings
gagik 5348a3a
fix: use npm with inspect
gagik c869d63
fix: remove jest types
gagik e0339a4
fix: use proper ESM with jest
gagik 80bc86e
Merge branch 'gagik/esm-jest' of github.com:mongodb-js/mongodb-mcp-se…
gagik 189e97d
wip
gagik 8575d9a
fix: adjust mocks to fit ESM
gagik 9d49948
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into …
gagik 5d981ee
fix: changes from feedback
gagik 89c3568
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into …
gagik bc57a97
fix: remove old implementation
gagik 8816bef
fix: remove assertions
gagik c611836
Merge branch 'main' into gagik/use-machine-id
gagik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
type DeferredPromiseOptions<T> = { | ||
timeout?: number; | ||
onTimeout?: (resolve: (value: T) => void, reject: (reason: Error) => void) => void; | ||
}; | ||
|
||
/** Creates a promise and exposes its resolve and reject methods, with an optional timeout. */ | ||
export class DeferredPromise<T> extends Promise<T> { | ||
resolve: (value: T) => void; | ||
reject: (reason: unknown) => void; | ||
private timeoutId?: NodeJS.Timeout; | ||
|
||
constructor( | ||
executor: (resolve: (value: T) => void, reject: (reason: Error) => void) => void, | ||
{ timeout, onTimeout }: DeferredPromiseOptions<T> = {} | ||
) { | ||
let resolveFn: (value: T) => void; | ||
let rejectFn: (reason?: unknown) => void; | ||
|
||
super((resolve, reject) => { | ||
resolveFn = resolve; | ||
rejectFn = reject; | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
this.resolve = resolveFn!; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
this.reject = rejectFn!; | ||
|
||
if (timeout !== undefined && onTimeout) { | ||
this.timeoutId = setTimeout(() => { | ||
onTimeout(this.resolve, this.reject); | ||
}, timeout); | ||
} | ||
|
||
executor( | ||
(value: T) => { | ||
if (this.timeoutId) clearTimeout(this.timeoutId); | ||
this.resolve(value); | ||
}, | ||
(reason: Error) => { | ||
if (this.timeoutId) clearTimeout(this.timeoutId); | ||
this.reject(reason); | ||
} | ||
); | ||
} | ||
|
||
static fromPromise<T>(promise: Promise<T>, options: DeferredPromiseOptions<T> = {}): DeferredPromise<T> { | ||
return new DeferredPromise<T>((resolve, reject) => { | ||
promise | ||
.then((value) => { | ||
resolve(value); | ||
}) | ||
.catch((reason) => { | ||
reject(reason as Error); | ||
}); | ||
}, options); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createHmac } from "crypto"; | ||
import { Telemetry } from "../../src/telemetry/telemetry.js"; | ||
import { Session } from "../../src/session.js"; | ||
import { config } from "../../src/config.js"; | ||
import nodeMachineId from "node-machine-id"; | ||
|
||
describe("Telemetry", () => { | ||
it("should resolve the actual machine ID", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access | ||
const actualId: string = await nodeMachineId.machineId(true); | ||
|
||
const actualHashedId = createHmac("sha256", actualId.toUpperCase()).update("atlascli").digest("hex"); | ||
|
||
const telemetry = Telemetry.create( | ||
new Session({ | ||
apiBaseUrl: "", | ||
}), | ||
config | ||
); | ||
|
||
expect(telemetry.getCommonProperties().device_id).toBe(undefined); | ||
expect(telemetry["isBufferingEvents"]).toBe(true); | ||
|
||
await telemetry.deviceIdPromise; | ||
|
||
expect(telemetry.getCommonProperties().device_id).toBe(actualHashedId); | ||
expect(telemetry["isBufferingEvents"]).toBe(false); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,6 @@ export function setupMongoDBIntegrationTest(): MongoDBIntegrationTest { | |
let dbsDir = path.join(tmpDir, "mongodb-runner", "dbs"); | ||
for (let i = 0; i < 10; i++) { | ||
try { | ||
// TODO: Fix this type once mongodb-runner is updated. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call | ||
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. drive-by |
||
mongoCluster = await MongoCluster.start({ | ||
tmpDir: dbsDir, | ||
logDir: path.join(tmpDir, "mongodb-runner", "logs"), | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
while this is not asyncronous. I'm using
create(...)
to make it clear there are associated side effects