mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-27 23:48:30 +00:00
Merge pull request #76496 from danielqsj/metrics-2
Clean deprecated metrics Kubernetes-commit: f4db8212be53c69a27d893d6a4111422fbce8008
This commit is contained in:
commit
7ec8a74ae9
@ -131,16 +131,14 @@ func (m *defaultQueueMetrics) updateUnfinishedWork() {
|
|||||||
var total float64
|
var total float64
|
||||||
var oldest float64
|
var oldest float64
|
||||||
for _, t := range m.processingStartTimes {
|
for _, t := range m.processingStartTimes {
|
||||||
age := m.sinceInMicroseconds(t)
|
age := m.sinceInSeconds(t)
|
||||||
total += age
|
total += age
|
||||||
if age > oldest {
|
if age > oldest {
|
||||||
oldest = age
|
oldest = age
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Convert to seconds; microseconds is unhelpfully granular for this.
|
|
||||||
total /= 1000000
|
|
||||||
m.unfinishedWorkSeconds.Set(total)
|
m.unfinishedWorkSeconds.Set(total)
|
||||||
m.longestRunningProcessor.Set(oldest / 1000000)
|
m.longestRunningProcessor.Set(oldest)
|
||||||
}
|
}
|
||||||
|
|
||||||
type noMetrics struct{}
|
type noMetrics struct{}
|
||||||
@ -150,11 +148,6 @@ func (noMetrics) get(item t) {}
|
|||||||
func (noMetrics) done(item t) {}
|
func (noMetrics) done(item t) {}
|
||||||
func (noMetrics) updateUnfinishedWork() {}
|
func (noMetrics) updateUnfinishedWork() {}
|
||||||
|
|
||||||
// Gets the time since the specified start in microseconds.
|
|
||||||
func (m *defaultQueueMetrics) sinceInMicroseconds(start time.Time) float64 {
|
|
||||||
return float64(m.clock.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the time since the specified start in seconds.
|
// Gets the time since the specified start in seconds.
|
||||||
func (m *defaultQueueMetrics) sinceInSeconds(start time.Time) float64 {
|
func (m *defaultQueueMetrics) sinceInSeconds(start time.Time) float64 {
|
||||||
return m.clock.Since(start).Seconds()
|
return m.clock.Since(start).Seconds()
|
||||||
|
@ -167,22 +167,6 @@ func (m *testMetricsProvider) NewRetriesMetric(name string) CounterMetric {
|
|||||||
return &m.retries
|
return &m.retries
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSinceInMicroseconds(t *testing.T) {
|
|
||||||
mp := testMetricsProvider{}
|
|
||||||
c := clock.NewFakeClock(time.Now())
|
|
||||||
mf := queueMetricsFactory{metricsProvider: &mp}
|
|
||||||
m := mf.newQueueMetrics("test", c)
|
|
||||||
dqm := m.(*defaultQueueMetrics)
|
|
||||||
|
|
||||||
for _, i := range []int{1, 50, 100, 500, 1000, 10000, 100000, 1000000} {
|
|
||||||
n := c.Now()
|
|
||||||
c.Step(time.Duration(i) * time.Microsecond)
|
|
||||||
if e, a := float64(i), dqm.sinceInMicroseconds(n); e != a {
|
|
||||||
t.Errorf("Expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMetrics(t *testing.T) {
|
func TestMetrics(t *testing.T) {
|
||||||
mp := testMetricsProvider{}
|
mp := testMetricsProvider{}
|
||||||
t0 := time.Unix(0, 0)
|
t0 := time.Unix(0, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user