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

Query service: fix logging errors on SIGINT #1601

Merged
merged 2 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/flags/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func (s *AdminServer) serveWithListener(l net.Listener) {
s.server = &http.Server{Handler: recoveryHandler(s.mux)}
s.logger.Info("Starting admin HTTP server", zap.Int("http-port", s.adminPort))
go func() {
if err := s.server.Serve(l); err != nil {
switch err := s.server.Serve(l); err {
case nil, http.ErrServerClosed:
// normal exit, nothing to do
default:
s.logger.Error("failed to serve", zap.Error(err))
s.hc.Set(healthcheck.Broken)
}
Expand Down
15 changes: 12 additions & 3 deletions cmd/query/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"fmt"
"net"
"net/http"
"strings"

"github.com/gorilla/handlers"
"github.com/opentracing/opentracing-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/soheilhy/cmux"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand Down Expand Up @@ -105,7 +106,11 @@ func (s *Server) Start() error {

go func() {
s.svc.Logger.Info("Starting HTTP server", zap.Int("port", s.queryOptions.Port))
if err := s.httpServer.Serve(httpListener); err != nil {

switch err := s.httpServer.Serve(httpListener); err {
case nil, http.ErrServerClosed, cmux.ErrListenerClosed:
// normal exit, nothing to do
default:
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
s.svc.Logger.Error("Could not start HTTP server", zap.Error(err))
}
s.svc.SetHealthCheckStatus(healthcheck.Unavailable)
Expand All @@ -114,6 +119,7 @@ func (s *Server) Start() error {
// Start GRPC server concurrently
go func() {
s.svc.Logger.Info("Starting GRPC server", zap.Int("port", s.queryOptions.Port))

if err := s.grpcServer.Serve(grpcListener); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this is the same pattern as with the other two servers, but it works fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, grpc doesn't complain. I guess it has to do with how grpc.Serve() is implemented. Unlike with http.Serve(), grpc doesn't throw errors after grpc.Stop()

s.svc.Logger.Error("Could not start GRPC server", zap.Error(err))
}
Expand All @@ -123,7 +129,10 @@ func (s *Server) Start() error {
// Start cmux server concurrently.
go func() {
s.svc.Logger.Info("Starting CMUX server", zap.Int("port", s.queryOptions.Port))
if err := cmuxServer.Serve(); err != nil {

err := cmuxServer.Serve()
// TODO: Remove string comparision when https://github.com/soheilhy/cmux/pull/69 is merged
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
s.svc.Logger.Error("Could not start multiplexed server", zap.Error(err))
}
s.svc.SetHealthCheckStatus(healthcheck.Unavailable)
Expand Down
27 changes: 26 additions & 1 deletion cmd/query/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package app

import (
"fmt"
"testing"
"time"

"github.com/opentracing/opentracing-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"

"github.com/jaegertracing/jaeger/cmd/flags"
"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
Expand Down Expand Up @@ -59,3 +61,26 @@ func TestServer(t *testing.T) {
}
assert.Equal(t, healthcheck.Unavailable, server.svc.HC().Get())
}

func TestServerGracefulExit(t *testing.T) {
flagsSvc := flags.NewService(ports.AgentAdminHTTP)

zapCore, logs := observer.New(zap.ErrorLevel)
assert.Equal(t, 0, logs.Len(), "Expected initial ObservedLogs to have zero length.")

flagsSvc.Logger = zap.New(zapCore)

querySvc := &querysvc.QueryService{}
tracer := opentracing.NoopTracer{}
server := NewServer(flagsSvc, querySvc, &QueryOptions{Port: ports.QueryAdminHTTP}, tracer)
assert.NoError(t, server.Start())

// Wait for servers to come up before we can call .Close()
time.Sleep(1 * time.Second)
server.Close()

for _, logEntry := range logs.All() {
assert.True(t, logEntry.Level != zap.ErrorLevel,
fmt.Sprintf("Error log found on server exit: %v", logEntry))
}
}