2022-04-27 01:00:20 -05:00
|
|
|
//go:build metrics
|
|
|
|
// +build metrics
|
|
|
|
|
|
|
|
package extensions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2022-10-20 11:39:20 -05:00
|
|
|
|
2022-04-27 01:00:20 -05:00
|
|
|
"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,
|
2023-02-10 17:52:54 -05:00
|
|
|
authFunc mux.MiddlewareFunc, log log.Logger,
|
2022-04-27 01:00:20 -05:00
|
|
|
) {
|
|
|
|
log.Info().Msg("setting up metrics routes")
|
|
|
|
|
|
|
|
if config.Extensions.Metrics != nil && *config.Extensions.Metrics.Enable {
|
2023-02-10 17:52:54 -05:00
|
|
|
extRouter := router.PathPrefix(config.Extensions.Metrics.Prometheus.Path).Subrouter()
|
|
|
|
extRouter.Use(authFunc)
|
|
|
|
extRouter.Methods("GET").Handler(promhttp.Handler())
|
2022-04-27 01:00:20 -05:00
|
|
|
}
|
|
|
|
}
|