Skip to content

Commit

Permalink
add port to logging and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ohdearaugustin committed May 15, 2020
1 parent 7b2a70a commit 07de03e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cmd/query/app/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Jaeger Authors.
// Copyright (c) 2019,2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,10 +104,10 @@ func (s *Server) Start() error {
if port, err := netutils.GetPort(s.conn.Addr()); err == nil {
tcpPort = port
}
s.svc.Logger.Info("addr", zap.Int("port", tcpPort))

s.svc.Logger.Info(
"Query server started",
zap.Int("port", tcpPort),
zap.String("addr", s.queryOptions.HostPort))

// cmux server acts as a reverse-proxy between HTTP and GRPC backends.
Expand All @@ -120,7 +120,7 @@ func (s *Server) Start() error {
httpListener := cmuxServer.Match(cmux.Any())

go func() {
s.svc.Logger.Info("Starting HTTP server", zap.String("addr", s.queryOptions.HostPort))
s.svc.Logger.Info("Starting HTTP server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HostPort))

switch err := s.httpServer.Serve(httpListener); err {
case nil, http.ErrServerClosed, cmux.ErrListenerClosed:
Expand All @@ -133,7 +133,7 @@ func (s *Server) Start() error {

// Start GRPC server concurrently
go func() {
s.svc.Logger.Info("Starting GRPC server", zap.String("addr", s.queryOptions.HostPort))
s.svc.Logger.Info("Starting GRPC server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HostPort))

if err := s.grpcServer.Serve(grpcListener); err != nil {
s.svc.Logger.Error("Could not start GRPC server", zap.Error(err))
Expand All @@ -143,7 +143,7 @@ func (s *Server) Start() error {

// Start cmux server concurrently.
go func() {
s.svc.Logger.Info("Starting CMUX server", zap.String("addr", s.queryOptions.HostPort))
s.svc.Logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HostPort))

err := cmuxServer.Serve()
// TODO: Remove string comparison when https://github.com/soheilhy/cmux/pull/69 is merged
Expand Down
6 changes: 3 additions & 3 deletions cmd/query/app/server_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Jaeger Authors.
// Copyright (c) 2019,2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -111,14 +111,14 @@ func TestServerHandlesPortZero(t *testing.T) {

querySvc := &querysvc.QueryService{}
tracer := opentracing.NoopTracer{}
server := NewServer(flagsSvc, querySvc, &QueryOptions{Port: 0}, tracer) //Change me
server := NewServer(flagsSvc, querySvc, &QueryOptions{HostPort: ":0"}, tracer) //Change me
assert.NoError(t, server.Start())
server.Close()

message := logs.FilterMessage("Query server started")
assert.Equal(t, 1, message.Len(), "Expected query started log message.")

onlyEntry := message.All()[0]
port := onlyEntry.ContextMap()["port"].(int64)
port := onlyEntry.ContextMap()["port"]
assert.Greater(t, port, int64(0))
}

0 comments on commit 07de03e

Please sign in to comment.