package metrics

import (
	"github.com/prometheus/client_golang/prometheus"
	"sigs.k8s.io/controller-runtime/pkg/metrics"
)

const tidbupgraderComponent = "tidbupgrader"

var (
	OldPodAssignCacheSizeGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Subsystem: tidbupgraderComponent,
			Name:      "old_pod_assign_cache_size",
			Help:      "Gauge of upgrader old pod assign cache size",
		},
		[]string{"revision", "pool_ns"},
	)
	AssignCacheSizeGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Subsystem: tidbupgraderComponent,
			Name:      "assign_cache_size",
			Help:      "Gauge of upgrader assign cache size",
		},
		[]string{"revision", "pool_ns"},
	)
	OldPodFreeCacheSizeGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Subsystem: tidbupgraderComponent,
			Name:      "old_pod_free_cache_size",
			Help:      "Gauge of upgrader old pod free cache size",
		},
		[]string{"revision", "pool_ns"},
	)
	FreeCacheSizeGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Subsystem: tidbupgraderComponent,
			Name:      "free_cache_size",
			Help:      "Gauge of upgrader free cache size",
		},
		[]string{"revision", "pool_ns"},
	)
	PodDeletionDurationGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Subsystem: tidbupgraderComponent,
			Name:      "pod_deletion_duration",
			Help:      "Gauge of pod deletion duration in seconds",
		},
		[]string{"namespace", "pod_name"},
	)
	UpgraderErrorDurationGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Subsystem: tidbupgraderComponent,
			Name:      "upgrader_error_duration",
			Help:      "Gauge of upgrader error duration in seconds",
		},
		[]string{"pool_ns"},
	)
)

func init() {
	// Register custom metrics with the global prometheus registry
	metrics.Registry.MustRegister(OldPodAssignCacheSizeGauge)
	metrics.Registry.MustRegister(AssignCacheSizeGauge)
	metrics.Registry.MustRegister(OldPodFreeCacheSizeGauge)
	metrics.Registry.MustRegister(FreeCacheSizeGauge)
	metrics.Registry.MustRegister(PodDeletionDurationGauge)
	metrics.Registry.MustRegister(UpgraderErrorDurationGauge)
}
