You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/03/12 15:39:37 UTC
[camel-k] 06/10: test: Add build queue duration metric e2e test
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit e4b5afd2dc87964ee6cba71702f7dd0896016923
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Mar 11 12:38:40 2021 +0100
test: Add build queue duration metric e2e test
---
e2e/common/metrics_test.go | 58 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 55 insertions(+), 3 deletions(-)
diff --git a/e2e/common/metrics_test.go b/e2e/common/metrics_test.go
index d4ce252..202387f 100644
--- a/e2e/common/metrics_test.go
+++ b/e2e/common/metrics_test.go
@@ -82,7 +82,7 @@ func TestMetrics(t *testing.T) {
AddStep(MatchFields(IgnoreExtras, Fields{
"LoggerName": Equal("camel-k.controller.build"),
"Message": Equal("Build state transition"),
- "Phase": Equal("Pending"),
+ "Phase": Equal(string(camelv1.BuildPhasePending)),
"RequestName": Equal(build.Name),
}), LogEntryNoop).
AddStep(MatchFields(IgnoreExtras, Fields{
@@ -101,8 +101,8 @@ func TestMetrics(t *testing.T) {
}), func(l *LogEntry) { ts2 = l.Timestamp.Time }).
Walk()
Expect(err).To(BeNil())
- Expect(ts1).NotTo(BeNil())
- Expect(ts2).NotTo(BeNil())
+ Expect(ts1).NotTo(BeZero())
+ Expect(ts2).NotTo(BeZero())
Expect(ts2).To(BeTemporally(">", ts1))
durationFromLogs := ts2.Sub(ts1)
@@ -328,6 +328,58 @@ func TestMetrics(t *testing.T) {
Expect(buildReconciliations).To(BeNumerically("==", buildReconciledCount+buildRequeuedCount))
})
+ t.Run("Build queue duration metric", func(t *testing.T) {
+ var ts1, ts2 time.Time
+ // The start queuing time is taken from the creation time
+ ts1 = build.CreationTimestamp.Time
+
+ // Retrieve the end queuing time from the logs
+ err = NewLogWalker(&logs).
+ AddStep(MatchFields(IgnoreExtras, Fields{
+ "LoggerName": Equal("camel-k.controller.build"),
+ "Message": Equal("Build state transition"),
+ "Phase": Equal(string(camelv1.BuildPhasePending)),
+ "RequestName": Equal(build.Name),
+ }), func(l *LogEntry) { ts2 = l.Timestamp.Time }).
+ Walk()
+ Expect(err).To(BeNil())
+ Expect(ts1).NotTo(BeZero())
+ Expect(ts2).NotTo(BeZero())
+
+ durationFromLogs := ts2.Sub(ts1)
+
+ // Retrieve the queuing duration from the metric
+ Expect(metrics).To(HaveKey("camel_k_build_queue_duration_seconds"))
+ metric := metrics["camel_k_build_queue_duration_seconds"].Metric
+ Expect(metric).To(HaveLen(1))
+ histogram := metric[0].Histogram
+ Expect(histogram).NotTo(BeNil())
+ Expect(histogram.SampleSum).NotTo(BeNil())
+
+ duration := *histogram.SampleSum
+
+ // Check both durations match
+ Expect(math.Abs(durationFromLogs.Seconds() - duration)).To(BeNumerically("<", 1))
+
+ // Check the queuing duration is correctly observed in the corresponding metric
+ Expect(metrics).To(HaveKeyWithValue("camel_k_build_queue_duration_seconds",
+ EqualP(prometheus.MetricFamily{
+ Name: stringP("camel_k_build_queue_duration_seconds"),
+ Help: stringP("Camel K build queue duration"),
+ Type: metricTypeP(prometheus.MetricType_HISTOGRAM),
+ Metric: []*prometheus.Metric{
+ {
+ Histogram: &prometheus.Histogram{
+ SampleCount: uint64P(1),
+ SampleSum: histogram.SampleSum,
+ Bucket: buckets(0, []float64{5, 15, 30, 60, 300, math.Inf(1)}),
+ },
+ },
+ },
+ }),
+ ))
+ })
+
t.Run("Integration metrics", func(t *testing.T) {
pod := IntegrationPod(ns, name)()
response, err := TestClient().CoreV1().RESTClient().Get().