Skip to content

Commit

Permalink
fix(pino): better loki support
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Aug 9, 2024
1 parent fb22314 commit 17946bb
Show file tree
Hide file tree
Showing 36 changed files with 1,259 additions and 1,150 deletions.
2 changes: 2 additions & 0 deletions common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
INSPECT: ${INSPECT---inspect=0.0.0.0:9229}
DEBUG: ${DEBUG-*}
PINO_LEVEL: ${PINO_LEVEL-debug}
PINO_LOKI: ~
PINO_LOKI_LEVEL: ~
PROM_HOST: '::'
DEBUG_HIDE_DATE: ~
DEBUG_COLORS: ~
Expand Down
894 changes: 0 additions & 894 deletions oada/.yarn/releases/yarn-4.3.1.cjs

This file was deleted.

925 changes: 925 additions & 0 deletions oada/.yarn/releases/yarn-4.4.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion oada/.yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ packageExtensions:
peerDependencies:
oauth2orize: "*"

yarnPath: .yarn/releases/yarn-4.3.1.cjs
yarnPath: .yarn/releases/yarn-4.4.0.cjs
7 changes: 5 additions & 2 deletions oada/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import regexp from 'eslint-plugin-regexp';
import security from 'eslint-plugin-security';
import sonarjs from 'eslint-plugin-sonarjs';
import unicorn from 'eslint-plugin-unicorn';
import xo from 'eslint-config-xo';
import xoTypescript from 'eslint-config-xo-typescript';

const __filename = fileURLToPath(import.meta.url);

Expand Down Expand Up @@ -70,8 +72,8 @@ export default typescript.config(
'plugin:optimize-regex/recommended',
'plugin:import/recommended',
'plugin:ava/recommended',
'xo',
),
...xo,
),
{
files: ['**/*.{c,m,}ts'],
Expand All @@ -80,8 +82,8 @@ export default typescript.config(
compat.extends(
// 'plugin:github/typescript',
'plugin:import/typescript',
// 'xo-typescript',
),
...xoTypescript
),
],
},
Expand Down Expand Up @@ -303,6 +305,7 @@ export default typescript.config(
argsIgnorePattern: '^_',
},
],
'no-unused-vars': 'off',

'@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
'@typescript-eslint/no-misused-promises': [
Expand Down
4 changes: 2 additions & 2 deletions oada/libs/lib-arangodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"@types/deep-equal": "^1.0.4",
"@types/flat": "^5.0.5",
"@types/json-pointer": "^1.0.34",
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"ava": "6.1.3",
"type-fest": "^4.23.0"
"type-fest": "^4.24.0"
},
"volta": {
"node": "22.5.1"
Expand Down
2 changes: 0 additions & 2 deletions oada/libs/lib-arangodb/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class DatabaseWrapper extends Database {
let tries = 0;
while (++tries) {
try {
// eslint-disable-next-line no-await-in-loop
const res = await super.query<T>(query, { profile, ...options });
if (trace.enabled) {
const { query: aql, ...rest } = query;
Expand All @@ -65,7 +64,6 @@ class DatabaseWrapper extends Database {
`Retrying query due to deadlock (retry #${tries})`,
);

// eslint-disable-next-line no-await-in-loop
await setTimeout(deadlockDelay);
continue;
}
Expand Down
1 change: 0 additions & 1 deletion oada/libs/lib-arangodb/test/resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test('should find parents based on resource id', async (t) => {
const p = await resources.getParents('/resources:default:resources_rock_123');
t.plan(3);

// eslint-disable-next-line no-unreachable-loop
for await (const parent of p) {
t.is(parent.path, '/rocks-index/90j2klfdjss');
t.is(parent.resource_id, 'resources/default:resources_rocks_123');
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/lib-kafka/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@ava/typescript": "^5.0.0",
"@types/convict": "^6.1.6",
"@types/debug": "^4.1.12",
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"@types/uuid": "^10.0.0",
"ava": "6.1.3"
},
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/lib-prom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@types/convict": "^6.1.6",
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"@types/ws": "^8.5.12",
"ava": "6.1.3",
"fastify-plugin": "^4.5.1"
Expand Down
4 changes: 2 additions & 2 deletions oada/libs/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"@oada/types": "^4.0.0",
"@qlever-llc/interface2class": "^1.1.0",
"tslib": "2.6.3",
"type-fest": "^4.23.0",
"type-fest": "^4.24.0",
"xksuid": "^0.0.4"
},
"volta": {
"node": "22.5.1"
},
"devDependencies": {
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"jose": "^5.6.3"
}
}
1 change: 0 additions & 1 deletion oada/libs/models/src/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Authorization extends makeClass<
// @ts-expect-error HACK
constructor(authorization?: Partial<Authorization>);

// eslint-disable-next-line max-params
constructor(
rest: Partial<Authorization> = {},
override readonly sub: string,
Expand Down
1 change: 0 additions & 1 deletion oada/libs/models/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Client extends makeClass<ReadonlyDeep<OmitIndexSignature<Metadata>>>() {
// @ts-expect-error HACK
constructor(client?: Partial<Client>);

// eslint-disable-next-line max-params
constructor(
rest: Partial<Client> = {},

Expand Down
1 change: 0 additions & 1 deletion oada/libs/models/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export
class User extends makeClass<Except<OmitIndexSignature<Claims>, 'sub'>>() {
constructor(user?: Partial<User>);

// eslint-disable-next-line max-params
constructor(
user: Partial<User> = {},
/**
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/pino-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^22.0.2"
"@types/node": "^22.2.0"
},
"peerDependencies": {
"debug": "*"
Expand Down
10 changes: 9 additions & 1 deletion oada/libs/pino-debug/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ function createRootLogger(): Logger {
level,
},
// Use pino-loki if configured
...(loki ? [{ target: 'pino-loki', options: loki, level }] : []),
...(loki
? [
{
target: 'pino-loki',
options: loki,
level: process.env.PINO_LOKI_LEVEL,
},
]
: []),
],
},
redact,
Expand Down
32 changes: 16 additions & 16 deletions oada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,44 @@
"g:pino-pretty": "pino-pretty"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/compat": "^1.1.1",
"@eslint/config-inspector": "^0.5.2",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@eslint/js": "^9.9.0",
"@tsconfig/node20": "^20.1.4",
"@types/eslint": "^9.6.0",
"@types/mocha": "^10.0.7",
"@types/node": "^22.0.2",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@yarnpkg/sdks": "^3.1.3",
"browserslist": "^4.23.2",
"@types/node": "^22.2.0",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"@yarnpkg/sdks": "^3.2.0",
"browserslist": "^4.23.3",
"c8": "^10.1.2",
"eslint": "^9.8.0",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.45.0",
"eslint-config-xo-typescript": "^5.0.0",
"eslint-config-xo": "^0.46.0",
"eslint-config-xo-typescript": "^6.0.0",
"eslint-formatter-pretty": "^6.0.1",
"eslint-import-resolver-node": "^0.3.9",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-array-func": "^5.0.1",
"eslint-plugin-array-func": "^5.0.2",
"eslint-plugin-ava": "^15.0.1",
"eslint-plugin-escompat": "^3.11.0",
"eslint-plugin-escompat": "^3.11.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^5.0.1",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^17.10.1",
"eslint-plugin-n": "^17.10.2",
"eslint-plugin-no-constructor-bind": "^2.0.4",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-no-secrets": "^1.0.2",
"eslint-plugin-notice": "^1.0.0",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.0.0",
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-sonarjs": "^1.0.4",
Expand All @@ -59,7 +59,7 @@
"prettier": "^3.3.3",
"tslib": "2.6.3",
"typescript": "5.5.4",
"typescript-eslint": "^8.0.0",
"typescript-eslint": "^8.0.1",
"update-browserslist-db": "^1.1.0",
"zx": "^8.1.4"
},
Expand All @@ -77,5 +77,5 @@
"volta": {
"node": "22.5.1"
},
"packageManager": "yarn@4.3.1"
"packageManager": "yarn@4.4.0"
}
2 changes: 1 addition & 1 deletion oada/services/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@types/uuid": "^10.0.0",
"c8": "^10.1.2",
"json-schema-to-ts": "^3.1.0",
"type-fest": "^4.23.0"
"type-fest": "^4.24.0"
},
"volta": {
"node": "22.5.1"
Expand Down
1 change: 0 additions & 1 deletion oada/services/auth/src/db/models/deviceCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class DeviceCode {
// @ts-expect-error HACK
constructor(deviceCode?: Partial<DeviceCode>);

// eslint-disable-next-line max-params
constructor(
rest: Partial<DeviceCode> = {},
readonly clientId: string,
Expand Down
1 change: 0 additions & 1 deletion oada/services/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ export async function start(): Promise<void> {
reqId: requestContext.get('id'),
}));

// eslint-disable-next-line new-cap
const fastify = Fastify({
trustProxy,
logger,
Expand Down
2 changes: 0 additions & 2 deletions oada/services/auth/src/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export const issueCode: IssueGrantCodeFunctionArity6 = async (
_,
request: OAuth2Req,
done,
// eslint-disable-next-line max-params
) => {
try {
if (!request.codeChallenge && authCode.pkce.required) {
Expand Down Expand Up @@ -233,7 +232,6 @@ export const exchangeCode: IssueExchangeCodeFunctionArity5<Client> = async (
redirectUri,
{ code_verifier },
done,
// eslint-disable-next-line max-params
) => {
try {
const { payload } = (await jwtDecrypt(code, codeKey, {
Expand Down
1 change: 0 additions & 1 deletion oada/services/auth/src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ const plugin: FastifyPluginAsync<Options> = async (
failWithError: true,
},

// eslint-disable-next-line max-params
async (req, res, error, user, info, status) => {
const cause = error ?? (info instanceof Error ? info : undefined);
request.log[cause ? 'error' : 'trace'](
Expand Down
4 changes: 2 additions & 2 deletions oada/services/http-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@
"@oada/write-handler": "workspace:^",
"@types/cacache": "^17.0.2",
"@types/debug": "^4.1.12",
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"@types/type-is": "^1.6.6",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.12",
"connect": "^3.7.0",
"find-my-way": "^8.2.0",
"light-my-request": "^5.13.0",
"type-fest": "^4.23.0"
"type-fest": "^4.24.0"
},
"volta": {
"node": "22.5.1"
Expand Down
3 changes: 2 additions & 1 deletion oada/services/http-handler/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ declare module '@fastify/jwt' {
}
}
declare module 'fastify-jwt-jwks' {
export interface FastifyJwtJwksOptions extends FastifyJWTOptions {}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface FastifyJwtJwksOptions extends FastifyJWTOptions { }
}

export const decoratorName = 'authenticate';
Expand Down
7 changes: 3 additions & 4 deletions oada/services/http-handler/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ mixins.push(() => ({

const trustProxy = config.get('trustProxy');

// eslint-disable-next-line new-cap
export const fastify = Fastify({
trustProxy,
logger,
Expand Down Expand Up @@ -300,7 +299,7 @@ await fastify.register(formats);
await fastify.register(websockets);

// TODO: Config/logic to decide if iss is trusted
const TRUSTED_ISSUERS = new Set([`${issuer}`]);
const TRUSTED_ISSUERS = new Set([`${issuer}`, config.get('oidc.issuer')]);

// eslint-disable-next-line unicorn/prevent-abbreviations
async function enureOIDCUser({ sub, iss: i, ...rest }: TokenClaims) {
Expand All @@ -327,7 +326,7 @@ async function enureOIDCUser({ sub, iss: i, ...rest }: TokenClaims) {
return u;
}

const user = new User({ ...rest, oidc: [{ sub, iss }] });
const user = new User({ ...rest, sub, oidc: [{ sub, iss }] });
const resp = (await requester.send(
{
connection_id: requestContext.get('id'),
Expand Down Expand Up @@ -362,7 +361,7 @@ await fastify.register(async (instance) => {

const user = await enureOIDCUser(claims);
if (!user) {
request.log.error({ claims }, 'No user for request');
request.log.error({ claims }, 'No user found for request');
return reply.unauthorized();
}

Expand Down
2 changes: 0 additions & 2 deletions oada/services/http-handler/src/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,8 @@ const plugin: FastifyPluginAsync = async (fastify) => {
message.requestId,
);

// eslint-disable-next-line no-await-in-loop
const change = await changes.getChangeArray(resourceId, sendRev);

// eslint-disable-next-line no-await-in-loop
await watch.sendChange({
requestId: [message.requestId],
resourceId,
Expand Down
2 changes: 1 addition & 1 deletion oada/services/permissions-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"@types/type-is": "^1.6.6"
},
"volta": {
Expand Down
4 changes: 2 additions & 2 deletions oada/services/rev-graph-update/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
"@oada/client": "^5.1.0",
"@oada/write-handler": "workspace:^",
"@types/debug": "^4.1.12",
"@types/node": "^22.0.2",
"@types/node": "^22.2.0",
"@types/randomstring": "^1.3.0",
"ava": "6.1.3",
"type-fest": "^4.23.0"
"type-fest": "^4.24.0"
},
"volta": {
"node": "22.5.1"
Expand Down
Loading

0 comments on commit 17946bb

Please sign in to comment.