Skip to content

Conversation

@leoparente
Copy link
Contributor

This pull request refactors the server startup and shutdown logic for the otlpinf service to improve error handling and resource management. The main change is switching the startup method to return an error channel, allowing asynchronous error reporting and cleaner shutdown procedures. The tests have also been updated to accommodate this new pattern and ensure proper cleanup.

Server startup and shutdown improvements:

  • Refactored OltpInf.Start to return a channel of errors instead of a single error, enabling asynchronous error handling and reporting during server startup and runtime. (otlpinf/otlpinf.go, cmd/main.go) [1] [2]
  • Updated OltpInf.Stop to gracefully shut down the HTTP server and clean up temporary resources, ensuring all resources are properly released. (otlpinf/otlpinf.go)
  • Modified startServer to use Go's http.Server for better control over server lifecycle and error propagation, replacing the previous synchronous start logic. (otlpinf/server.go)

Testing improvements:

  • Refactored all tests to use the new error channel returned by Start, adding proper cleanup logic and error assertions to verify server startup and shutdown behavior. (otlpinf/otlpinf_test.go) [1] [2] [3]
  • Improved resource cleanup in tests by using t.Cleanup and ensuring all server errors are logged and handled. (otlpinf/otlpinf_test.go) [1] [2]

Minor code improvements:

  • Added missing imports and minor variable initializations to support the new server logic and error handling. (otlpinf/otlpinf.go, otlpinf/server.go, otlpinf/otlpinf_test.go) [1] [2] [3]

@leoparente leoparente self-assigned this Oct 2, 2025
@github-actions
Copy link

github-actions bot commented Oct 2, 2025

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 6.08s github.com/netboxlabs/opentelemetry-infinity/otlpinf 79.5% 4 0 0
🟢 PASS 3.43s github.com/netboxlabs/opentelemetry-infinity/runner 65.8% 5 0 0

Total coverage: 73.0%

jajeffries
jajeffries previously approved these changes Oct 3, 2025
Copy link

@jajeffries jajeffries left a comment

Choose a reason for hiding this comment

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

LGTM

@leoparente leoparente requested a review from Copilot October 3, 2025 17:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the otlpinf service to improve error handling and resource management by implementing asynchronous server startup and graceful shutdown procedures. The main change switches the startup method to return an error channel for asynchronous error reporting.

  • Refactored Start method to return an error channel instead of a direct error
  • Implemented graceful HTTP server shutdown with proper timeout and cleanup
  • Updated all tests to handle the new asynchronous startup pattern

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
otlpinf/server.go Replaced synchronous server startup with async pattern using http.Server and error channel
otlpinf/otlpinf.go Modified Start to return error channel and enhanced Stop with graceful shutdown logic
otlpinf/otlpinf_test.go Updated tests to handle async startup pattern with proper cleanup and error handling
cmd/main.go Added error channel handling and background goroutine for server error monitoring

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@leoparente leoparente merged commit bd526c8 into main Oct 7, 2025
6 checks passed
@leoparente leoparente deleted the chore/gracefully-shutdown branch October 7, 2025 14:55
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.

2 participants