mirror of
https://github.com/project-zot/zot.git
synced 2025-01-06 22:40:28 -05:00
97f1fc0f98
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> (cherry picked from commit d557da0baba819b7cd7e6b5941528776e125ac6d)
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
//go:build metrics
|
|
// +build metrics
|
|
|
|
package extensions
|
|
|
|
import (
|
|
"github.com/gorilla/mux"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"zotregistry.io/zot/pkg/api/config"
|
|
"zotregistry.io/zot/pkg/log"
|
|
"zotregistry.io/zot/pkg/storage"
|
|
)
|
|
|
|
func EnableMetricsExtension(config *config.Config, log log.Logger, rootDir string) {
|
|
if config.Extensions.Metrics != nil &&
|
|
*config.Extensions.Metrics.Enable &&
|
|
config.Extensions.Metrics.Prometheus != nil {
|
|
if config.Extensions.Metrics.Prometheus.Path == "" {
|
|
config.Extensions.Metrics.Prometheus.Path = "/metrics"
|
|
|
|
log.Warn().Msg("Prometheus instrumentation Path not set, changing to '/metrics'.")
|
|
}
|
|
} else {
|
|
log.Info().Msg("Metrics config not provided, skipping Metrics config update")
|
|
}
|
|
}
|
|
|
|
func SetupMetricsRoutes(config *config.Config, router *mux.Router, storeController storage.StoreController,
|
|
authFunc mux.MiddlewareFunc, l log.Logger,
|
|
) {
|
|
// fork a new zerolog child to avoid data race
|
|
log := log.Logger{Logger: l.With().Caller().Timestamp().Logger()}
|
|
log.Info().Msg("setting up metrics routes")
|
|
|
|
if config.Extensions.Metrics != nil && *config.Extensions.Metrics.Enable {
|
|
extRouter := router.PathPrefix(config.Extensions.Metrics.Prometheus.Path).Handler(promhttp.Handler()).Subrouter()
|
|
extRouter.Use(authFunc)
|
|
}
|
|
}
|