Skip to content
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

chore(api): /api/clean better logging #280

Merged
merged 1 commit into from
Jun 30, 2024
Merged

chore(api): /api/clean better logging #280

merged 1 commit into from
Jun 30, 2024

Conversation

duyet
Copy link
Owner

@duyet duyet commented Jun 30, 2024

Summary by Sourcery

This pull request enhances the /api/clean endpoint by adding detailed logging messages to improve traceability and debugging of the cleanup process.

  • Enhancements:
    • Added detailed logging messages to the /api/clean endpoint to improve traceability of the cleanup process.

Copy link

vercel bot commented Jun 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clickhouse-monitoring ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 30, 2024 9:59am

Copy link
Contributor

sourcery-ai bot commented Jun 30, 2024

Reviewer's Guide by Sourcery

This pull request enhances the logging in the /api/clean route. It adds logs at various stages of the cleanup process, including the start of the cleanup, when there is nothing to clean up, and when the 'LastCleanup' event is created. Additionally, it improves error logging by providing more context.

File-Level Changes

Files Changes
app/api/clean/route.ts Improved logging for the cleanup process in the /api/clean route.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@duyet duyet enabled auto-merge June 30, 2024 09:58
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @duyet - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -67,6 +67,8 @@ async function cleanupHangQuery(
throw new Error(
`Last cleanup was ${lastCleanup} less than ${QUERY_CLEANUP_MAX_DURATION_SECONDS}s`
)
} else {
console.log('[/api/clean] Starting clean up hang queries')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.log

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

@@ -97,6 +99,7 @@ async function cleanupHangQuery(

// Nothing to cleanup
if (!killQueryResp || killQueryResp?.rows === 0) {
console.log('[/api/clean] Done, nothing to cleanup')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.log

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

return { lastCleanup, message: 'Nothing to cleanup' }
} else {
console.error(error)
console.error('[/api/clean] Error when killing queries:', error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.error

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

Suggested change
console.error('[/api/clean] Error when killing queries:', error)
import { Logger } from 'some-logging-library';
const logger = new Logger();
...
logger.error('[/api/clean] Error when killing queries:', error);

@@ -126,7 +130,9 @@ async function cleanupHangQuery(
],
format: 'JSONEachRow',
})
console.log('[/api/clean] LastCleanup event created')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.log

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

} catch (error) {
console.error("[/api/clean] 'LastCleanup' event creating error:", error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.error

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

@duyet duyet merged commit b46175e into main Jun 30, 2024
14 of 15 checks passed
@duyet duyet deleted the chore/ui branch June 30, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant