Skip to content

Commit 0c4830b

Browse files
authored
Merge pull request #569 from saikat-royc/fix-process-start-time
Add process_start_time_seconds metric
2 parents f1fa4d1 + 3c216f7 commit 0c4830b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

pkg/metrics/metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ type MetricsManager interface {
111111
// status - the operation status, if not specified, i.e., status == nil, an
112112
// "Unknown" status of the passed-in operation is assumed.
113113
RecordMetrics(op OperationKey, status OperationStatus, driverName string)
114+
115+
// GetRegistry() returns the metrics.KubeRegistry used by this metrics manager.
116+
GetRegistry() k8smetrics.KubeRegistry
114117
}
115118

116119
// OperationKey is a structure which holds information to
@@ -265,6 +268,7 @@ func (opMgr *operationMetricsManager) recordCancelMetric(val OperationValue, key
265268

266269
func (opMgr *operationMetricsManager) init() {
267270
opMgr.registry = k8smetrics.NewKubeRegistry()
271+
k8smetrics.RegisterProcessStartTime(opMgr.registry.Register)
268272
opMgr.opLatencyMetrics = k8smetrics.NewHistogramVec(
269273
&k8smetrics.HistogramOpts{
270274
Subsystem: subSystem,
@@ -327,6 +331,10 @@ func (opMgr *operationMetricsManager) StartMetricsEndpoint(pattern, addr string,
327331
return srv, nil
328332
}
329333

334+
func (opMgr *operationMetricsManager) GetRegistry() k8smetrics.KubeRegistry {
335+
return opMgr.registry
336+
}
337+
330338
// snapshotProvisionType represents which kind of snapshot a metric is
331339
type snapshotProvisionType string
332340

pkg/metrics/metrics_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ var (
4444
)
4545

4646
const (
47-
httpPattern = "/metrics"
48-
addr = "localhost:0"
47+
httpPattern = "/metrics"
48+
addr = "localhost:0"
49+
processStartTimeMetric = "process_start_time_seconds"
4950
)
5051

5152
type fakeOpStatus struct {
@@ -707,3 +708,24 @@ func containsMetrics(expectedMfs, gotMfs []*cmg.MetricFamily) bool {
707708

708709
return true
709710
}
711+
712+
func TestProcessStartTimeMetricExist(t *testing.T) {
713+
mgr, wg, srv := initMgr()
714+
defer shutdown(srv, wg)
715+
metricsFamilies, err := mgr.GetRegistry().Gather()
716+
if err != nil {
717+
t.Fatalf("Error fetching metrics: %v", err)
718+
}
719+
720+
for _, metricsFamily := range metricsFamilies {
721+
if metricsFamily.GetName() == processStartTimeMetric {
722+
return
723+
}
724+
m := metricsFamily.GetMetric()
725+
if m[0].GetGauge().GetValue() <= 0 {
726+
t.Fatalf("Expected non zero timestamp for process start time")
727+
}
728+
}
729+
730+
t.Fatalf("Metrics does not contain %v. Scraped content: %v", processStartTimeMetric, metricsFamilies)
731+
}

0 commit comments

Comments
 (0)