-
Notifications
You must be signed in to change notification settings - Fork 613
chore: more logging and retries #2475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,7 +142,19 @@ export class KeyService { | |||||||||
| > | ||||||||||
| > { | ||||||||||
| try { | ||||||||||
| const res = await this._verifyKey(c, req); | ||||||||||
| let res = await this._verifyKey(c, req); | ||||||||||
| let remainingRetries = 3; | ||||||||||
| while (res.err && remainingRetries > 0) { | ||||||||||
| remainingRetries--; | ||||||||||
| this.logger.warn("retrying verification", { | ||||||||||
| remainingRetries, | ||||||||||
| previousError: res.err.message, | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| await this.cache.keyByHash.remove(await this.hash(req.key)); | ||||||||||
| res = await this._verifyKey(c, req); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (res.err) { | ||||||||||
| this.metrics.emit({ | ||||||||||
| metric: "metric.key.verification", | ||||||||||
|
|
@@ -209,7 +221,7 @@ export class KeyService { | |||||||||
| async () => | ||||||||||
| this.cache.keyByHash.swr(keyHash, async (hash) => { | ||||||||||
| const dbStart = performance.now(); | ||||||||||
| const dbRes = await this.db.readonly.query.keys.findFirst({ | ||||||||||
| const query = this.db.readonly.query.keys.findFirst({ | ||||||||||
| where: (table, { and, eq, isNull }) => | ||||||||||
| and(eq(table.hash, hash), isNull(table.deletedAt)), | ||||||||||
| with: { | ||||||||||
|
|
@@ -257,10 +269,14 @@ export class KeyService { | |||||||||
| }, | ||||||||||
| }, | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const dbRes = await query; | ||||||||||
| this.metrics.emit({ | ||||||||||
| metric: "metric.db.read", | ||||||||||
| query: "getKeyAndApiByHash", | ||||||||||
| latency: performance.now() - dbStart, | ||||||||||
| dbRes: JSON.stringify(dbRes), | ||||||||||
| sql: query.toSQL().sql, | ||||||||||
|
Comment on lines
+278
to
+279
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Sensitive Data Exposure in Logs Logging the entire database response ( Consider sanitizing or limiting the data being logged to exclude sensitive information. Instead of logging the full this.metrics.emit({
metric: "metric.db.read",
query: "getKeyAndApiByHash",
latency: performance.now() - dbStart,
- dbRes: JSON.stringify(dbRes),
- sql: query.toSQL().sql,
+ resultSize: dbRes ? 1 : 0,
+ queryInfo: { /* include non-sensitive query details if necessary */ },
});📝 Committable suggestion
Suggested change
|
||||||||||
| }); | ||||||||||
| if (!dbRes?.keyAuth?.api) { | ||||||||||
| return null; | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant Retry Mechanisms in
verifyKeyand_verifyKeyThe
verifyKeymethod introduces a retry loop that attempts to call_verifyKeyup to three times if an error occurs. However, the_verifyKeymethod already includes its own retry logic when fetching key data from the cache and database using theretryfunction.This redundancy could lead to unnecessary duplication of retries, increasing the overall number of attempts and potentially prolonging response times. Consider consolidating the retry logic to a single location to improve efficiency. You might handle retries either in
verifyKeyor within_verifyKey, but not both.