mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 07:12:25 -05:00
[feature] Initial Prometheus metrics implementation (#2334)
* feat: Initial OTEL metrics * docs: add metrics documentation * fix: metrics endpoint conditional check * feat: metrics endpoint basic auth * fix: make metrics-auth-enabled default false * fix: go fmt helpers.gen.go * fix: add metric-related env vars to envparsing.sh * fix: metrics docs * fix: metrics related stuff in envparsing.sh * fix: metrics docs * chore: metrics docs wording * fix: metrics stuff in envparsing? * bump otel versions --------- Co-authored-by: Tsuribori <user@acertaindebian> Co-authored-by: Tsuribori <none@example.org> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
This commit is contained in:
parent
16275853eb
commit
1ba3e14b36
251 changed files with 48389 additions and 22 deletions
|
|
@ -33,6 +33,7 @@ import (
|
|||
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cleaner"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/metrics"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/middleware"
|
||||
tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||
|
|
@ -81,6 +82,11 @@ var Start action.GTSAction = func(ctx context.Context) error {
|
|||
return fmt.Errorf("error initializing tracing: %w", err)
|
||||
}
|
||||
|
||||
// Initialize Metrics
|
||||
if err := metrics.Initialize(); err != nil {
|
||||
return fmt.Errorf("error initializing metrics: %w", err)
|
||||
}
|
||||
|
||||
// Open connection to the database
|
||||
dbService, err := bundb.NewBunDBService(ctx, &state)
|
||||
if err != nil {
|
||||
|
|
@ -213,13 +219,18 @@ var Start action.GTSAction = func(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("error creating router: %s", err)
|
||||
}
|
||||
|
||||
middlewares := []gin.HandlerFunc{
|
||||
middleware.AddRequestID(config.GetRequestIDHeader()), // requestID middleware must run before tracing
|
||||
}
|
||||
|
||||
if config.GetTracingEnabled() {
|
||||
middlewares = append(middlewares, tracing.InstrumentGin())
|
||||
}
|
||||
|
||||
if config.GetMetricsEnabled() {
|
||||
middlewares = append(middlewares, metrics.InstrumentGin())
|
||||
}
|
||||
|
||||
middlewares = append(middlewares, []gin.HandlerFunc{
|
||||
// note: hooks adding ctx fields must be ABOVE
|
||||
// the logger, otherwise won't be accessible.
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/language"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/metrics"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/middleware"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oidc"
|
||||
tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline"
|
||||
|
|
@ -68,6 +69,10 @@ var Start action.GTSAction = func(ctx context.Context) error {
|
|||
return fmt.Errorf("error initializing tracing: %w", err)
|
||||
}
|
||||
|
||||
if err := metrics.Initialize(); err != nil {
|
||||
return fmt.Errorf("error initializing metrics: %w", err)
|
||||
}
|
||||
|
||||
// Initialize caches and database
|
||||
state.DB = testrig.NewTestDB(&state)
|
||||
|
||||
|
|
@ -142,6 +147,11 @@ var Start action.GTSAction = func(ctx context.Context) error {
|
|||
if config.GetTracingEnabled() {
|
||||
middlewares = append(middlewares, tracing.InstrumentGin())
|
||||
}
|
||||
|
||||
if config.GetMetricsEnabled() {
|
||||
middlewares = append(middlewares, metrics.InstrumentGin())
|
||||
}
|
||||
|
||||
middlewares = append(middlewares, []gin.HandlerFunc{
|
||||
middleware.Logger(config.GetLogClientIP()),
|
||||
middleware.UserAgent(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue