package metrics

import (
	"sync"

	"github.com/prometheus/client_golang/prometheus"
)

var (
	HTTPReqDuration *prometheus.HistogramVec
	HTTPReqTotal    *prometheus.CounterVec

	httpRegisterOnce sync.Once
)

func httpRegister(subsystem string) {
	httpRegisterOnce.Do(func() {
		HTTPReqDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "http_request_duration_ms",
			Help:      "The HTTP request latencies in ms.",
			Buckets:   prometheus.ExponentialBuckets(1, 2, 21), // 1ms ~ 1048576ms
		}, []string{"method", "path"})

		HTTPReqTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "http_requests_total",
			Help:      "Total number of HTTP requests made.",
		}, []string{"method", "path", "status"})

		prometheus.MustRegister(
			HTTPReqDuration,
			HTTPReqTotal,
		)
	})
}
