feat(tenant): expose additional metrics (#1517)

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* chore(lint): fix golint problems

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): fix linting

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

* feat(tenant): expose additional metrics

Signed-off-by: Hristo Hristov <me@hhristov.info>

---------

Signed-off-by: Hristo Hristov <me@hhristov.info>
This commit is contained in:
Hristo Hristov
2025-08-01 16:57:38 +03:00
committed by GitHub
parent bdcae3af42
commit e234200d1c
4 changed files with 98 additions and 6 deletions

View File

@@ -9,8 +9,11 @@ import (
)
type TenantRecorder struct {
TenantResourceUsageGauge *prometheus.GaugeVec
TenantResourceLimitGauge *prometheus.GaugeVec
TenantNamespaceRelationshipGauge *prometheus.GaugeVec
TenantCordonedStatusGauge *prometheus.GaugeVec
TenantNamespaceCounterGauge *prometheus.GaugeVec
TenantResourceUsageGauge *prometheus.GaugeVec
TenantResourceLimitGauge *prometheus.GaugeVec
}
func MustMakeTenantRecorder() *TenantRecorder {
@@ -22,6 +25,27 @@ func MustMakeTenantRecorder() *TenantRecorder {
func NewTenantRecorder() *TenantRecorder {
return &TenantRecorder{
TenantNamespaceRelationshipGauge: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricsPrefix,
Name: "tenant_namespace_relationship",
Help: "Mapping metric showing namespace to tenant relationships",
}, []string{"tenant", "namespace"},
),
TenantCordonedStatusGauge: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricsPrefix,
Name: "tenant_status",
Help: "Tenant cordon state indicating if tenant operations are restricted (1) or allowed (0) for resource creation and modification",
}, []string{"tenant"},
),
TenantNamespaceCounterGauge: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricsPrefix,
Name: "tenant_namespace_count",
Help: "Total number of namespaces currently owned by the tenant",
}, []string{"tenant"},
),
TenantResourceUsageGauge: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricsPrefix,
@@ -41,13 +65,16 @@ func NewTenantRecorder() *TenantRecorder {
func (r *TenantRecorder) Collectors() []prometheus.Collector {
return []prometheus.Collector{
r.TenantNamespaceRelationshipGauge,
r.TenantCordonedStatusGauge,
r.TenantNamespaceCounterGauge,
r.TenantResourceUsageGauge,
r.TenantResourceLimitGauge,
}
}
// DeleteCondition deletes the condition metrics for the ref.
func (r *TenantRecorder) DeleteTenantMetric(tenant string) {
func (r *TenantRecorder) DeleteTenantResourceMetrics(tenant string) {
r.TenantResourceUsageGauge.DeletePartialMatch(map[string]string{
"tenant": tenant,
})
@@ -55,3 +82,28 @@ func (r *TenantRecorder) DeleteTenantMetric(tenant string) {
"tenant": tenant,
})
}
// DeleteCondition deletes the condition metrics for the ref.
func (r *TenantRecorder) DeleteTenantStatusMetrics(tenant string) {
r.TenantNamespaceRelationshipGauge.DeletePartialMatch(map[string]string{
"tenant": tenant,
})
r.TenantResourceUsageGauge.DeletePartialMatch(map[string]string{
"tenant": tenant,
})
r.TenantResourceLimitGauge.DeletePartialMatch(map[string]string{
"tenant": tenant,
})
}
// DeleteCondition deletes the condition metrics for the ref.
func (r *TenantRecorder) DeleteNamespaceRelationshipMetrics(namespace string) {
r.TenantNamespaceRelationshipGauge.DeletePartialMatch(map[string]string{
"namespace": namespace,
})
}
func (r *TenantRecorder) DeleteAllMetrics(tenant string) {
r.DeleteTenantResourceMetrics(tenant)
r.DeleteTenantStatusMetrics(tenant)
}