collector: publish base units and _total counter names (#2743)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-16 10:48:26 +02:00
committed by GitHub
parent dc8092f46d
commit 3fb18521f6
131 changed files with 1674 additions and 1459 deletions
+21 -16
View File
@@ -38,7 +38,7 @@ func BenchmarkCollector(b *testing.B) {
func TestCollector(t *testing.T) {
metrics := testutils.TestCollector(t, hyperv.New, nil)
testutils.RequireFixtureMetric(t, metrics, hyperv.Name, "windows_hyperv_dynamic_memory_vm_physical_bytes", prometheus.Labels{"vm": "GitHubActions"})
testutils.RequireFixtureMetric(t, metrics, hyperv.Name, "windows_hyperv_vm_processor_count", prometheus.Labels{"vm": "GitHubActions"})
testutils.RequireFixtureMetric(t, metrics, hyperv.Name, "windows_hyperv_vm_processors", prometheus.Labels{"vm": "GitHubActions"})
// An empty "Hyper-V DataStore" counter set is tolerated as an optional
// instance group, so require a series explicitly (#2328).
@@ -58,28 +58,33 @@ func TestCollector(t *testing.T) {
}
}
// TestCollectorVirtualStorageDeviceLatency checks that the deprecated latency gauges
// expose the raw cumulative value in 100ns ticks of the *_io_latency_seconds_total counters.
// TestCollectorVirtualStorageDeviceLatency checks that the latencies are published
// as counters in seconds for every device, and that the removed gauges, which
// exposed the same raw value in 100ns ticks, are gone.
func TestCollectorVirtualStorageDeviceLatency(t *testing.T) {
metrics := testutils.TestCollector(t, hyperv.New, &hyperv.Config{CollectorsEnabled: []string{"virtual_storage_device"}})
for deprecated, replacement := range map[string]string{
"windows_hyperv_virtual_storage_device_latency_seconds": "windows_hyperv_virtual_storage_device_io_latency_seconds_total",
"windows_hyperv_virtual_storage_device_lower_latency_seconds": "windows_hyperv_virtual_storage_device_lower_io_latency_seconds_total",
} {
want := testutils.MetricValuesByLabel(metrics, deprecated, "device")
got := testutils.MetricValuesByLabel(metrics, replacement, "device")
devices := testutils.MetricValuesByLabel(metrics, "windows_hyperv_virtual_storage_device_throughput_total", "device")
require.Len(t, got, len(want))
for _, name := range []string{
"windows_hyperv_virtual_storage_device_io_latency_seconds_total",
"windows_hyperv_virtual_storage_device_lower_io_latency_seconds_total",
} {
got := testutils.MetricValuesByLabel(metrics, name, "device")
require.Len(t, got, len(devices), name)
if len(got) > 0 {
require.Equal(t, dto.MetricType_COUNTER, metrics[replacement].GetType())
require.Equal(t, dto.MetricType_COUNTER, metrics[name].GetType())
}
}
for device, ticks := range want {
require.Contains(t, got, device)
require.InDelta(t, ticks*pdh.TicksToSecondScaleFactor, got[device], 1e-6, "%s{device=%q}", replacement, device)
}
for _, removed := range []string{
"windows_hyperv_virtual_storage_device_latency_seconds",
"windows_hyperv_virtual_storage_device_lower_latency_seconds",
"windows_hyperv_virtual_storage_device_queue_length",
"windows_hyperv_virtual_storage_device_lower_queue_length",
} {
require.NotContains(t, metrics, removed)
}
}
@@ -118,7 +123,7 @@ func TestCollectorVirtualHardDisk(t *testing.T) {
if metric := testutils.RequireFixtureMetric(t, metrics, hyperv.Name, "windows_hyperv_virtual_hard_disk_size_bytes", labels); metric != nil {
device := labelValue(metric, "device")
require.NotEmpty(t, device, "the running VM's disk has no device")
require.Contains(t, testutils.MetricValuesByLabel(metrics, "windows_hyperv_virtual_storage_device_queue_length", "device"), device,
require.Contains(t, testutils.MetricValuesByLabel(metrics, "windows_hyperv_virtual_storage_device_throughput_total", "device"), device,
"device %q is not a virtual_storage_device instance", device)
}