-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Refactor healthcheck signalling between server and service #5308
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
Merged
yurishkuro
merged 2 commits into
jaegertracing:main
from
WillSewell:refactor-healthcheck-channels
Mar 28, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,23 +48,23 @@ import ( | |
| // Server runs HTTP, Mux and a grpc server | ||
| type Server struct { | ||
| logger *zap.Logger | ||
| healthCheck *healthcheck.HealthCheck | ||
|
Contributor
Author
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. I felt like this was nicer ordering because this felt related to the logger to me since they both come from the service and are both related to "reporting status". |
||
| querySvc *querysvc.QueryService | ||
| queryOptions *QueryOptions | ||
|
|
||
| tracer *jtracer.JTracer // TODO make part of flags.Service | ||
|
|
||
| conn net.Listener | ||
| grpcConn net.Listener | ||
| httpConn net.Listener | ||
| cmuxServer cmux.CMux | ||
| grpcServer *grpc.Server | ||
| httpServer *http.Server | ||
| separatePorts bool | ||
| unavailableChannel chan healthcheck.Status | ||
| conn net.Listener | ||
| grpcConn net.Listener | ||
| httpConn net.Listener | ||
| cmuxServer cmux.CMux | ||
| grpcServer *grpc.Server | ||
| httpServer *http.Server | ||
| separatePorts bool | ||
| } | ||
|
|
||
| // NewServer creates and initializes Server | ||
| func NewServer(logger *zap.Logger, querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, tracer *jtracer.JTracer) (*Server, error) { | ||
| func NewServer(logger *zap.Logger, healthCheck *healthcheck.HealthCheck, querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, tracer *jtracer.JTracer) (*Server, error) { | ||
| _, httpPort, err := net.SplitHostPort(options.HTTPHostPort) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid HTTP server host:port: %w", err) | ||
|
|
@@ -89,22 +89,17 @@ func NewServer(logger *zap.Logger, querySvc *querysvc.QueryService, metricsQuery | |
| } | ||
|
|
||
| return &Server{ | ||
| logger: logger, | ||
| querySvc: querySvc, | ||
| queryOptions: options, | ||
| tracer: tracer, | ||
| grpcServer: grpcServer, | ||
| httpServer: httpServer, | ||
| separatePorts: grpcPort != httpPort, | ||
| unavailableChannel: make(chan healthcheck.Status), | ||
| logger: logger, | ||
| healthCheck: healthCheck, | ||
| querySvc: querySvc, | ||
| queryOptions: options, | ||
| tracer: tracer, | ||
| grpcServer: grpcServer, | ||
| httpServer: httpServer, | ||
| separatePorts: grpcPort != httpPort, | ||
| }, nil | ||
| } | ||
|
|
||
| // HealthCheckStatus returns health check status channel a client can subscribe to | ||
| func (s Server) HealthCheckStatus() chan healthcheck.Status { | ||
| return s.unavailableChannel | ||
| } | ||
|
|
||
| func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, logger *zap.Logger, tracer *jtracer.JTracer) (*grpc.Server, error) { | ||
| var grpcOpts []grpc.ServerOption | ||
|
|
||
|
|
@@ -292,7 +287,7 @@ func (s *Server) Start() error { | |
| s.logger.Error("Could not start HTTP server", zap.Error(err)) | ||
| } | ||
|
|
||
| s.unavailableChannel <- healthcheck.Unavailable | ||
| s.healthCheck.Set(healthcheck.Unavailable) | ||
| }() | ||
|
|
||
| // Start GRPC server concurrently | ||
|
|
@@ -302,7 +297,7 @@ func (s *Server) Start() error { | |
| if err := s.grpcServer.Serve(s.grpcConn); err != nil { | ||
| s.logger.Error("Could not start GRPC server", zap.Error(err)) | ||
| } | ||
| s.unavailableChannel <- healthcheck.Unavailable | ||
| s.healthCheck.Set(healthcheck.Unavailable) | ||
| }() | ||
|
|
||
| // Start cmux server concurrently. | ||
|
|
@@ -315,7 +310,7 @@ func (s *Server) Start() error { | |
| if err != nil && !strings.Contains(err.Error(), "use of closed network connection") { | ||
| s.logger.Error("Could not start multiplexed server", zap.Error(err)) | ||
| } | ||
| s.unavailableChannel <- healthcheck.Unavailable | ||
| s.healthCheck.Set(healthcheck.Unavailable) | ||
| }() | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.