Deprecate apiserver_storage_objects and replace it with apiserver_resource_objects metric using labels consistent with other metrics
Kubernetes-commit: cf68f75fc3393e2579ba8158d3936c275a6d9be0
This commit is contained in:
parent
b8b19e9618
commit
e1b2eb304d
|
@ -72,9 +72,10 @@ var (
|
||||||
)
|
)
|
||||||
objectCounts = compbasemetrics.NewGaugeVec(
|
objectCounts = compbasemetrics.NewGaugeVec(
|
||||||
&compbasemetrics.GaugeOpts{
|
&compbasemetrics.GaugeOpts{
|
||||||
Name: "apiserver_storage_objects",
|
Name: "apiserver_storage_objects",
|
||||||
Help: "Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.",
|
Help: "Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.",
|
||||||
StabilityLevel: compbasemetrics.STABLE,
|
StabilityLevel: compbasemetrics.STABLE,
|
||||||
|
DeprecatedVersion: "1.34.0",
|
||||||
},
|
},
|
||||||
[]string{"resource"},
|
[]string{"resource"},
|
||||||
)
|
)
|
||||||
|
@ -86,6 +87,14 @@ var (
|
||||||
},
|
},
|
||||||
[]string{"group", "resource"},
|
[]string{"group", "resource"},
|
||||||
)
|
)
|
||||||
|
newObjectCounts = compbasemetrics.NewGaugeVec(
|
||||||
|
&compbasemetrics.GaugeOpts{
|
||||||
|
Name: "apiserver_resource_objects",
|
||||||
|
Help: "Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.",
|
||||||
|
StabilityLevel: compbasemetrics.ALPHA,
|
||||||
|
},
|
||||||
|
[]string{"group", "resource"},
|
||||||
|
)
|
||||||
dbTotalSize = compbasemetrics.NewGaugeVec(
|
dbTotalSize = compbasemetrics.NewGaugeVec(
|
||||||
&compbasemetrics.GaugeOpts{
|
&compbasemetrics.GaugeOpts{
|
||||||
Subsystem: "apiserver",
|
Subsystem: "apiserver",
|
||||||
|
@ -178,6 +187,7 @@ func Register() {
|
||||||
legacyregistry.MustRegister(etcdRequestErrorCounts)
|
legacyregistry.MustRegister(etcdRequestErrorCounts)
|
||||||
legacyregistry.MustRegister(objectCounts)
|
legacyregistry.MustRegister(objectCounts)
|
||||||
legacyregistry.MustRegister(resourceSizeEstimate)
|
legacyregistry.MustRegister(resourceSizeEstimate)
|
||||||
|
legacyregistry.MustRegister(newObjectCounts)
|
||||||
legacyregistry.MustRegister(dbTotalSize)
|
legacyregistry.MustRegister(dbTotalSize)
|
||||||
legacyregistry.CustomMustRegister(storageMonitor)
|
legacyregistry.CustomMustRegister(storageMonitor)
|
||||||
legacyregistry.MustRegister(etcdEventsReceivedCounts)
|
legacyregistry.MustRegister(etcdEventsReceivedCounts)
|
||||||
|
@ -195,12 +205,14 @@ func Register() {
|
||||||
func UpdateStoreStats(groupResource schema.GroupResource, stats storage.Stats, err error) {
|
func UpdateStoreStats(groupResource schema.GroupResource, stats storage.Stats, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
objectCounts.WithLabelValues(groupResource.String()).Set(-1)
|
objectCounts.WithLabelValues(groupResource.String()).Set(-1)
|
||||||
|
newObjectCounts.WithLabelValues(groupResource.Group, groupResource.Resource).Set(-1)
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.SizeBasedListCostEstimate) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.SizeBasedListCostEstimate) {
|
||||||
resourceSizeEstimate.WithLabelValues(groupResource.Group, groupResource.Resource).Set(-1)
|
resourceSizeEstimate.WithLabelValues(groupResource.Group, groupResource.Resource).Set(-1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
objectCounts.WithLabelValues(groupResource.String()).Set(float64(stats.ObjectCount))
|
objectCounts.WithLabelValues(groupResource.String()).Set(float64(stats.ObjectCount))
|
||||||
|
newObjectCounts.WithLabelValues(groupResource.Group, groupResource.Resource).Set(float64(stats.ObjectCount))
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.SizeBasedListCostEstimate) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.SizeBasedListCostEstimate) {
|
||||||
if stats.ObjectCount > 0 && stats.EstimatedAverageObjectSizeBytes == 0 {
|
if stats.ObjectCount > 0 && stats.EstimatedAverageObjectSizeBytes == 0 {
|
||||||
resourceSizeEstimate.WithLabelValues(groupResource.Group, groupResource.Resource).Set(-1)
|
resourceSizeEstimate.WithLabelValues(groupResource.Group, groupResource.Resource).Set(-1)
|
||||||
|
@ -213,6 +225,7 @@ func UpdateStoreStats(groupResource schema.GroupResource, stats storage.Stats, e
|
||||||
// DeleteStoreStats delete the stats metrics.
|
// DeleteStoreStats delete the stats metrics.
|
||||||
func DeleteStoreStats(groupResource schema.GroupResource) {
|
func DeleteStoreStats(groupResource schema.GroupResource) {
|
||||||
objectCounts.DeleteLabelValues(groupResource.String())
|
objectCounts.DeleteLabelValues(groupResource.String())
|
||||||
|
newObjectCounts.DeleteLabelValues(groupResource.Group, groupResource.Resource)
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.SizeBasedListCostEstimate) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.SizeBasedListCostEstimate) {
|
||||||
resourceSizeEstimate.DeleteLabelValues(groupResource.Group, groupResource.Resource)
|
resourceSizeEstimate.DeleteLabelValues(groupResource.Group, groupResource.Resource)
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,6 +230,7 @@ func TestStorageSizeCollector(t *testing.T) {
|
||||||
func TestUpdateStoreStats(t *testing.T) {
|
func TestUpdateStoreStats(t *testing.T) {
|
||||||
registry := metrics.NewKubeRegistry()
|
registry := metrics.NewKubeRegistry()
|
||||||
registry.Register(objectCounts)
|
registry.Register(objectCounts)
|
||||||
|
registry.MustRegister(newObjectCounts)
|
||||||
registry.MustRegister(resourceSizeEstimate)
|
registry.MustRegister(resourceSizeEstimate)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -243,7 +244,10 @@ func TestUpdateStoreStats(t *testing.T) {
|
||||||
desc: "successful object count",
|
desc: "successful object count",
|
||||||
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
||||||
stats: storage.Stats{ObjectCount: 10},
|
stats: storage.Stats{ObjectCount: 10},
|
||||||
want: `# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
want: `# HELP apiserver_resource_objects [ALPHA] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
# TYPE apiserver_resource_objects gauge
|
||||||
|
apiserver_resource_objects{group="foo",resource="bar"} 10
|
||||||
|
# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
||||||
# TYPE apiserver_resource_size_estimate_bytes gauge
|
# TYPE apiserver_resource_size_estimate_bytes gauge
|
||||||
apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} -1
|
apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} -1
|
||||||
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
@ -255,7 +259,10 @@ apiserver_storage_objects{resource="bar.foo"} 10
|
||||||
desc: "successful object count and size",
|
desc: "successful object count and size",
|
||||||
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
||||||
stats: storage.Stats{ObjectCount: 10, EstimatedAverageObjectSizeBytes: 10},
|
stats: storage.Stats{ObjectCount: 10, EstimatedAverageObjectSizeBytes: 10},
|
||||||
want: `# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
want: `# HELP apiserver_resource_objects [ALPHA] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
# TYPE apiserver_resource_objects gauge
|
||||||
|
apiserver_resource_objects{group="foo",resource="bar"} 10
|
||||||
|
# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
||||||
# TYPE apiserver_resource_size_estimate_bytes gauge
|
# TYPE apiserver_resource_size_estimate_bytes gauge
|
||||||
apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} 100
|
apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} 100
|
||||||
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
@ -267,7 +274,10 @@ apiserver_storage_objects{resource="bar.foo"} 10
|
||||||
desc: "empty object count",
|
desc: "empty object count",
|
||||||
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
||||||
stats: storage.Stats{ObjectCount: 0, EstimatedAverageObjectSizeBytes: 0},
|
stats: storage.Stats{ObjectCount: 0, EstimatedAverageObjectSizeBytes: 0},
|
||||||
want: `# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
want: `# HELP apiserver_resource_objects [ALPHA] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
# TYPE apiserver_resource_objects gauge
|
||||||
|
apiserver_resource_objects{group="foo",resource="bar"} 0
|
||||||
|
# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
||||||
# TYPE apiserver_resource_size_estimate_bytes gauge
|
# TYPE apiserver_resource_size_estimate_bytes gauge
|
||||||
apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} 0
|
apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} 0
|
||||||
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
@ -279,7 +289,10 @@ apiserver_storage_objects{resource="bar.foo"} 0
|
||||||
desc: "failed fetch",
|
desc: "failed fetch",
|
||||||
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
resource: schema.GroupResource{Group: "foo", Resource: "bar"},
|
||||||
err: errors.New("dummy"),
|
err: errors.New("dummy"),
|
||||||
want: `# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
want: `# HELP apiserver_resource_objects [ALPHA] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
|
# TYPE apiserver_resource_objects gauge
|
||||||
|
apiserver_resource_objects{group="foo",resource="bar"} -1
|
||||||
|
# HELP apiserver_storage_objects [STABLE] Number of stored objects at the time of last check split by kind. In case of a fetching error, the value will be -1.
|
||||||
# TYPE apiserver_storage_objects gauge
|
# TYPE apiserver_storage_objects gauge
|
||||||
apiserver_storage_objects{resource="bar.foo"} -1
|
apiserver_storage_objects{resource="bar.foo"} -1
|
||||||
# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
# HELP apiserver_resource_size_estimate_bytes [ALPHA] Estimated size of stored objects in database. Estimate is based on sum of last observed sizes of serialized objects. In case of a fetching error, the value will be -1.
|
||||||
|
@ -293,7 +306,7 @@ apiserver_resource_size_estimate_bytes{group="foo",resource="bar"} -1
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
defer registry.Reset()
|
defer registry.Reset()
|
||||||
UpdateStoreStats(test.resource, test.stats, test.err)
|
UpdateStoreStats(test.resource, test.stats, test.err)
|
||||||
if err := testutil.GatherAndCompare(registry, strings.NewReader(test.want), "apiserver_storage_objects", "apiserver_resource_size_estimate_bytes"); err != nil {
|
if err := testutil.GatherAndCompare(registry, strings.NewReader(test.want), "apiserver_storage_objects", "apiserver_resource_size_estimate_bytes", "apiserver_resource_objects"); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue