Skip to content

Commit

Permalink
feat: add monitoring support
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Apr 6, 2023
1 parent 3575c31 commit 9545ca5
Show file tree
Hide file tree
Showing 7 changed files with 819 additions and 589 deletions.
516 changes: 258 additions & 258 deletions .yarn/releases/yarn-3.4.1.cjs → .yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.4.1.cjs
yarnPath: .yarn/releases/yarn-3.5.0.cjs
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
unfisk:
build:
context: .
image: qlever-llc/unfisk
image: qlever/unfisk:${VERSION-build}
restart: unless-stopped
environment:
NODE_TLS_REJECT_UNAUTHORIZED:
Expand Down
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qlever-llc/unfisk",
"version": "2.0.1",
"version": "2.1.0",
"description": "OADA uservice to \"unflatten\" a list into a list of links",
"author": "Alex Layton <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -48,37 +48,38 @@
},
"dependencies": {
"@oada/client": "^4.5.0",
"@oada/pino-debug": "^3.6.1",
"@oada/lib-prom": "^3.8.0",
"@oada/pino-debug": "^3.9.1",
"convict": "^6.2.4",
"debug": "^4.3.4",
"dotenv": "^16.0.3",
"moment": "^2.29.4",
"tslib": "^2.5.0"
},
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@ava/typescript": "^4.0.0",
"@tsconfig/node16": "^1.0.3",
"@types/convict": "^6.1.1",
"@types/debug": "^4.1.7",
"@types/node": "^16.18.12",
"@types/node": "^16.18.23",
"@types/prettier": "^2.7.2",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@yarnpkg/sdks": "^3.0.0-rc.39",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"@yarnpkg/sdks": "^3.0.0-rc.42",
"ava": "5.2.0",
"c8": "^7.12.0",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"c8": "^7.13.0",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-xo": "^0.43.1",
"eslint-config-xo-typescript": "^0.56.0",
"eslint-formatter-pretty": "^4.1.0",
"eslint-config-xo-typescript": "^0.57.0",
"eslint-formatter-pretty": "^5.0.0",
"eslint-import-resolver-node": "^0.3.7",
"eslint-plugin-array-func": "^3.1.8",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-escompat": "^3.3.4",
"eslint-plugin-escompat": "^3.4.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^4.6.0",
"eslint-plugin-github": "^4.7.0",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-no-constructor-bind": "^2.0.4",
Expand All @@ -89,14 +90,14 @@
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-regexp": "^1.12.0",
"eslint-plugin-regexp": "^1.14.0",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-sonarjs": "^0.18.0",
"eslint-plugin-unicorn": "^45.0.2",
"prettier": "^2.8.4",
"typescript": "^4.9.5"
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-unicorn": "^46.0.0",
"prettier": "^2.8.7",
"typescript": "^5.0.3"
},
"packageManager": "yarn@3.4.1",
"packageManager": "yarn@3.5.0",
"volta": {
"node": "16.17.0"
}
Expand Down
30 changes: 20 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import debug from 'debug';
import moment from 'moment';

import { type Change, type OADAClient, connect } from '@oada/client';
import { Counter } from '@oada/lib-prom';

const info = debug('unfisk:info');
const trace = debug('unfisk:trace');
Expand All @@ -35,13 +36,18 @@ const error = debug('unfisk:error');
const fatal = debug('unfisk:fatal');

// Tolerant of https or not https on domain
const domain = config.get('oada.domain').replace(/^https?:\/\//, '');
const domain = config.get('oada.domain');
const tokens = config.get('oada.token');
const flat = config.get('lists.flat');
const unflat = config.get('lists.unflat'); // Day-index will be added to this
const unflatTree = config.get('lists.unflatTree');
const rateLimit = config.get('oada.throttle');

const unflattened = new Counter({
name: 'unflattened_items_total',
help: `Total number of items unflattened from ${flat}`,
});

/**
* Shared OADA client instance?
*/
Expand Down Expand Up @@ -134,15 +140,16 @@ async function ensureAllPathsExist(conn: OADAClient) {
);
}

for await (const token of tokens) {
try {
await unfisk(token);
} catch (cError: unknown) {
fatal({ error: cError }, `Error running unfisk for token ${token}`);
// eslint-disable-next-line no-process-exit, unicorn/no-process-exit
process.exit(1);
}
}
await Promise.race(
tokens.map(async (token) => {
try {
await unfisk(token);
} catch (cError: unknown) {
fatal({ error: cError }, `Error running unfisk for token ${token}`);
throw cError as Error;
}
})
);

/**
* Handle when there is a change to the flat list
Expand Down Expand Up @@ -221,4 +228,7 @@ async function unflatten({
await conn.delete({
path: `${flat}/${id}`,
});

// Update prom counter
unflattened.inc();
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"importHelpers": true,
"alwaysStrict": true,
"strict": true,
"importsNotUsedAsValues": "error",
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitThis": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noErrorTruncation": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "src",
Expand Down
Loading

0 comments on commit 9545ca5

Please sign in to comment.