Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
loki/pkg/validation/exporter.go

61 lines
1.5 KiB

package validation
import (
"reflect"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/grafana/loki/pkg/util/flagext"
)
type OverridesExporter struct {
tenantLimits TenantLimits
description *prometheus.Desc
}
// TODO(jordanrushing): break out overrides from defaults?
func NewOverridesExporter(tenantLimits TenantLimits) *OverridesExporter {
return &OverridesExporter{
tenantLimits: tenantLimits,
description: prometheus.NewDesc(
"loki_overrides",
"Resource limit overrides applied to tenants",
[]string{"limit_name", "user"},
nil,
),
}
}
func (oe *OverridesExporter) Describe(ch chan<- *prometheus.Desc) {
ch <- oe.description
}
func (oe *OverridesExporter) Collect(ch chan<- prometheus.Metric) {
var metricValue float64
var metricLabelValue string
var rv reflect.Value
for tenant, limits := range oe.tenantLimits.AllByUserID() {
rv = reflect.ValueOf(limits).Elem()
for i := 0; i < rv.NumField(); i++ {
switch rv.Field(i).Interface().(type) {
case int, time.Duration:
metricValue = float64(rv.Field(i).Int())
case model.Duration:
metricValue = float64(rv.Field(i).Interface().(model.Duration))
case flagext.ByteSize:
metricValue = float64(rv.Field(i).Uint())
case float64:
metricValue = rv.Field(i).Float()
default:
continue
}
metricLabelValue = rv.Type().Field(i).Tag.Get("yaml")
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, metricValue, metricLabelValue, tenant)
}
}
}