Fix permetheus query fingerprinting (#24)
Some checks failed
Publish Docker image / Build (push) Successful in 4m42s
Lint / pnpm_install (push) Successful in 1m27s
Test (production install and build) / production (22.11.0) (push) Successful in 1m6s
Test (backend) / unit (22.11.0) (push) Successful in 8m38s
Test (backend) / e2e (22.11.0) (push) Failing after 11m33s
Lint / lint (backend) (push) Successful in 2m38s
Lint / lint (frontend) (push) Successful in 2m32s
Lint / lint (frontend-embed) (push) Successful in 2m33s
Lint / lint (frontend-shared) (push) Successful in 2m30s
Lint / lint (misskey-bubble-game) (push) Successful in 2m29s
Lint / lint (misskey-js) (push) Successful in 2m28s
Lint / lint (misskey-reversi) (push) Successful in 2m25s
Lint / lint (sw) (push) Successful in 2m27s
Lint / typecheck (backend) (push) Successful in 2m26s
Lint / typecheck (misskey-js) (push) Successful in 1m40s
Lint / typecheck (sw) (push) Successful in 1m44s
Some checks failed
Publish Docker image / Build (push) Successful in 4m42s
Lint / pnpm_install (push) Successful in 1m27s
Test (production install and build) / production (22.11.0) (push) Successful in 1m6s
Test (backend) / unit (22.11.0) (push) Successful in 8m38s
Test (backend) / e2e (22.11.0) (push) Failing after 11m33s
Lint / lint (backend) (push) Successful in 2m38s
Lint / lint (frontend) (push) Successful in 2m32s
Lint / lint (frontend-embed) (push) Successful in 2m33s
Lint / lint (frontend-shared) (push) Successful in 2m30s
Lint / lint (misskey-bubble-game) (push) Successful in 2m29s
Lint / lint (misskey-js) (push) Successful in 2m28s
Lint / lint (misskey-reversi) (push) Successful in 2m25s
Lint / lint (sw) (push) Successful in 2m27s
Lint / typecheck (backend) (push) Successful in 2m26s
Lint / typecheck (misskey-js) (push) Successful in 1m40s
Lint / typecheck (sw) (push) Successful in 1m44s
Signed-off-by: eternal-flame-AD <yume@yumechi.jp> <!-- ℹ お読みください / README PRありがとうございます! PRを作成する前に、コントリビューションガイドをご確認ください: Thank you for your PR! Before creating a PR, please check the contribution guide: https://github.com/misskey-dev/misskey/blob/develop/CONTRIBUTING.md --> ## What <!-- このPRで何をしたのか? どう変わるのか? --> <!-- What did you do with this PR? How will it change things? --> ## Why <!-- なぜそうするのか? どういう意図なのか? 何が困っているのか? --> <!-- Why do you do it? What are your intentions? What is the problem? --> ## Additional info (optional) <!-- テスト観点など --> <!-- Test perspective, etc --> ## Checklist - [ ] Read the [contribution guide](https://github.com/misskey-dev/misskey/blob/develop/CONTRIBUTING.md) - [ ] Test working in a local environment - [ ] (If needed) Add story of storybook - [ ] (If needed) Update CHANGELOG.md - [ ] (If possible) Add tests Reviewed-on: #24 Co-authored-by: eternal-flame-AD <yume@yumechi.jp> Co-committed-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
b805239b39
commit
b78edccd19
1 changed files with 5 additions and 12 deletions
|
@ -95,7 +95,6 @@ const sqlLogger = dbLogger.createSubLogger('sql', 'gray');
|
|||
type QueryTagCache = {
|
||||
join: string;
|
||||
from: string;
|
||||
hash: string;
|
||||
};
|
||||
|
||||
function dedupConsecutive<T>(arr: T[]): T[] {
|
||||
|
@ -107,40 +106,34 @@ function simplifyIdentifiers(sql: string) {
|
|||
}
|
||||
|
||||
function extractQueryTags(query: string): QueryTagCache {
|
||||
const joins = query.matchAll(/(LEFT|RIGHT|INNER|OUTER) JOIN ([a-zA-Z0-9_"`.\s]+) ON/ig);
|
||||
const froms = query.matchAll(/FROM ([a-zA-Z0-9_"`.]+)/ig);
|
||||
const joins = query.matchAll(/(LEFT|RIGHT|INNER|OUTER)[\s\S]+JOIN[\s\r\n]+([a-zA-Z0-9_"`.]+)/ig);
|
||||
const froms = query.matchAll(/FROM[\s\r\n]+([a-zA-Z0-9_"`.]+)/ig);
|
||||
|
||||
const join = Array.from(joins).map(j => `${j[1]}:${simplifyIdentifiers(j[2])}`).join('|');
|
||||
const from = dedupConsecutive(Array.from(froms).map(f => simplifyIdentifiers(f[1]))).join('|');
|
||||
|
||||
// this is not for security just to reduce metrics size just for confirmation in local environment
|
||||
// all the code is public there is nothing secret in the query itself
|
||||
const hash = createHash('md5');
|
||||
hash.update(query);
|
||||
|
||||
return {
|
||||
join,
|
||||
from,
|
||||
hash: hash.digest('hex'),
|
||||
};
|
||||
}
|
||||
|
||||
const mQueryCounter = metricCounter({
|
||||
name: 'misskey_postgres_query_total',
|
||||
help: 'Total queries to postgres',
|
||||
labelNames: ['join', 'from', 'hash'],
|
||||
labelNames: ['join', 'from'],
|
||||
});
|
||||
|
||||
const mQueryErrorCounter = metricCounter({
|
||||
name: 'misskey_postgres_query_error_total',
|
||||
help: 'Total errors in queries to postgres',
|
||||
labelNames: ['join', 'from', 'hash'],
|
||||
labelNames: ['join', 'from'],
|
||||
});
|
||||
|
||||
const mSlowQueryHisto = metricHistogram({
|
||||
name: 'misskey_postgres_query_slow_duration_seconds',
|
||||
help: 'Duration of slow queries to postgres',
|
||||
labelNames: ['join', 'from', 'hash'],
|
||||
labelNames: ['join', 'from'],
|
||||
buckets: [0.1, 0.5, 1, 2, 5, 10, 30, 300],
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue