Skip to content

Commit b1bf975

Browse files
author
Aman Brar
authored
added fix for prometheus tests (#193)
1 parent a9daea0 commit b1bf975

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

sample-apps/prometheus/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func loadMetricCountFromEnv() int {
7474
func updateMetrics() {
7575
for {
7676
time.Sleep(time.Second * 30)
77+
mtx.Lock()
7778
mc.timestamp = float64(time.Now().UnixNano()) / 1000000000
7879
for idx := 0; idx < mc.metricCount; idx++ {
79-
mtx.Lock()
8080
mc.counters[idx].Add(rand.Float64())
8181
mc.gauges[idx].Add(rand.Float64())
8282
lowerBound := math.Mod(rand.Float64(), 1)
@@ -85,8 +85,8 @@ func updateMetrics() {
8585
mc.histograms[idx].Observe(i)
8686
mc.summarys[idx].Observe(i)
8787
}
88-
mtx.Unlock()
8988
}
89+
mtx.Unlock()
9090
}
9191
}
9292

terraform/eks/pull_mode_deployment.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
# Pull mode deployments
33
##########################################
44

5-
resource "time_sleep" "wait_until_sample_app_produces_metrics" {
6-
create_duration = "30s"
7-
depends_on = [kubernetes_service.sample_app_service]
8-
}
9-
105
# deploy aoc and mocked server
116
resource "kubernetes_deployment" "pull_mode_aoc_deployment" {
127
count = var.sample_app_mode == "pull" ? 1 : 0
13-
depends_on = [time_sleep.wait_until_sample_app_produces_metrics]
148

159
metadata {
1610
name = "aoc"

validator/src/main/java/com/amazon/aoc/models/prometheus/PrometheusMetric.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static int staticPrometheusMetricCompare(PrometheusMetric o1, PrometheusM
7878
}
7979

8080
// check metric value
81-
if (o1.getMetricValue().equals(o2.getMetricValue())) {
81+
if (!o1.getMetricValue().equals(o2.getMetricValue())) {
8282
return o1.getMetricValue().compareTo(o2.getMetricValue());
8383
}
8484

validator/src/main/java/com/amazon/aoc/validators/PrometheusMetricValidator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@ public class PrometheusMetricValidator implements IValidator {
5050
@Override
5151
public void validate() throws Exception {
5252
log.info("Start prometheus metric validating");
53-
log.info("sleeping to allow metrics to propogate through AOC");
54-
TimeUnit.SECONDS.sleep(30);
53+
log.info("allow sample app load balancer to start");
54+
TimeUnit.SECONDS.sleep(60);
5555
log.info("resuming validation");
5656

5757
RetryHelper.retry(
5858
MAX_RETRY_COUNT,
5959
() -> {
6060
// get expected metrics
6161
List<PrometheusMetric> expectedMetricList = this.getExpectedMetricList(context);
62+
63+
// Since we add 20s to timestamp, must sleep 20s between requests
64+
TimeUnit.SECONDS.sleep(20);
65+
6266
// get metric from cortex
6367
CortexService cortexService = new CortexService(context);
6468

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-
22
validationType: "prom-metric"
3-
shouldValidateMetricValue: true
3+
shouldValidateMetricValue: false
44
expectedResultPath: "/expected_metrics"

0 commit comments

Comments
 (0)