Add process start time metric

This commit is contained in:
Saikat Roychowdhury
2021-08-04 03:13:39 +00:00
parent 77adc85097
commit 3c216f78bb
2 changed files with 32 additions and 2 deletions

View File

@@ -111,6 +111,9 @@ type MetricsManager interface {
// status - the operation status, if not specified, i.e., status == nil, an
// "Unknown" status of the passed-in operation is assumed.
RecordMetrics(op OperationKey, status OperationStatus, driverName string)
// GetRegistry() returns the metrics.KubeRegistry used by this metrics manager.
GetRegistry() k8smetrics.KubeRegistry
}
// OperationKey is a structure which holds information to
@@ -265,6 +268,7 @@ func (opMgr *operationMetricsManager) recordCancelMetric(val OperationValue, key
func (opMgr *operationMetricsManager) init() {
opMgr.registry = k8smetrics.NewKubeRegistry()
k8smetrics.RegisterProcessStartTime(opMgr.registry.Register)
opMgr.opLatencyMetrics = k8smetrics.NewHistogramVec(
&k8smetrics.HistogramOpts{
Subsystem: subSystem,
@@ -327,6 +331,10 @@ func (opMgr *operationMetricsManager) StartMetricsEndpoint(pattern, addr string,
return srv, nil
}
func (opMgr *operationMetricsManager) GetRegistry() k8smetrics.KubeRegistry {
return opMgr.registry
}
// snapshotProvisionType represents which kind of snapshot a metric is
type snapshotProvisionType string

View File

@@ -46,6 +46,7 @@ var (
const (
httpPattern = "/metrics"
addr = "localhost:0"
processStartTimeMetric = "process_start_time_seconds"
)
type fakeOpStatus struct {
@@ -707,3 +708,24 @@ func containsMetrics(expectedMfs, gotMfs []*cmg.MetricFamily) bool {
return true
}
func TestProcessStartTimeMetricExist(t *testing.T) {
mgr, wg, srv := initMgr()
defer shutdown(srv, wg)
metricsFamilies, err := mgr.GetRegistry().Gather()
if err != nil {
t.Fatalf("Error fetching metrics: %v", err)
}
for _, metricsFamily := range metricsFamilies {
if metricsFamily.GetName() == processStartTimeMetric {
return
}
m := metricsFamily.GetMetric()
if m[0].GetGauge().GetValue() <= 0 {
t.Fatalf("Expected non zero timestamp for process start time")
}
}
t.Fatalf("Metrics does not contain %v. Scraped content: %v", processStartTimeMetric, metricsFamilies)
}