Added new stats reporter to check suitable redis pool size

This commit is contained in:
ErickSkrauch
2020-05-01 02:46:12 +03:00
parent 5dbe6af1d0
commit aabf54e318
8 changed files with 94 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
package di
import (
"context"
"fmt"
"path"
"time"
"github.com/goava/di"
"github.com/spf13/viper"
@@ -23,6 +25,7 @@ var db = di.Options(
di.Provide(newRedis,
di.As(new(http.SkinsRepository)),
di.As(new(mojangtextures.UUIDsStorage)),
di.As(new(es.RedisPoolCheckable)),
),
di.Provide(newFSFactory,
di.As(new(http.CapesRepository)),
@@ -43,6 +46,12 @@ func newRedis(container *di.Container, config *viper.Viper) (*redis.Redis, error
return nil, err
}
if err := container.Provide(func() es.ReporterFunc {
return es.AvailableRedisPoolSizeReporter(conn, time.Second, context.Background())
}, di.As(new(es.Reporter))); err != nil {
return nil, err
}
if err := container.Provide(func() *namedHealthChecker {
return &namedHealthChecker{
Name: "redis",

View File

@@ -74,6 +74,11 @@ func newHandlerFactory(
mount(router, "/api", apiRouter)
}
err := container.Invoke(enableReporters)
if err != nil {
return nil, err
}
// Resolve health checkers last, because all the services required by the application
// must first be initialized and each of them can publish its own checkers
var healthCheckers []*namedHealthChecker

View File

@@ -13,6 +13,7 @@ import (
"github.com/mono83/slf/wd"
"github.com/spf13/viper"
"github.com/elyby/chrly/eventsubscribers"
"github.com/elyby/chrly/version"
)
@@ -95,3 +96,9 @@ func newStatsReporter(config *viper.Viper) (slf.StatsReporter, error) {
return wd.Custom("", "", dispatcher), nil
}
func enableReporters(reporter slf.StatsReporter, factories []eventsubscribers.Reporter) {
for _, factory := range factories {
factory.Enable(reporter)
}
}