Skip to content

Commit

Permalink
refactor: gosec lint
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenschneider committed Jul 10, 2023
1 parent ba0ffc9 commit 448e90e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions internal/metrics/server_metrics.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package metrics

import (
"errors"
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog/log"
"net/http"
)

var (
Expand Down Expand Up @@ -67,9 +70,19 @@ var (
)

func StartMetricsServer(addr string) {
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(addr, nil)
if err != nil {
log.Fatal().Msgf("Can not start metrics server at %s: %v", addr, err)
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())

server := http.Server{
Addr: addr,
Handler: mux,
ReadTimeout: 3 * time.Second,
ReadHeaderTimeout: 3 * time.Second,
WriteTimeout: 3 * time.Second,
IdleTimeout: 30 * time.Second,
}

if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msgf("Can not start metrics server")
}
}

0 comments on commit 448e90e

Please sign in to comment.