Skip to content

Commit

Permalink
test for name and description (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Confino <[email protected]>
  • Loading branch information
yasmin-aumeeruddy and benjamin-confino authored Jun 20, 2024
1 parent 701aa1f commit dcaf771
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.microprofile.telemetry.metrics.tck.http;

import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -55,6 +56,9 @@

public class HttpHistogramTest extends Arquillian {

private static final String HTTP_SERVER_REQUEST_DURATION = "http.server.request.duration";
private static final String HTTP_SERVER_REQUEST_DURATION_DESCRIPTION = "Duration of HTTP server requests.";

private static final AttributeKey<String> HTTP_REQUEST_METHOD = AttributeKey.stringKey("http.request.method");
private static final AttributeKey<String> URL_SCHEME = AttributeKey.stringKey("url.scheme");
private static final AttributeKey<String> HTTP_RESPONSE_STATUS_CODE =
Expand Down Expand Up @@ -111,7 +115,26 @@ void testHTTPMetricAttributes() {
}

List<MetricData> items = metricExporter.getFinishedMetricItems();

List<MetricData> unfilteredItems = new ArrayList<MetricData>(items);

Assert.assertFalse(items.isEmpty(), "We did not find any MetricData");

// Filter out any MetricData objects that have the wrong name or description
items.removeIf(md -> !md.getName().equals(HTTP_SERVER_REQUEST_DURATION));
Assert.assertFalse(items.isEmpty(),
"We did not find any MetricData with the name " + HTTP_SERVER_REQUEST_DURATION + " we found "
+ unfilteredItems.stream()
.map(md -> md.toString())
.collect(Collectors.joining(", ")));

items.removeIf(md -> !md.getDescription().equals(HTTP_SERVER_REQUEST_DURATION_DESCRIPTION));
Assert.assertFalse(items.isEmpty(),
"We did not find any MetricData with the descriptoin " + HTTP_SERVER_REQUEST_DURATION_DESCRIPTION
+ " we found " + unfilteredItems.stream()
.map(md -> md.toString())
.collect(Collectors.joining(", ")));

// Build maps of the expected attribute keys and their values
Map<AttributeKey<String>, String> successfulHTTPMethod = new HashMap<AttributeKey<String>, String>();
successfulHTTPMethod.put(HTTP_REQUEST_METHOD, "GET");
successfulHTTPMethod.put(URL_SCHEME, "http");
Expand All @@ -127,6 +150,8 @@ void testHTTPMetricAttributes() {
failingHTTPMethod.put(HTTP_ROUTE, url.getPath() + "fail");
failingHTTPMethod.put(ERROR_TYPE, "500");

// Test that one of the MetricData objects with the right name and description also
// has all the items in a map
testMetricData(successfulHTTPMethod, items);
testMetricData(failingHTTPMethod, items);
}
Expand Down

0 comments on commit dcaf771

Please sign in to comment.