Skip to content

Commit

Permalink
Avoids shadowing metrics package in httpserver/server.go (#30)
Browse files Browse the repository at this point in the history
* Avoids shadowing metrics package in httpserver/server.go

* Fixes handler.go
  • Loading branch information
Ruteri authored Jul 1, 2024
1 parent e315e3c commit afeb3de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion httpserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (s *Server) handleAPI(w http.ResponseWriter, r *http.Request) {
m := s.metrics.Float64Histogram(
m := s.metricsSrv.Float64Histogram(
"request_duration_api",
"API request handling duration",
metrics.UomMicroseconds,
Expand Down
18 changes: 9 additions & 9 deletions httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ type Server struct {
isReady atomic.Bool
log *slog.Logger

srv *http.Server
metrics *metrics.MetricsServer
srv *http.Server
metricsSrv *metrics.MetricsServer
}

func New(cfg *HTTPServerConfig) (srv *Server, err error) {
metrics, err := metrics.New(common.PackageName, cfg.MetricsAddr)
metricsSrv, err := metrics.New(common.PackageName, cfg.MetricsAddr)
if err != nil {
return nil, err
}

srv = &Server{
cfg: cfg,
log: cfg.Log,
srv: nil,
metrics: metrics,
cfg: cfg,
log: cfg.Log,
srv: nil,
metricsSrv: metricsSrv,
}
srv.isReady.Swap(true)

Expand Down Expand Up @@ -81,7 +81,7 @@ func (s *Server) RunInBackground() {
if s.cfg.MetricsAddr != "" {
go func() {
s.log.With("metricsAddress", s.cfg.MetricsAddr).Info("Starting metrics server")
err := s.metrics.ListenAndServe()
err := s.metricsSrv.ListenAndServe()
if err != nil && !errors.Is(err, http.ErrServerClosed) {
s.log.Error("HTTP server failed", "err", err)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (s *Server) Shutdown() {
ctx, cancel := context.WithTimeout(context.Background(), s.cfg.GracefulShutdownDuration)
defer cancel()

if err := s.metrics.Shutdown(ctx); err != nil {
if err := s.metricsSrv.Shutdown(ctx); err != nil {
s.log.Error("Graceful metrics server shutdown failed", "err", err)
} else {
s.log.Info("Metrics server gracefully stopped")
Expand Down

0 comments on commit afeb3de

Please sign in to comment.