Private
Public Access
1
0

data-api: fix health check shutdown; adjust db idle reset feature
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-01-03 14:28:36 +01:00
parent d206f9d20e
commit 9fb3edacef
4 changed files with 8 additions and 3 deletions

2
go.mod
View File

@@ -16,7 +16,7 @@ require (
github.com/spf13/cobra v1.8.1 github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0 github.com/stretchr/testify v1.10.0
go.ntppool.org/api v0.3.4 go.ntppool.org/api v0.3.4
go.ntppool.org/common v0.3.1 go.ntppool.org/common v0.3.2-0.20250103130152-f6d160a7f8f4
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.58.0 go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.58.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.58.0 go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.58.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0

2
go.sum
View File

@@ -140,6 +140,8 @@ go.ntppool.org/api v0.3.4 h1:KeRyFhIRkjJwZif7hkpqEDEBmukyYGiOi2Fd6j3UzQ0=
go.ntppool.org/api v0.3.4/go.mod h1:LFLAwnrc/JyjzKnjgf8tCOJhps6oFIjuledS3PCx7xc= go.ntppool.org/api v0.3.4/go.mod h1:LFLAwnrc/JyjzKnjgf8tCOJhps6oFIjuledS3PCx7xc=
go.ntppool.org/common v0.3.1 h1:JaJpS3m8oAc9jH0yhHYJnjOC+RUzxx/F+EDe0QON4eQ= go.ntppool.org/common v0.3.1 h1:JaJpS3m8oAc9jH0yhHYJnjOC+RUzxx/F+EDe0QON4eQ=
go.ntppool.org/common v0.3.1/go.mod h1:1SKjFBH9AL7Fj2S0zy41isHzV6dTC+6yIKD5QDtX8aY= go.ntppool.org/common v0.3.1/go.mod h1:1SKjFBH9AL7Fj2S0zy41isHzV6dTC+6yIKD5QDtX8aY=
go.ntppool.org/common v0.3.2-0.20250103130152-f6d160a7f8f4 h1:ku0m24CFP9UL8MZbcW01M7pqqnyCgzYTvLw74Uw2BYA=
go.ntppool.org/common v0.3.2-0.20250103130152-f6d160a7f8f4/go.mod h1:1SKjFBH9AL7Fj2S0zy41isHzV6dTC+6yIKD5QDtX8aY=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/contrib/bridges/otelslog v0.8.0 h1:G3sKsNueSdxuACINFxKrQeimAIst0A5ytA2YJH+3e1c= go.opentelemetry.io/contrib/bridges/otelslog v0.8.0 h1:G3sKsNueSdxuACINFxKrQeimAIst0A5ytA2YJH+3e1c=

View File

@@ -107,6 +107,7 @@ func (srv *Server) fetchGraph(ctx context.Context, serverIP string) (string, []b
client := retryablehttp.NewClient() client := retryablehttp.NewClient()
client.Logger = log client.Logger = log
client.HTTPClient.Transport = otelhttp.NewTransport( client.HTTPClient.Transport = otelhttp.NewTransport(
client.HTTPClient.Transport, client.HTTPClient.Transport,
otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace { otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace {

View File

@@ -284,7 +284,7 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
g, ctx := errgroup.WithContext(ctx) g, ctx := errgroup.WithContext(ctx)
stats := srv.db.Stats() stats := srv.db.Stats()
if stats.OpenConnections > 5 { if stats.OpenConnections > 3 {
log.InfoContext(ctx, "health requests", "url", req.URL.String(), "stats", stats) log.InfoContext(ctx, "health requests", "url", req.URL.String(), "stats", stats)
} }
@@ -293,9 +293,11 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
log.InfoContext(ctx, "db reset request", "err", err, "reset", reset) log.InfoContext(ctx, "db reset request", "err", err, "reset", reset)
if err == nil && reset { if err == nil && reset {
// this feature was to debug some specific problem
log.InfoContext(ctx, "setting idle db conns to zero") log.InfoContext(ctx, "setting idle db conns to zero")
srv.db.SetConnMaxLifetime(30 * time.Second)
srv.db.SetMaxIdleConns(0) srv.db.SetMaxIdleConns(0)
srv.db.SetConnMaxLifetime(5 * time.Second) srv.db.SetMaxIdleConns(4)
} }
} }