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

flush traces on shutdown #2882

Merged
merged 3 commits into from
Jul 17, 2024
Merged

flush traces on shutdown #2882

merged 3 commits into from
Jul 17, 2024

Conversation

trajan0x
Copy link
Contributor

@trajan0x trajan0x commented Jul 17, 2024

Description

Flushes all traces on shutdown

Summary by CodeRabbit

  • New Features
    • Introduced a graceful shutdown mechanism for the exporter, ensuring all traces are flushed and the system has up to 10 seconds to shut down properly.

Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Walkthrough

The recent updates to the core/metrics package enhance the baseHandler struct by introducing a new field (unwrappedTP) to better manage tracers and resources. The newBaseHandler and related functions were adjusted to incorporate these changes. Additionally, a new handleShutdown function was added to otlp.go for graceful shutdown of the exporter, ensuring all traces are properly flushed.

Changes

Files Change Summary
core/metrics/base.go Modified baseHandler struct by adding unwrappedTP field, reordered fields, and updated functions to handle changes.
core/metrics/otlp.go Introduced handleShutdown function to manage exporter shutdown with proper handling of traces.

Poem

In code's vast garden, new changes bloom,
Enhancing tracers, no more gloom.
With shutdowns handled, traces flush,
The system's grace, a gentle hush.
A rabbit hops, in metrics' light,
Rejoicing in the code's delight. 🌸💡


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Jul 17, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Added unwrappedTP field to baseHandler in /core/metrics/base.go for trace flushing on shutdown
  • Modified newBaseHandler and newBaseHandlerWithTracerProvider in /core/metrics/base.go to handle unwrappedTP
  • Introduced handleShutdown function in /core/metrics/otlp.go for graceful shutdown of traces
  • Updated Start method in /core/metrics/otlp.go to call ForceFlush and Shutdown on context cancellation

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings


// allow only 10 seconds for graceful shutdown.
// we use without cancel to copy the parents values while making sure are derived context is not canceled.
shutdownCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), shutdownAllowance)
Copy link

Choose a reason for hiding this comment

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

Spelling: Typo: 'are' should be 'our'.

Suggested change
shutdownCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), shutdownAllowance)
// we use without cancel to copy the parents values while making sure our derived context is not canceled.

Copy link

cloudflare-workers-and-pages bot commented Jul 17, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1397f8f
Status: ✅  Deploy successful!
Preview URL: https://094f9c8f.sanguine-fe.pages.dev
Branch Preview URL: https://fix-trace-flush.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced graceful shutdown mechanism in /core/metrics/otlp.go
  • Ensured traces are flushed within a 10-second allowance during shutdown
  • Created derived context with timeout for shutdown process

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
core/metrics/otlp.go (1)

66-86: Review of handleShutdown function.

  1. Context Handling: The function waits for the context to be canceled before proceeding with the shutdown, which is a good practice for graceful termination.
  2. Shutdown Timeout: A 10-second timeout is enforced for the shutdown process. This is a reasonable choice to balance between a quick shutdown and giving enough time for operations to complete.
  3. Error Handling: Errors during the flush and shutdown processes are logged but not escalated. This might be acceptable depending on the application's error handling strategy, but it would be wise to consider if there should be further action taken on these errors.
  4. Use of context.WithoutCancel: This is an interesting choice. It ensures that the derived context inherits the values from the parent context without being affected by its cancellation. This is crucial in ensuring that the shutdown process can complete even if the parent context is canceled.

Overall, the function is well-implemented with proper use of contexts and error handling. However, consider the implications of not escalating errors during the shutdown process.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67e255f and d1328bb.

Files selected for processing (2)
  • core/metrics/base.go (3 hunks)
  • core/metrics/otlp.go (2 hunks)
Additional comments not posted (2)
core/metrics/otlp.go (1)

55-58: Initiate graceful shutdown in a separate goroutine.

The implementation correctly starts a separate goroutine to handle the shutdown process. This ensures that the main execution flow is not blocked.

core/metrics/base.go (1)

40-47: Structural changes in baseHandler.

The baseHandler struct now includes the unwrappedTP field, which is used only for shutdown. This is a good separation of concerns, allowing the regular tracer provider to be unaffected by shutdown operations. The reordering of fields and the removal of resource are significant changes that should be verified across the codebase to ensure no side effects.

Verification successful

Verify structural changes in baseHandler.

The structural changes in baseHandler, including the addition of the unwrappedTP field, appear to be consistently integrated across the codebase. The unwrappedTP field is used appropriately for shutdown operations, and the instantiation of baseHandler aligns with the new structure.

  • core/metrics/otlp.go
  • core/metrics/tester.go
  • core/metrics/jaeger.go
  • core/metrics/base.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `baseHandler` across the codebase to ensure no side effects from the structural changes.

# Test: Search for the usage of `baseHandler`. Expect: Consistent usage considering the new structure.
rg --type go -A 5 $'baseHandler'

Length of output: 8217

Comment on lines +211 to +217
unwrappedTP := tracesdk.NewTracerProvider(opts...)
tp := PyroscopeWrapTracerProvider(unwrappedTP, buildInfo)
// will do nothing if not enabled.
StartPyroscope(buildInfo)

propagator := b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader | b3.B3SingleHeader))
return newBaseHandlerWithTracerProvider(rsr, buildInfo, tp, propagator)
return newBaseHandlerWithTracerProvider(rsr, buildInfo, unwrappedTP, tp, propagator)
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of newBaseHandler and newBaseHandlerWithTracerProvider.

  1. Function Signature Changes: The addition of unwrappedTP as a parameter before other tracer-related parameters helps in segregating the shutdown-specific tracer provider from others. This is a strategic design choice to enhance modularity and clarity.
  2. Implementation Details: The function setups are quite complex, involving multiple OpenTelemetry configurations and custom logger setups. It's crucial that these configurations are thoroughly tested, especially since they involve external dependencies and environmental configurations.
  3. Error Handling: There is a TODO comment about handling errors which should be addressed to ensure robustness.

These changes are well thought out but require thorough testing and error handling strategies to be fully effective.

Would you like me to help with implementing the error handling or testing strategies mentioned in the TODO comments?

Also applies to: 243-243

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 23.95059%. Comparing base (ac2fa5d) to head (1397f8f).
Report is 7 commits behind head on master.

Files Patch % Lines
core/metrics/otlp.go 76.00000% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2882         +/-   ##
===================================================
+ Coverage   23.56910%   23.95059%   +0.38148%     
===================================================
  Files            679         628         -51     
  Lines          50842       48408       -2434     
  Branches          80          80                 
===================================================
- Hits           11983       11594        -389     
+ Misses         37536       35664       -1872     
+ Partials        1323        1150        -173     
Flag Coverage Δ
agents ?
cctp-relayer 31.97848% <ø> (ø)
core 60.15156% <80.00000%> (?)
ethergo 48.08619% <ø> (+0.09367%) ⬆️
explorer 4.97877% <ø> (ø)
git-changes-action 23.69615% <ø> (?)
omnirpc 33.23904% <ø> (ø)
opbot 0.18564% <ø> (ø)
promexporter 8.50242% <ø> (?)
rfq 24.76385% <ø> (ø)
screener-api 29.29293% <ø> (?)
scribe 18.17597% <ø> (ø)
tools 30.55118% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added size/s and removed size/xs labels Jul 17, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced graceful shutdown mechanism in /core/metrics/otlp.go
  • Ensured traces are flushed within a 10-second allowance during shutdown
  • Created derived context with timeout for shutdown process

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d1328bb and 80b8e29.

Files selected for processing (1)
  • core/metrics/otlp.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/metrics/otlp.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 80b8e29 and 1397f8f.

Files selected for processing (1)
  • core/metrics/otlp.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/metrics/otlp.go

@trajan0x trajan0x merged commit ca253cf into master Jul 17, 2024
53 checks passed
@trajan0x trajan0x deleted the fix/trace-flush branch July 17, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code needs-go-generate-services/rfq size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant