Add shard_ordinal label
Facilitates many otherwise impossible promql queries
This commit is contained in:
parent
676c7a74d9
commit
ba58b77bc8
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
@ -104,7 +105,9 @@ func (b *Builder) WithNamespaces(n options.NamespaceList) {
|
||||||
// WithSharding sets the shard and totalShards property of a Builder.
|
// WithSharding sets the shard and totalShards property of a Builder.
|
||||||
func (b *Builder) WithSharding(shard int32, totalShards int) {
|
func (b *Builder) WithSharding(shard int32, totalShards int) {
|
||||||
b.shard = shard
|
b.shard = shard
|
||||||
b.shardingMetrics.Ordinal.Set(float64(shard))
|
labels := map[string]string{sharding.LabelOrdinal: strconv.Itoa(int(shard))}
|
||||||
|
b.shardingMetrics.Ordinal.Reset()
|
||||||
|
b.shardingMetrics.Ordinal.With(labels).Set(float64(shard))
|
||||||
b.totalShards = totalShards
|
b.totalShards = totalShards
|
||||||
b.shardingMetrics.Total.Set(float64(totalShards))
|
b.shardingMetrics.Total.Set(float64(totalShards))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,7 @@ kube_pod_status_reason{namespace="default",pod="pod0",uid="abc-0",reason="Unexpe
|
||||||
# HELP kube_state_metrics_total_shards Number of total shards this instance is aware of
|
# HELP kube_state_metrics_total_shards Number of total shards this instance is aware of
|
||||||
# TYPE kube_state_metrics_shard_ordinal gauge
|
# TYPE kube_state_metrics_shard_ordinal gauge
|
||||||
# TYPE kube_state_metrics_total_shards gauge
|
# TYPE kube_state_metrics_total_shards gauge
|
||||||
kube_state_metrics_shard_ordinal 0
|
kube_state_metrics_shard_ordinal{shard_ordinal="0"} 0
|
||||||
kube_state_metrics_total_shards 1
|
kube_state_metrics_total_shards 1
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,15 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Name of Prometheus metric label to use in conjunction with kube_state_metrics_shard_ordinal.
|
||||||
|
LabelOrdinal = "shard_ordinal"
|
||||||
|
)
|
||||||
|
|
||||||
// Metrics stores the pointers of kube_state_metrics_shard_ordinal
|
// Metrics stores the pointers of kube_state_metrics_shard_ordinal
|
||||||
// and kube_state_metrics_total_shards metrics.
|
// and kube_state_metrics_total_shards metrics.
|
||||||
type Metrics struct {
|
type Metrics struct {
|
||||||
Ordinal prometheus.Gauge
|
Ordinal *prometheus.GaugeVec
|
||||||
Total prometheus.Gauge
|
Total prometheus.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,11 +37,11 @@ type Metrics struct {
|
||||||
// and registers sharding configuration metrics. It returns those registered metrics.
|
// and registers sharding configuration metrics. It returns those registered metrics.
|
||||||
func NewShardingMetrics(r prometheus.Registerer) *Metrics {
|
func NewShardingMetrics(r prometheus.Registerer) *Metrics {
|
||||||
return &Metrics{
|
return &Metrics{
|
||||||
Ordinal: promauto.With(r).NewGauge(
|
Ordinal: promauto.With(r).NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "kube_state_metrics_shard_ordinal",
|
Name: "kube_state_metrics_shard_ordinal",
|
||||||
Help: "Current sharding ordinal/index of this instance",
|
Help: "Current sharding ordinal/index of this instance",
|
||||||
},
|
}, []string{LabelOrdinal},
|
||||||
),
|
),
|
||||||
Total: promauto.With(r).NewGauge(
|
Total: promauto.With(r).NewGauge(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue