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:
Harshavardhana
2019-10-04 11:18:59 -07:00
committed by kannappanr
parent 589e32a4ed
commit e85df07518
2 changed files with 158 additions and 1 deletions

View File

@@ -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()))
}
}