Skip to content

Commit 1f97fa3

Browse files
committed
Create an inventory startup time metric
1 parent eb0edda commit 1f97fa3

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

pkg/driver/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,13 @@ func Start(ctx context.Context, driverName string, kubeClient kubernetes.Interfa
192192
plugin.netdb = inventory.New()
193193
}
194194
go func() {
195+
begin := time.Now()
195196
for i := 0; i < maxAttempts; i++ {
196197
err = plugin.netdb.Run(ctx)
197198
if err != nil {
198199
klog.Infof("Network Device DB failed with error %v", err)
199200
}
201+
inventoryStartupDurationSeconds.Set(time.Since(begin).Seconds())
200202
select {
201203
case <-ctx.Done():
202204
return

pkg/driver/metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func registerMetrics() {
4747
prometheus.MustRegister(nriPluginRequestsLatencySeconds)
4848
prometheus.MustRegister(publishedDevicesTotal)
4949
prometheus.MustRegister(lastPublishedTime)
50+
prometheus.MustRegister(inventoryStartupDurationSeconds)
5051
})
5152
}
5253

@@ -87,4 +88,10 @@ var (
8788
Name: "last_published_time_seconds",
8889
Help: "The timestamp of the last successful resource publication.",
8990
})
91+
inventoryStartupDurationSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
92+
Namespace: "dranet",
93+
Subsystem: "driver",
94+
Name: "inventory_startup_duration_seconds",
95+
Help: "The duration of the inventory startup.",
96+
})
9097
)

pkg/inventory/db.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ func (db *DB) GetPodNetNs(pod string) string {
156156
}
157157

158158
func (db *DB) Run(ctx context.Context) error {
159+
registerMetrics()
160+
begin := time.Now()
159161
defer close(db.notifications)
160162

161163
// Resources are published periodically or if there is a netlink notification
@@ -171,7 +173,7 @@ func (db *DB) Run(ctx context.Context) error {
171173
db.instance = getInstanceProperties(ctx)
172174
db.gwInterfaces = getDefaultGwInterfaces()
173175
klog.V(2).Infof("Default gateway interfaces: %v", db.gwInterfaces.UnsortedList())
174-
176+
inventoryStartupDurationSeconds.Set(time.Since(begin).Seconds())
175177
for {
176178
err := db.rateLimiter.Wait(ctx)
177179
if err != nil {

pkg/inventory/metrics.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright The Kubernetes Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package inventory
18+
19+
import (
20+
"sync"
21+
22+
"github.com/prometheus/client_golang/prometheus"
23+
)
24+
25+
var registerMetricsOnce sync.Once
26+
27+
func registerMetrics() {
28+
registerMetricsOnce.Do(func() {
29+
prometheus.MustRegister(inventoryStartupDurationSeconds)
30+
})
31+
}
32+
33+
var (
34+
inventoryStartupDurationSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
35+
Namespace: "dranet",
36+
Subsystem: "inventory",
37+
Name: "inventory_startup_duration_seconds",
38+
Help: "The duration of the inventory startup.",
39+
})
40+
)

0 commit comments

Comments
 (0)