Add prometheus auth-type to turn-off authentication (#8356)
Also this PR moves the original doc from cookbook to MinIO repo under docs/metrics/prometheus/ Fixes #8323
This commit is contained in:
committed by
kannappanr
parent
589e32a4ed
commit
e85df07518
@@ -17,6 +17,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
@@ -24,9 +27,28 @@ const (
|
||||
prometheusMetricsPath = "/prometheus/metrics"
|
||||
)
|
||||
|
||||
// Standard env prometheus auth type
|
||||
const (
|
||||
EnvPrometheusAuthType = "MINIO_PROMETHEUS_AUTH_TYPE"
|
||||
)
|
||||
|
||||
type prometheusAuthType string
|
||||
|
||||
const (
|
||||
prometheusJWT prometheusAuthType = "jwt"
|
||||
prometheusPublic prometheusAuthType = "public"
|
||||
)
|
||||
|
||||
// registerMetricsRouter - add handler functions for metrics.
|
||||
func registerMetricsRouter(router *mux.Router) {
|
||||
// metrics router
|
||||
metricsRouter := router.NewRoute().PathPrefix(minioReservedBucketPath).Subrouter()
|
||||
metricsRouter.Handle(prometheusMetricsPath, AuthMiddleware(metricsHandler()))
|
||||
|
||||
authType := strings.ToLower(os.Getenv(EnvPrometheusAuthType))
|
||||
switch prometheusAuthType(authType) {
|
||||
case prometheusPublic:
|
||||
metricsRouter.Handle(prometheusMetricsPath, metricsHandler())
|
||||
default:
|
||||
metricsRouter.Handle(prometheusMetricsPath, AuthMiddleware(metricsHandler()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user