Skip to content

Commit

Permalink
chore(logging): add more context on errors from http servers
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <[email protected]>
  • Loading branch information
jakubdyszkiewicz committed Dec 5, 2023
1 parent fd45311 commit e03bc0e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/kuma-dp/pkg/dataplane/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync"
"time"

"github.com/bakito/go-log-logr-adapter/adapter"
"github.com/pkg/errors"
"github.com/prometheus/common/expfmt"

Expand Down Expand Up @@ -137,6 +138,7 @@ func (s *Hijacker) Start(stop <-chan struct{}) error {
server := &http.Server{
ReadHeaderTimeout: time.Second,
Handler: s,
ErrorLog: adapter.ToStd(logger),
}

errCh := make(chan error)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/Nordix/simple-ipam v1.0.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/bakito/go-log-logr-adapter v0.0.2
github.com/cilium/ebpf v0.12.3
github.com/containernetworking/cni v1.1.2
github.com/containernetworking/plugins v1.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/aws/aws-sdk-go v1.44.187 h1:D5CsRomPnlwDHJCanL2mtaLIcbhjiWxNh5j8zvaWdJA=
github.com/aws/aws-sdk-go v1.44.187/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/bakito/go-log-logr-adapter v0.0.2 h1:epK+VaMPkK7dK+Vs78xo0BABqN1lIXD3IXX1VUj4PcM=
github.com/bakito/go-log-logr-adapter v0.0.2/go.mod h1:B2tvB31L1Sxpkfhpj13QkJEisDNNKcC9FoYU8KL87AA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
Expand Down
3 changes: 3 additions & 0 deletions pkg/api-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strings"
"time"

"github.com/bakito/go-log-logr-adapter/adapter"
"github.com/emicklei/go-restful/v3"
"github.com/pkg/errors"
http_prometheus "github.com/slok/go-http-metrics/metrics/prometheus"
Expand Down Expand Up @@ -348,6 +349,7 @@ func (a *ApiServer) startHttpServer(errChan chan error) *http.Server {
ReadHeaderTimeout: time.Second,
Addr: net.JoinHostPort(a.config.HTTP.Interface, strconv.FormatUint(uint64(a.config.HTTP.Port), 10)),
Handler: a.mux,
ErrorLog: adapter.ToStd(log),
}

go func() {
Expand Down Expand Up @@ -390,6 +392,7 @@ func (a *ApiServer) startHttpsServer(errChan chan error) (*http.Server, error) {
Addr: net.JoinHostPort(a.config.HTTPS.Interface, strconv.FormatUint(uint64(a.config.HTTPS.Port), 10)),
Handler: a.mux,
TLSConfig: tlsConfig,
ErrorLog: adapter.ToStd(log),
}

go func() {
Expand Down
8 changes: 7 additions & 1 deletion pkg/diagnostics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
pprof "net/http/pprof"
"time"

"github.com/bakito/go-log-logr-adapter/adapter"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"

Expand Down Expand Up @@ -51,7 +52,12 @@ func (s *diagnosticsServer) Start(stop <-chan struct{}) error {
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

httpServer := &http.Server{Addr: fmt.Sprintf(":%d", s.config.ServerPort), Handler: mux, ReadHeaderTimeout: time.Second}
httpServer := &http.Server{
Addr: fmt.Sprintf(":%d", s.config.ServerPort),
Handler: mux,
ReadHeaderTimeout: time.Second,
ErrorLog: adapter.ToStd(diagnosticsServerLog),
}

if s.config.TlsEnabled {
cert, err := tls.LoadX509KeyPair(s.config.TlsCertFile, s.config.TlsKeyFile)
Expand Down
2 changes: 2 additions & 0 deletions pkg/dp-server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/bakito/go-log-logr-adapter/adapter"
http_prometheus "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
"github.com/slok/go-http-metrics/middleware/std"
Expand Down Expand Up @@ -88,6 +89,7 @@ func (d *DpServer) Start(stop <-chan struct{}) error {
Addr: fmt.Sprintf(":%d", d.config.Port),
Handler: http.HandlerFunc(d.handle),
TLSConfig: tlsConfig,
ErrorLog: adapter.ToStd(log),
}

errChan := make(chan error)
Expand Down
2 changes: 2 additions & 0 deletions pkg/mads/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/bakito/go-log-logr-adapter/adapter"
"github.com/emicklei/go-restful/v3"
"github.com/pkg/errors"
http_prometheus "github.com/slok/go-http-metrics/metrics/prometheus"
Expand Down Expand Up @@ -154,6 +155,7 @@ func (s *muxServer) Start(stop <-chan struct{}) error {
httpS := &http.Server{
ReadHeaderTimeout: time.Second,
Handler: s.createHttpServicesHandler(),
ErrorLog: adapter.ToStd(log),
}
errChanHttp := make(chan error)
go func() {
Expand Down

0 comments on commit e03bc0e

Please sign in to comment.