Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/inventory/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (db *DB) GetPodNetNs(pod string) string {
}

func (db *DB) Run(ctx context.Context) error {
registerMetrics()
begin := time.Now()
defer close(db.notifications)

// Resources are published periodically or if there is a netlink notification
Expand All @@ -171,7 +173,7 @@ func (db *DB) Run(ctx context.Context) error {
db.instance = getInstanceProperties(ctx)
db.gwInterfaces = getDefaultGwInterfaces()
klog.V(2).Infof("Default gateway interfaces: %v", db.gwInterfaces.UnsortedList())

inventoryStartupDurationSeconds.Set(time.Since(begin).Seconds())
for {
err := db.rateLimiter.Wait(ctx)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions pkg/inventory/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright The Kubernetes Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package inventory

import (
"sync"

"github.com/prometheus/client_golang/prometheus"
)

var registerMetricsOnce sync.Once

func registerMetrics() {
registerMetricsOnce.Do(func() {
prometheus.MustRegister(inventoryStartupDurationSeconds)
})
}

var (
inventoryStartupDurationSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "dranet",
Subsystem: "inventory",
Name: "inventory_startup_duration_seconds",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final metric name for this would end up being dranet_inventory_inventory_startup_duration_seconds. Should we strip the name to startup_duration_seconds?

Also, inventory startup name doesn't seem to be doing justice to what its measuring, given it excludes the initial scan completely. If our intent is to measure the cloud-provider detection latency, should we change the name to focus on the cloud provider? (And if we do that, then maybe we can wrap the metric within getInstanceProperties?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, it's more about the cloud provider latency here. Let me update this after the refactor being done with cloud provider hints #118

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Help: "The duration of the inventory startup.",
})
)
Loading