diff --git a/CHANGELOG.md b/CHANGELOG.md index cb845e9..7bf130d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [0.2.1](https://github.com/zph/msh/compare/0.2.0...0.2.1) + +- Add behavior to avoid errors when one or more nodes down [`b500c8a`](https://github.com/zph/msh/commit/b500c8a61996f1e084d786c73b911d25d6d62806) +- Fix ts linting errors during build [`8e2a899`](https://github.com/zph/msh/commit/8e2a8999fe2f37afa952c0be21ccc3eb4d6e9b21) +- Lint [`7355eec`](https://github.com/zph/msh/commit/7355eecd11d5d4c65cbee0a7609c9cbdaee68136) + #### [0.2.0](https://github.com/zph/msh/compare/0.1.3...0.2.0) +> 27 February 2024 + - Add debug logging [`5d7de09`](https://github.com/zph/msh/commit/5d7de097c973714186fd2be0e82ea9231c430d31) - Remove no longer used import [`7bda8b2`](https://github.com/zph/msh/commit/7bda8b2bcaf268cfcf2e24798925f3c159e035f7) +- Release 0.2.0 [`8725ec1`](https://github.com/zph/msh/commit/8725ec1ba1ec71b2c8af8cf1cd42588a3f3696d8) #### [0.1.3](https://github.com/zph/msh/compare/0.1.2...0.1.3) diff --git a/config.json b/config.json index 10e64e0..b7938ce 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,3 @@ { - "version": "0.2.0" + "version": "0.2.1" } diff --git a/main.ts b/main.ts index 0443708..5fa08a8 100644 --- a/main.ts +++ b/main.ts @@ -104,12 +104,12 @@ const getShardMap = async (envName: string) => { }?authSource=${MONGO_AUTH_DB}`; logger.debug("getShardMap", { fn: "getShardMap", uri }); - let result + let result; try { const client = new MongoClient(uri); result = await client.db("admin").command({ getShardMap: 1 }); } catch (error) { - logger.warn(`Error on ${envName}`, {error, MONGO_USER, MONGO_AUTH_DB}) + logger.warn(`Error on ${envName}`, { error, MONGO_USER, MONGO_AUTH_DB }); } return result?.map; }; @@ -146,11 +146,11 @@ const mainPrompted = async (envName: string) => { const allShards = nodes.map(([_k, v]) => { // "rs-N/rs1-0:27017,rs1-1:27017,rs1-2:27017" - const [rs, connection] = v.split("/") - return {rs, connection} as Shard - }) + const [rs, connection] = v.split("/"); + return { rs, connection } as Shard; + }); - const shardURIs = _.uniqBy(allShards, (s: Shard) => (s.rs)) + const shardURIs = _.uniqBy(allShards, (s: Shard) => (s.rs)); type Node = { rs: string; @@ -159,21 +159,22 @@ const mainPrompted = async (envName: string) => { }; const nodeRespondedOnPort = async (node: string, port: string) => { - const result = await $`nc -z ${node} ${port}`.stdout("piped").noThrow().quiet() - if(result.code === 0) { - return true + const result = await $`nc -z ${node} ${port}`.stdout("piped").noThrow() + .quiet(); + if (result.code === 0) { + return true; } - return false - } + return false; + }; // Fails if any of the nodes is unreachable on the port // So we work around that by trying one node at a time // first with netcat and then with the actual connection // See issue: https://github.com/denoland/deno/issues/11595 - const replSetGetStatus = async ({rs, connection}: Shard) => { + const replSetGetStatus = async ({ rs, connection }: Shard) => { const oneNode = await connection.split(",").find(async (c) => { - const [node, port] = c.split(":") - return await nodeRespondedOnPort(node, port) - }) + const [node, port] = c.split(":"); + return await nodeRespondedOnPort(node, port); + }); // NOTE: ?authenticationDatabase=admin is equivalent to authSource when using driver :shrug: const uri = `mongodb://${ buildAuthURI(MONGO_USER, MONGO_PASSWORD) @@ -182,25 +183,25 @@ const mainPrompted = async (envName: string) => { try { const client = new MongoClient(uri); logger.debug("mainPrompt client instantiated", { uri }); - const db = client.db("admin") + const db = client.db("admin"); logger.debug("mainPrompt db instance"); - return await db.command({ replSetGetStatus: 1 }) + return await db.command({ replSetGetStatus: 1 }); } catch (error) { - logger.error(error) + logger.error(error); } - } + }; const allNodes: Node[] = []; for await (const n of shardURIs) { - const result = await replSetGetStatus(n).catch(e => + const result = await replSetGetStatus(n).catch((e) => logger.error("Error getting connection", e) - ) as Document + ) as Document; // Try to guard against a single node going down and breaking connectivity - if(result === undefined) { - continue + if (result === undefined) { + continue; } // deno-lint-ignore no-explicit-any const all = result.members.map((e: any) => { - return {rs: n.rs, name: e.name as string, state: e.stateStr }; + return { rs: n.rs, name: e.name as string, state: e.stateStr }; }); allNodes.push(all); } diff --git a/package-lock.json b/package-lock.json index 074fc29..6124e80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "@release-it/bumper": "^6.0.1", "release-it": "^17.0.1" }, - "version": "0.2.0" + "version": "0.2.1" }, "node_modules/@babel/code-frame": { "version": "7.23.5", @@ -5511,5 +5511,5 @@ } } }, - "version": "0.2.0" + "version": "0.2.1" } diff --git a/package.json b/package.json index f19a6a9..47f0ada 100644 --- a/package.json +++ b/package.json @@ -3,5 +3,5 @@ "@release-it/bumper": "^6.0.1", "release-it": "^17.0.1" }, - "version": "0.2.0" + "version": "0.2.1" }