-
Notifications
You must be signed in to change notification settings - Fork 2k
Add workqueue prometheus metrics #1266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package collectors | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
// WorkQueueMetricsCollector collects the metrics about the work queue, which the Ingress Controller uses to process changes to the resources in the cluster. | ||
// implements the prometheus.Collector interface | ||
type WorkQueueMetricsCollector struct { | ||
Dean-Coakley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
depth *prometheus.GaugeVec | ||
latency *prometheus.HistogramVec | ||
workDuration *prometheus.HistogramVec | ||
} | ||
|
||
// NewWorkQueueMetricsCollector creates a new WorkQueueMetricsCollector | ||
func NewWorkQueueMetricsCollector(constLabels map[string]string) *WorkQueueMetricsCollector { | ||
const workqueueSubsystem = "workqueue" | ||
var latencyBucketSeconds = []float64{0.1, 0.5, 1, 5, 10, 50} | ||
|
||
return &WorkQueueMetricsCollector{ | ||
depth: prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: workqueueSubsystem, | ||
Name: "depth", | ||
Help: "Current depth of workqueue", | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{"name"}, | ||
), | ||
latency: prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: workqueueSubsystem, | ||
Name: "queue_duration_seconds", | ||
Dean-Coakley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Help: "How long in seconds an item stays in workqueue before being processed", | ||
Buckets: latencyBucketSeconds, | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{"name"}, | ||
), | ||
workDuration: prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: workqueueSubsystem, | ||
Name: "work_duration_seconds", | ||
Help: "How long in seconds processing an item from workqueue takes", | ||
Buckets: latencyBucketSeconds, | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{"name"}, | ||
), | ||
} | ||
} | ||
|
||
// Collect implements the prometheus.Collector interface Collect method | ||
func (wqc *WorkQueueMetricsCollector) Collect(ch chan<- prometheus.Metric) { | ||
wqc.depth.Collect(ch) | ||
wqc.latency.Collect(ch) | ||
wqc.workDuration.Collect(ch) | ||
} | ||
|
||
// Describe implements the prometheus.Collector interface Describe method | ||
func (wqc *WorkQueueMetricsCollector) Describe(ch chan<- *prometheus.Desc) { | ||
wqc.depth.Describe(ch) | ||
wqc.latency.Describe(ch) | ||
wqc.workDuration.Describe(ch) | ||
} | ||
|
||
// Register registers all the metrics of the collector | ||
func (wqc *WorkQueueMetricsCollector) Register(registry *prometheus.Registry) error { | ||
workqueue.SetProvider(wqc) | ||
return registry.Register(wqc) | ||
} | ||
|
||
// NewDepthMetric implements the workqueue.MetricsProvider interface NewDepthMetric method | ||
func (wqc *WorkQueueMetricsCollector) NewDepthMetric(name string) workqueue.GaugeMetric { | ||
return wqc.depth.WithLabelValues(name) | ||
} | ||
|
||
// NewLatencyMetric implements the workqueue.MetricsProvider interface NewLatencyMetric method | ||
func (wqc *WorkQueueMetricsCollector) NewLatencyMetric(name string) workqueue.HistogramMetric { | ||
return wqc.latency.WithLabelValues(name) | ||
|
||
} | ||
|
||
// NewWorkDurationMetric implements the workqueue.MetricsProvider interface NewWorkDurationMetric method | ||
func (wqc *WorkQueueMetricsCollector) NewWorkDurationMetric(name string) workqueue.HistogramMetric { | ||
return wqc.workDuration.WithLabelValues(name) | ||
} | ||
|
||
// noopMetric implements the workqueue.GaugeMetric and workqueue.HistogramMetric interfaces | ||
type noopMetric struct{} | ||
|
||
func (noopMetric) Inc() {} | ||
func (noopMetric) Dec() {} | ||
func (noopMetric) Set(float64) {} | ||
func (noopMetric) Observe(float64) {} | ||
|
||
// NewAddsMetric implements the workqueue.MetricsProvider interface NewAddsMetric method | ||
func (*WorkQueueMetricsCollector) NewAddsMetric(string) workqueue.CounterMetric { | ||
return noopMetric{} | ||
} | ||
|
||
// NewUnfinishedWorkSecondsMetric implements the workqueue.MetricsProvider interface NewUnfinishedWorkSecondsMetric method | ||
func (*WorkQueueMetricsCollector) NewUnfinishedWorkSecondsMetric(string) workqueue.SettableGaugeMetric { | ||
return noopMetric{} | ||
} | ||
|
||
// NewLongestRunningProcessorSecondsMetric implements the workqueue.MetricsProvider interface NewLongestRunningProcessorSecondsMetric method | ||
func (*WorkQueueMetricsCollector) NewLongestRunningProcessorSecondsMetric(string) workqueue.SettableGaugeMetric { | ||
return noopMetric{} | ||
} | ||
|
||
// NewRetriesMetric implements the workqueue.MetricsProvider interface NewRetriesMetric method | ||
func (*WorkQueueMetricsCollector) NewRetriesMetric(string) workqueue.CounterMetric { | ||
return noopMetric{} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.