Skip to content
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

fix(e2e): Avoid nested Gomega fields matcher #2833

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 47 additions & 43 deletions e2e/common/operator_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func TestMetrics(t *testing.T) {
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
Expect(Kamel("run", "-n", ns, "files/Java.java",
"-t", "prometheus.enabled=true",
"-t", "prometheus.pod-monitor=false").Execute()).To(Succeed())
"-t", "prometheus.pod-monitor=false",
).Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expand Down Expand Up @@ -253,26 +254,22 @@ func TestMetrics(t *testing.T) {
Expect(integrationReconciliations).To(BeNumerically(">", 0))

// Check it matches the observation in the corresponding metric
Expect(metrics["camel_k_reconciliation_duration_seconds"]).To(PointTo(MatchFields(IgnoreExtras,
Fields{
"Name": EqualP("camel_k_reconciliation_duration_seconds"),
"Help": EqualP("Camel K reconciliation loop duration"),
"Type": EqualP(prometheus.MetricType_HISTOGRAM),
"Metric": ContainElement(MatchFieldsP(IgnoreExtras, Fields{
"Label": ConsistOf(
label("group", v1.SchemeGroupVersion.Group),
label("version", v1.SchemeGroupVersion.Version),
label("kind", "Integration"),
label("namespace", it.Namespace),
label("result", "Reconciled"),
label("tag", ""),
),
"Histogram": MatchFieldsP(IgnoreExtras, Fields{
"SampleCount": EqualP(uint64(integrationReconciliations)),
}),
})),
},
)))
integrationReconciled := getMetric(metrics["camel_k_reconciliation_duration_seconds"],
MatchFieldsP(IgnoreExtras, Fields{
"Label": ConsistOf(
label("group", v1.SchemeGroupVersion.Group),
label("version", v1.SchemeGroupVersion.Version),
label("kind", "Integration"),
label("namespace", it.Namespace),
label("result", "Reconciled"),
label("tag", ""),
),
}))
Expect(integrationReconciled).NotTo(BeNil())
integrationReconciledCount := *integrationReconciled.Histogram.SampleCount
Expect(integrationReconciledCount).To(BeNumerically(">", 0))

Expect(integrationReconciliations).To(BeNumerically("==", integrationReconciledCount))

// Count the number of IntegrationKit reconciliations
integrationKitReconciliations, err := counter.Count(MatchFields(IgnoreExtras, Fields{
Expand All @@ -285,26 +282,22 @@ func TestMetrics(t *testing.T) {
Expect(integrationKitReconciliations).To(BeNumerically(">", 0))

// Check it matches the observation in the corresponding metric
Expect(metrics["camel_k_reconciliation_duration_seconds"]).To(PointTo(MatchFields(IgnoreExtras,
Fields{
"Name": EqualP("camel_k_reconciliation_duration_seconds"),
"Help": EqualP("Camel K reconciliation loop duration"),
"Type": EqualP(prometheus.MetricType_HISTOGRAM),
"Metric": ContainElement(MatchFieldsP(IgnoreExtras, Fields{
"Label": ConsistOf(
label("group", v1.SchemeGroupVersion.Group),
label("version", v1.SchemeGroupVersion.Version),
label("kind", "IntegrationKit"),
label("namespace", it.Status.IntegrationKit.Namespace),
label("result", "Reconciled"),
label("tag", ""),
),
"Histogram": MatchFieldsP(IgnoreExtras, Fields{
"SampleCount": EqualP(uint64(integrationKitReconciliations)),
}),
})),
},
)))
integrationKitReconciled := getMetric(metrics["camel_k_reconciliation_duration_seconds"],
MatchFieldsP(IgnoreExtras, Fields{
"Label": ConsistOf(
label("group", v1.SchemeGroupVersion.Group),
label("version", v1.SchemeGroupVersion.Version),
label("kind", "IntegrationKit"),
label("namespace", it.Status.IntegrationKit.Namespace),
label("result", "Reconciled"),
label("tag", ""),
),
}))
Expect(integrationKitReconciled).NotTo(BeNil())
integrationKitReconciledCount := *integrationKitReconciled.Histogram.SampleCount
Expect(integrationKitReconciledCount).To(BeNumerically(">", 0))

Expect(integrationKitReconciliations).To(BeNumerically("==", integrationKitReconciledCount))

// Count the number of Build reconciliations
buildReconciliations, err := counter.Count(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -442,7 +435,18 @@ func TestMetrics(t *testing.T) {
durationFromLogs := ts2.Sub(ts1)

// Check both durations match
Expect(math.Abs((durationFromLogs - duration).Seconds())).To(BeNumerically("<", 1))
Expect(math.Abs((durationFromLogs - duration).Seconds())).To(BeNumerically("<=", 1))

// Retrieve the first readiness duration from the metric
Expect(metrics).To(HaveKey("camel_k_integration_first_readiness_seconds"))
metric := metrics["camel_k_integration_first_readiness_seconds"].Metric
Expect(metric).To(HaveLen(1))
histogram := metric[0].Histogram
Expect(histogram).NotTo(BeNil())

// Check both durations match
d := duration.Seconds()
Expect(math.Abs(*histogram.SampleSum - d)).To(BeNumerically("<=", 1))

// Check the duration is correctly observed in the corresponding metric
Expect(metrics).To(HaveKey("camel_k_integration_first_readiness_seconds"))
Expand All @@ -455,7 +459,7 @@ func TestMetrics(t *testing.T) {
{
Histogram: &prometheus.Histogram{
SampleCount: uint64P(1),
SampleSum: float64P(duration.Seconds()),
SampleSum: histogram.SampleSum,
Bucket: buckets(duration.Seconds(), []float64{5, 10, 30, 60, 120, math.Inf(1)}),
},
},
Expand Down