Skip to content

Commit

Permalink
Upgrade to latest localstack version
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Nov 18, 2024
1 parent f1325c7 commit d404656
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
32 changes: 11 additions & 21 deletions src/test/java/com/exasol/cloudwatch/LocalstackCloudWatchRaw.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.exasol.cloudwatch;

import static java.util.stream.Collectors.toMap;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.CLOUDWATCH;

import java.io.*;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.Instant;
import java.util.*;

import org.testcontainers.containers.localstack.LocalStackContainer;
Expand All @@ -19,7 +19,7 @@
* metric data. This API is for testing only!
*/
public class LocalstackCloudWatchRaw {
private static final String BACKDOOR_API_PATH = "/cloudwatch/metrics/raw";
private static final String BACKDOOR_API_PATH = "/_aws/cloudwatch/metrics/raw";
private final URI backdoorApi;

public LocalstackCloudWatchRaw(final LocalStackContainer localStackContainer) {
Expand All @@ -36,25 +36,18 @@ public SortedMap<Instant, Double> readMetrics(final String expectedMetricName, f
final SortedMap<Instant, Double> result = new TreeMap<>();
for (final Object arrayItem : metrics) {
final JsonObject metric = (JsonObject) arrayItem;
final String timestampString = metric.getString("t");
final Map<String, String> result1 = readDimensions(metric);
final Instant timestamp = Instant.ofEpochSecond(metric.getJsonNumber("t").longValue());
final Map<String, String> dimensions = readDimensions(metric);
final String metricName = metric.getString("n");
if (expectedMetricName.equals(metricName) && testIfDimensionsMatch(result1, dimensionFilter)) {
final Instant instant = readTimestamp(timestampString);
if (expectedMetricName.equals(metricName) && testIfDimensionsMatch(dimensions, dimensionFilter)) {
final double metricValue = metric.getJsonNumber("v").doubleValue();
result.put(instant, metricValue);
result.put(timestamp, metricValue);
}
}
return result;
}
}

private Instant readTimestamp(final String timestampString) {
final LocalDateTime localDateTime = LocalDateTime.parse(timestampString,
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
return localDateTime.toInstant(ZoneOffset.UTC);
}

private boolean testIfDimensionsMatch(final Map<String, String> actual, final Dimension[] filter) {
for (final Dimension dimension : filter) {
if (!actual.containsKey(dimension.name())) {
Expand All @@ -67,12 +60,9 @@ private boolean testIfDimensionsMatch(final Map<String, String> actual, final Di
}

private Map<String, String> readDimensions(final JsonObject metric) {
final JsonArray dimensionsJson = metric.getJsonArray("d");
final Map<String, String> dimensions = new HashMap<>();
for (final Object arrayItem : dimensionsJson) {
final JsonObject dimension = (JsonObject) arrayItem;
dimensions.put(dimension.getString("n"), dimension.getString("v"));
}
return dimensions;
final String tabSeparatedValues = metric.getString("d");
return Arrays.stream(tabSeparatedValues.split("\t")) //
.map(entry -> entry.split("=")) //
.collect(toMap(e -> e[0], e -> e[1]));
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/exasol/cloudwatch/TestConstants.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.exasol.cloudwatch;

public class TestConstants {
public static final String EXASOL_DOCKER_DB_VERSION = "8.27.0";
public static final String LOCAL_STACK_IMAGE = "localstack/localstack:2.2";
public static final String EXASOL_DOCKER_DB_VERSION = "8.32.0";
public static final String LOCAL_STACK_IMAGE = "localstack/localstack:3.8";
}

0 comments on commit d404656

Please sign in to comment.