Replace default with custom prometheus registry

The default prometheus registry exports data that may be useful for
side-channel attacks. This removes all of the default metrics and makes
sure we are only reporting snowflake metrics from the broker.
This commit is contained in:
Cecylia Bocovich 2021-04-01 14:21:12 -04:00
parent 2a310682b5
commit af6e2c30e1
2 changed files with 9 additions and 10 deletions

View file

@ -506,9 +506,7 @@ func main() {
http.Handle("/answer", SnowflakeHandler{ctx, proxyAnswers}) http.Handle("/answer", SnowflakeHandler{ctx, proxyAnswers})
http.Handle("/debug", SnowflakeHandler{ctx, debugHandler}) http.Handle("/debug", SnowflakeHandler{ctx, debugHandler})
http.Handle("/metrics", MetricsHandler{metricsFilename, metricsHandler}) http.Handle("/metrics", MetricsHandler{metricsFilename, metricsHandler})
http.Handle("/prometheus", promhttp.Handler()) http.Handle("/prometheus", promhttp.HandlerFor(promMetrics.registry, promhttp.HandlerOpts{}))
InitPrometheus()
server := http.Server{ server := http.Server{
Addr: addr, Addr: addr,

View file

@ -15,7 +15,6 @@ import (
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
@ -261,6 +260,7 @@ func binCount(count uint) uint {
} }
type PromMetrics struct { type PromMetrics struct {
registry *prometheus.Registry
ProxyTotal *prometheus.CounterVec ProxyTotal *prometheus.CounterVec
ProxyPollTotal *RoundedCounterVec ProxyPollTotal *RoundedCounterVec
ClientPollTotal *RoundedCounterVec ClientPollTotal *RoundedCounterVec
@ -272,7 +272,9 @@ func initPrometheus() *PromMetrics {
promMetrics := &PromMetrics{} promMetrics := &PromMetrics{}
promMetrics.ProxyTotal = promauto.NewCounterVec( promMetrics.registry = prometheus.NewRegistry()
promMetrics.ProxyTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: prometheusNamespace, Namespace: prometheusNamespace,
Name: "proxy_total", Name: "proxy_total",
@ -281,7 +283,7 @@ func initPrometheus() *PromMetrics {
[]string{"type", "nat", "cc"}, []string{"type", "nat", "cc"},
) )
promMetrics.AvailableProxies = promauto.NewGaugeVec( promMetrics.AvailableProxies = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: prometheusNamespace, Namespace: prometheusNamespace,
Name: "available_proxies", Name: "available_proxies",
@ -308,10 +310,9 @@ func initPrometheus() *PromMetrics {
[]string{"nat", "status"}, []string{"nat", "status"},
) )
// We need to register this new metric type because there is no constructor // We need to register our metrics so they can be exported.
// for it in promauto. promMetrics.registry.MustRegister(promMetrics.ClientPollTotal, promMetrics.ProxyPollTotal,
prometheus.DefaultRegisterer.MustRegister(promMetrics.ClientPollTotal) promMetrics.ProxyTotal, promMetrics.AvailableProxies)
prometheus.DefaultRegisterer.MustRegister(promMetrics.ProxyPollTotal)
return promMetrics return promMetrics