Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit 779eb8a

Browse files
authored
Merge pull request #1926 from serathius/fix-metrics
Fix measuring remaining timestamp/duration metrics
2 parents e843003 + d93e43c commit 779eb8a

File tree

8 files changed

+46
-34
lines changed

8 files changed

+46
-34
lines changed

events/manager/manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ func (rm *realManager) Housekeep() {
9090
}
9191

9292
func (rm *realManager) housekeep() {
93-
defer lastHousekeepTimestamp.Set(float64(time.Now().Unix()))
93+
defer func() {
94+
lastHousekeepTimestamp.Set(float64(time.Now().Unix()))
95+
}()
9496

9597
LatestScrapeTime = time.Now()
9698

events/sinks/manager.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ const (
2929
)
3030

3131
var (
32-
// Time spent exporting events to sink in microseconds.
32+
// Time spent exporting events to sink in milliseconds.
3333
exporterDuration = prometheus.NewSummaryVec(
3434
prometheus.SummaryOpts{
3535
Namespace: "eventer",
3636
Subsystem: "exporter",
37-
Name: "duration_microseconds",
38-
Help: "Time spent exporting events to sink in microseconds.",
37+
Name: "duration_milliseconds",
38+
Help: "Time spent exporting events to sink in milliseconds.",
3939
},
4040
[]string{"exporter"},
4141
)
@@ -137,8 +137,10 @@ func (this *sinkManager) Stop() {
137137

138138
func export(s core.EventSink, data *core.EventBatch) {
139139
startTime := time.Now()
140-
defer exporterDuration.
141-
WithLabelValues(s.Name()).
142-
Observe(float64(time.Since(startTime)) / float64(time.Microsecond))
140+
defer func() {
141+
exporterDuration.
142+
WithLabelValues(s.Name()).
143+
Observe(float64(time.Since(startTime)) / float64(time.Millisecond))
144+
}()
143145
s.ExportEvents(data)
144146
}

events/sources/kubernetes/kubernetes_source.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ var (
5555
prometheus.SummaryOpts{
5656
Namespace: "eventer",
5757
Subsystem: "scraper",
58-
Name: "duration_microseconds",
59-
Help: "Time spent scraping events in microseconds.",
58+
Name: "duration_milliseconds",
59+
Help: "Time spent scraping events in milliseconds.",
6060
})
6161
)
6262

@@ -78,8 +78,10 @@ type KubernetesEventSource struct {
7878

7979
func (this *KubernetesEventSource) GetNewEvents() *core.EventBatch {
8080
startTime := time.Now()
81-
defer lastEventTimestamp.Set(float64(time.Now().Unix()))
82-
defer scrapEventsDuration.Observe(float64(time.Since(startTime)) / float64(time.Microsecond))
81+
defer func() {
82+
lastEventTimestamp.Set(float64(time.Now().Unix()))
83+
scrapEventsDuration.Observe(float64(time.Since(startTime)) / float64(time.Millisecond))
84+
}()
8385
result := core.EventBatch{
8486
Timestamp: time.Now(),
8587
Events: []*kubeapi.Event{},

metrics/manager/manager.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ const (
2929
)
3030

3131
var (
32-
// The Time spent in a processor in microseconds.
32+
// The Time spent in a processor in milliseconds.
3333
processorDuration = prometheus.NewSummaryVec(
3434
prometheus.SummaryOpts{
3535
Namespace: "heapster",
3636
Subsystem: "processor",
37-
Name: "duration_microseconds",
38-
Help: "The Time spent in a processor in microseconds.",
37+
Name: "duration_milliseconds",
38+
Help: "The Time spent in a processor in milliseconds.",
3939
},
4040
[]string{"processor"},
4141
)
@@ -149,9 +149,11 @@ func (rm *realManager) housekeep(start, end time.Time) {
149149

150150
func process(p core.DataProcessor, data *core.DataBatch) (*core.DataBatch, error) {
151151
startTime := time.Now()
152-
defer processorDuration.
153-
WithLabelValues(p.Name()).
154-
Observe(float64(time.Since(startTime)) / float64(time.Microsecond))
152+
defer func() {
153+
processorDuration.
154+
WithLabelValues(p.Name()).
155+
Observe(float64(time.Since(startTime)) / float64(time.Millisecond))
156+
}()
155157

156158
return p.Process(data)
157159
}

metrics/sinks/manager.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ func export(s core.DataSink, data *core.DataBatch) {
152152
lastExportTimestamp.
153153
WithLabelValues(s.Name()).
154154
Set(float64(time.Now().Unix()))
155-
}()
156-
defer func() {
157155
exporterDuration.
158156
WithLabelValues(s.Name()).
159157
Observe(float64(time.Since(startTime)) / float64(time.Millisecond))

metrics/sources/kubelet/kubelet.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ var (
5050
prometheus.SummaryOpts{
5151
Namespace: "heapster",
5252
Subsystem: "kubelet",
53-
Name: "request_duration_microseconds",
54-
Help: "The Kubelet request latencies in microseconds.",
53+
Name: "request_duration_milliseconds",
54+
Help: "The Kubelet request latencies in milliseconds.",
5555
},
5656
[]string{"node"},
5757
)
@@ -260,7 +260,9 @@ func (this *kubeletMetricsSource) ScrapeMetrics(start, end time.Time) (*DataBatc
260260

261261
func (this *kubeletMetricsSource) scrapeKubelet(client *KubeletClient, host Host, start, end time.Time) ([]cadvisor.ContainerInfo, error) {
262262
startTime := time.Now()
263-
defer kubeletRequestLatency.WithLabelValues(this.hostname).Observe(float64(time.Since(startTime)))
263+
defer func() {
264+
kubeletRequestLatency.WithLabelValues(this.hostname).Observe(float64(time.Since(startTime)) / float64(time.Millisecond))
265+
}()
264266
return client.GetAllRawContainers(host, start, end)
265267
}
266268

metrics/sources/manager.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ var (
4242
[]string{"source"},
4343
)
4444

45-
// Time spent exporting scraping sources in microseconds..
45+
// Time spent exporting scraping sources in milliseconds.
4646
scraperDuration = prometheus.NewSummaryVec(
4747
prometheus.SummaryOpts{
4848
Namespace: "heapster",
4949
Subsystem: "scraper",
50-
Name: "duration_microseconds",
51-
Help: "Time spent scraping sources in microseconds.",
50+
Name: "duration_milliseconds",
51+
Help: "Time spent scraping sources in milliseconds.",
5252
},
5353
[]string{"source"},
5454
)
@@ -164,12 +164,14 @@ responseloop:
164164
func scrape(s MetricsSource, start, end time.Time) (*DataBatch, error) {
165165
sourceName := s.Name()
166166
startTime := time.Now()
167-
defer lastScrapeTimestamp.
168-
WithLabelValues(sourceName).
169-
Set(float64(time.Now().Unix()))
170-
defer scraperDuration.
171-
WithLabelValues(sourceName).
172-
Observe(float64(time.Since(startTime)) / float64(time.Microsecond))
167+
defer func() {
168+
lastScrapeTimestamp.
169+
WithLabelValues(sourceName).
170+
Set(float64(time.Now().Unix()))
171+
scraperDuration.
172+
WithLabelValues(sourceName).
173+
Observe(float64(time.Since(startTime)) / float64(time.Millisecond))
174+
}()
173175

174176
return s.ScrapeMetrics(start, end)
175177
}

metrics/sources/summary/summary.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ var (
3838
prometheus.SummaryOpts{
3939
Namespace: "heapster",
4040
Subsystem: "kubelet_summary",
41-
Name: "request_duration_microseconds",
42-
Help: "The Kubelet summary request latencies in microseconds.",
41+
Name: "request_duration_milliseconds",
42+
Help: "The Kubelet summary request latencies in milliseconds.",
4343
},
4444
[]string{"node"},
4545
)
@@ -89,7 +89,9 @@ func (this *summaryMetricsSource) ScrapeMetrics(start, end time.Time) (*DataBatc
8989

9090
summary, err := func() (*stats.Summary, error) {
9191
startTime := time.Now()
92-
defer summaryRequestLatency.WithLabelValues(this.node.HostName).Observe(float64(time.Since(startTime)))
92+
defer func() {
93+
summaryRequestLatency.WithLabelValues(this.node.HostName).Observe(float64(time.Since(startTime)) / float64(time.Millisecond))
94+
}()
9395
return this.kubeletClient.GetSummary(this.node.Host)
9496
}()
9597

0 commit comments

Comments
 (0)