Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
fd77aa5a
Commit
fd77aa5a
authored
Nov 12, 2018
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add longest_running_processor_microseconds metric
parent
578962d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
10 deletions
+44
-10
prometheus.go
pkg/util/workqueue/prometheus/prometheus.go
+11
-0
metrics.go
staging/src/k8s.io/client-go/util/workqueue/metrics.go
+25
-10
metrics_test.go
staging/src/k8s.io/client-go/util/workqueue/metrics_test.go
+8
-0
No files found.
pkg/util/workqueue/prometheus/prometheus.go
View file @
fd77aa5a
...
...
@@ -84,6 +84,17 @@ func (prometheusMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) wor
return
unfinished
}
func
(
prometheusMetricsProvider
)
NewLongestRunningProcessorMicrosecondsMetric
(
name
string
)
workqueue
.
SettableGaugeMetric
{
unfinished
:=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Subsystem
:
name
,
Name
:
"longest_running_procesor_microseconds"
,
Help
:
"How many microseconds has the longest running "
+
"processor for "
+
name
+
" been running."
,
})
prometheus
.
Register
(
unfinished
)
return
unfinished
}
func
(
prometheusMetricsProvider
)
NewRetriesMetric
(
name
string
)
workqueue
.
CounterMetric
{
retries
:=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Subsystem
:
name
,
...
...
staging/src/k8s.io/client-go/util/workqueue/metrics.go
View file @
fd77aa5a
...
...
@@ -80,7 +80,8 @@ type defaultQueueMetrics struct {
processingStartTimes
map
[
t
]
time
.
Time
// how long have current threads been working?
unfinishedWorkSeconds
SettableGaugeMetric
unfinishedWorkSeconds
SettableGaugeMetric
longestRunningProcessor
SettableGaugeMetric
}
func
(
m
*
defaultQueueMetrics
)
add
(
item
t
)
{
...
...
@@ -120,13 +121,21 @@ func (m *defaultQueueMetrics) done(item t) {
}
func
(
m
*
defaultQueueMetrics
)
updateUnfinishedWork
()
{
// Note that a summary metric would be better for this, but prometheus
// doesn't seem to have non-hacky ways to reset the summary metrics.
var
total
float64
var
oldest
float64
for
_
,
t
:=
range
m
.
processingStartTimes
{
total
+=
m
.
sinceInMicroseconds
(
t
)
age
:=
m
.
sinceInMicroseconds
(
t
)
total
+=
age
if
age
>
oldest
{
oldest
=
age
}
}
// Convert to seconds; microseconds is unhelpfully granular for this.
total
/=
1000000
m
.
unfinishedWorkSeconds
.
Set
(
total
)
m
.
longestRunningProcessor
.
Set
(
oldest
)
// in microseconds.
}
type
noMetrics
struct
{}
...
...
@@ -164,6 +173,7 @@ type MetricsProvider interface {
NewLatencyMetric
(
name
string
)
SummaryMetric
NewWorkDurationMetric
(
name
string
)
SummaryMetric
NewUnfinishedWorkSecondsMetric
(
name
string
)
SettableGaugeMetric
NewLongestRunningProcessorMicrosecondsMetric
(
name
string
)
SettableGaugeMetric
NewRetriesMetric
(
name
string
)
CounterMetric
}
...
...
@@ -189,6 +199,10 @@ func (_ noopMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) Settabl
return
noopMetric
{}
}
func
(
_
noopMetricsProvider
)
NewLongestRunningProcessorMicrosecondsMetric
(
name
string
)
SettableGaugeMetric
{
return
noopMetric
{}
}
func
(
_
noopMetricsProvider
)
NewRetriesMetric
(
name
string
)
CounterMetric
{
return
noopMetric
{}
}
...
...
@@ -215,14 +229,15 @@ func (f *queueMetricsFactory) newQueueMetrics(name string, clock clock.Clock) qu
return
noMetrics
{}
}
return
&
defaultQueueMetrics
{
clock
:
clock
,
depth
:
mp
.
NewDepthMetric
(
name
),
adds
:
mp
.
NewAddsMetric
(
name
),
latency
:
mp
.
NewLatencyMetric
(
name
),
workDuration
:
mp
.
NewWorkDurationMetric
(
name
),
unfinishedWorkSeconds
:
mp
.
NewUnfinishedWorkSecondsMetric
(
name
),
addTimes
:
map
[
t
]
time
.
Time
{},
processingStartTimes
:
map
[
t
]
time
.
Time
{},
clock
:
clock
,
depth
:
mp
.
NewDepthMetric
(
name
),
adds
:
mp
.
NewAddsMetric
(
name
),
latency
:
mp
.
NewLatencyMetric
(
name
),
workDuration
:
mp
.
NewWorkDurationMetric
(
name
),
unfinishedWorkSeconds
:
mp
.
NewUnfinishedWorkSecondsMetric
(
name
),
longestRunningProcessor
:
mp
.
NewLongestRunningProcessorMicrosecondsMetric
(
name
),
addTimes
:
map
[
t
]
time
.
Time
{},
processingStartTimes
:
map
[
t
]
time
.
Time
{},
}
}
...
...
staging/src/k8s.io/client-go/util/workqueue/metrics_test.go
View file @
fd77aa5a
...
...
@@ -94,6 +94,7 @@ type testMetricsProvider struct {
latency
testMetric
duration
testMetric
unfinished
testMetric
longest
testMetric
retries
testMetric
}
...
...
@@ -117,6 +118,10 @@ func (m *testMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) Settab
return
&
m
.
unfinished
}
func
(
m
*
testMetricsProvider
)
NewLongestRunningProcessorMicrosecondsMetric
(
name
string
)
SettableGaugeMetric
{
return
&
m
.
longest
}
func
(
m
*
testMetricsProvider
)
NewRetriesMetric
(
name
string
)
CounterMetric
{
return
&
m
.
retries
}
...
...
@@ -232,6 +237,9 @@ func TestMetrics(t *testing.T) {
if
e
,
a
:=
.001
,
mp
.
unfinished
.
gaugeValue
();
e
!=
a
{
t
.
Errorf
(
"expected %v, got %v"
,
e
,
a
)
}
if
e
,
a
:=
1000.0
,
mp
.
longest
.
gaugeValue
();
e
!=
a
{
t
.
Errorf
(
"expected %v, got %v"
,
e
,
a
)
}
// Finish that one up
q
.
Done
(
i
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment