Skip to content

Commit

Permalink
Release 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zph committed Feb 27, 2024
1 parent 8e2a899 commit 80ed0cc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.2.0"
"version": "0.2.1"
}
49 changes: 25 additions & 24 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"@release-it/bumper": "^6.0.1",
"release-it": "^17.0.1"
},
"version": "0.2.0"
"version": "0.2.1"
}

0 comments on commit 80ed0cc

Please sign in to comment.