Skip to content

Commit

Permalink
fix(http/log_middleware): fix latency keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sveatlo committed Aug 20, 2021
1 parent c41e2d5 commit c609b4f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion builder_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func WithHTTPListeningAddress(addr string) HTTPOption {
}

// WithGlobalMiddleware adds new global middleware to the HTTP server
// default - metrics, recovery and logging
// default - metrics, logging and recovery (in this order)
func WithGlobalMiddleware(middlware ...gin.HandlerFunc) HTTPOption {
return func(h *httpOptions) error {
h.globalMiddleware = append(h.globalMiddleware, middlware...)
Expand Down
7 changes: 3 additions & 4 deletions cadre.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cadre
import (
"context"
"net"
"net/http"
stdhttp "net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (c *cadre) Start() error {
// start http servers
for port, httpServer := range c.httpServers {
c.swg.Add(1)
go c.startHttpServer(port, httpServer)
go c.startHTTPServer(port, httpServer)
}

// start grpc server
Expand Down Expand Up @@ -105,7 +104,7 @@ func (c *cadre) Shutdown() error {
return nil
}

func (c *cadre) startHttpServer(addr string, httpServer *stdhttp.Server) {
func (c *cadre) startHTTPServer(addr string, httpServer *stdhttp.Server) {
defer c.swg.Done()

c.logger.Debug().
Expand All @@ -119,7 +118,7 @@ func (c *cadre) startHttpServer(addr string, httpServer *stdhttp.Server) {
}()

err := httpServer.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
if err != nil && err != stdhttp.ErrServerClosed {
c.logger.Error().
Err(err).
Msg("http server failed")
Expand Down
4 changes: 2 additions & 2 deletions http/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func NewLogger(baseLogger zerolog.Logger) func(*gin.Context) {
dumplogger := logger.With().
Str("method", c.Request.Method).
Str("path", path).
Dur("latency_ms", latency). // keep this for log aggregation, where number is better than user-readable string
Str("latency", latency.String()). // user-readable latency
Dur("latency", latency). // keep this for log aggregation, where number is better than user-readable string
Str("latency_str", latency.String()). // user-readable latency
Int("status_code", c.Writer.Status()).
Str("ip", c.ClientIP()).Logger()

Expand Down
5 changes: 4 additions & 1 deletion lb/shard/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package shard

const Name = "shard"
const DefaultShardKeyName = "shard_key"

type ShardLBCtxKeyType string

const DefaultShardKeyName ShardLBCtxKeyType = "shard_key"

0 comments on commit c609b4f

Please sign in to comment.