From 92d9a2e7e3d0ff22a721e54cb6c3102cb6d9fb63 Mon Sep 17 00:00:00 2001 From: David Chan Date: Mon, 8 Aug 2022 20:20:45 -0400 Subject: [PATCH 1/3] Remove JSON from spec + TCK - Remove JSON from specification - Remove JSON related from MPMetricTest -- Replace removed JSON tests with Prom tests (some functionality was tested with JSON and not Prom/OM) - Update ReusedMetricTest to query for Prometheus format - Replace deprecated assertThat call in MultipleBeanInstancesTest - Rename any OpenMetrics mentions to Prometheus - MetricAppBean modified to use labels correctly (strict name x tag combination) - Removed JSON from Optional REST test (i.e. MpMetricOptionalTest) -- Need to validate/test/rewrite in separate PR as current impl unable to do so. --- spec/src/main/asciidoc/architecture.adoc | 14 +- spec/src/main/asciidoc/rest-endpoints.adoc | 322 ----- .../test/optional/MpMetricOptionalTest.java | 412 +----- tck/rest/src/main/base_metrics.xml | 10 +- .../metrics/test/MetricAppBean.java | 18 +- .../metrics/test/MpMetricTest.java | 1144 ++++++++--------- .../metrics/test/ReusedMetricsTest.java | 54 +- .../MultipleBeanInstancesTest.java | 2 +- tck/rest/src/main/resources/base_metrics.xml | 10 +- 9 files changed, 582 insertions(+), 1404 deletions(-) diff --git a/spec/src/main/asciidoc/architecture.adoc b/spec/src/main/asciidoc/architecture.adoc index 56dc923a..1e0a10d4 100644 --- a/spec/src/main/asciidoc/architecture.adoc +++ b/spec/src/main/asciidoc/architecture.adoc @@ -252,7 +252,6 @@ that will probably have multiple instances. Data is exposed via REST over HTTP under the `/metrics` base path in different data formats for `GET` requests: -* JSON format - used when the HTTP Accept header best matches `application/json`. * OpenMetrics exposition format - used when the HTTP Accept header best matches `application/openmetrics-text; version=1.0.0`. Support for this format by implementations is optional. * Prometheus text-based exposition format - used when the HTTP Accept header best matches `text/plain; version=0.0.4`. This format is also returned when no media type is requested (i.e. no Accept header is provided in the request) @@ -276,18 +275,11 @@ The API MUST NOT return a 500 Internal Server Error code to represent a non-exis [cols="2,1,1,3"] |=== | Endpoint | Request Type | Supported Formats | Description - -| `/metrics` | GET | JSON, Prometheus, OpenMetrics | Returns all registered metrics -| `/metrics?scope=` | GET | JSON, Prometheus, OpenMetrics | Returns metrics registered for the respective scope. Scopes are listed in <> -| `/metrics?scope=&name=` | GET | JSON, Prometheus, OpenMetrics | Returns metrics that match the metric name for the respective scope -| `/metrics` | OPTIONS | JSON | Returns all registered metrics' metadata -| `/metrics?scope=` | OPTIONS | JSON | Returns metrics' metadata registered for the respective scope. Scopes are listed in <> -| `/metrics?scope=&name=` | OPTIONS | JSON | Returns the metric's metadata that matches the metric name for the respective scope +| `/metrics` | GET | Prometheus, OpenMetrics | Returns all registered metrics +| `/metrics?scope=` | GET | Prometheus, OpenMetrics | Returns metrics registered for the respective scope. Scopes are listed in <> +| `/metrics?scope=&name=` | GET | Prometheus, OpenMetrics | Returns metrics that match the metric name for the respective scope |=== -NOTE: The implementation must return a 406 response code if the request's HTTP Accept header for an OPTIONS request -does not match `application/json`. - [[app-servers]] === Usage of MicroProfile Metrics in application servers with multiple applications Even though multi-app servers are generally outside the scope of MicroProfile, this section describes recommendations diff --git a/spec/src/main/asciidoc/rest-endpoints.adoc b/spec/src/main/asciidoc/rest-endpoints.adoc index 873023b3..5c1eb568 100644 --- a/spec/src/main/asciidoc/rest-endpoints.adoc +++ b/spec/src/main/asciidoc/rest-endpoints.adoc @@ -23,328 +23,6 @@ This section describes the REST-API, that monitoring agents would use to retrieve the collected metrics. (Java-) methods mentioned refer to the respective Objects in the Java API. See also <> -[[json-format-def]] -=== JSON format - -* When using JSON format, the REST API will respond to GET requests with data formatted in a tree like fashion with sub-trees for the sub-resources. -A sub-tree that does not contain data must be omitted. -* A 'shadow tree' that responds to OPTIONS will provide the metadata and tags associated to a metric name. - -==== Translation rules for metric names and handling of tags - -The following rules apply only to GET requests: - -* Tags are appended to the leaf element of the metric's JSON tree. -* For metrics with tags, the metric name must be appended with a semicolon `;` followed by a semicolon-separated list of tag key/value pairs. -* For compound metrics (those with child JSON attributes) with tags, only the "leaf" metric names are decorated with tags. -* Semicolons `;` present in tag values must be converted to underscores `_` in JSON output. - -For example: -[source, json] ----- -{ - "carsCounter;colour=red": 0, - "carsCounter;car=sedan;colour=blue": 0, - "carsSpeed": { - "count;colour=red": 324, - "percentile;colour=red;_p=50": 110, - "percentile;colour=red;_p=75": 122, - "percentile;colour=red;_p=95": 135, - "percentile;colour=red;_p=98": 138, - "percentile;colour=red;_p=99": 141, - "percentile;colour=red;_p=99.9": 155, - "count;colour=blue": 199, - "percentile;colour=blue;_p=50": 105, - "percentile;colour=blue;_p=75": 118, - "percentile;colour=blue;_p=95": 133, - "percentile;colour=blue;_p=98": 139, - "percentile;colour=blue;_p=99": 140, - "percentile;colour=blue;_p=99.9": 152 - } -} ----- - -The following apply to both GET and OPTION requests: - -* Each tag is a key-value-pair in the format of `=`. The list of tags must be sorted alphabetically by key name. -* If the metric name or tag value contains a special reserved JSON character, these characters must be escaped in the JSON response. - - -If the metric has no tags, the semicolon `;` must be omitted. - -For example, -[source, json] ----- -{ - "metricWithoutTags": 192 -} ----- - - -*REST-API Objects* - -API-objects MAY include one or more metrics as in - -[source, json] ----- -{ - "thread.count": 33, - "thread.max.count": 47, - "memory.maxHeap": 3817863211, - "memory.usedHeap": 16859081, - "memory.committedHeap": 64703546 -} ----- - -or - -[source, json] ----- -{ - "hitCount;type=yes": 45 -} ----- - -In case `/metrics` is requested, then the data for the scopes are wrapped in the scope name: - -[source, json] ----- -{ - "application": { - "hitCount": 45 - }, - "base": { - "thread.count": 33, - "thread.max.count": 47 - }, - "vendor": {...}, - "someCustomScope": { - "myCounter": 22 - } -} ----- - -If there is a scope that contains no metrics, then it can be either present with an empty object -as its value, or it can be omitted completely. - -==== Gauge JSON Format - -The value of the gauge must be equivalent to a call to the instance Gauge's `getValue()`. -The JSON leaf is named `[';''=']+` with tags in alphabetical order. - -.Example Gauge JSON GET Response -[source, json] ----- -{ - "responsePercentage": 48.45632, - "responsePercentage;servlet=two": 26.23654, - "responsePercentage;servlet=three;store=webshop": 29.24554 -} ----- - -==== Counter JSON Format - -The value of the counter must be equivalent to a call to the instance Counter's `getCount()`. -The JSON leaf is named `[';''=']+` with tags in alphabetical order. - -.Example Counter JSON GET Response -[source, json] ----- -{ - "hitCount": 45, - "hitCount;servlet=two": 3, - "hitCount;servlet=three;store=webshop": 4 -} ----- - -==== Histogram JSON Format - -`Histogram` is a complex metric type comprised of multiple key/values. The format is specified by the table below. -The JSON node is named ``. The JSON leaves are named `[';''=']+` with tags in alphabetical order and keys according to below table. - -.JSON mapping for a Histogram metric -[cols="1,4"] -|=== -| JSON Key | Value (Equivalent Histogram method) - -| `count` | `getCount()` -| `sum` | `getSum()` -| `min` | `getSnapshot().getMin()` -| `max` | `getSnapshot().getMax()` -| `p50` | `getSnapshot().getMedian()` -| `p75` | `getSnapshot().get75thPercentile()` -| `p95` | `getSnapshot().get95thPercentile()` -| `p98` | `getSnapshot().get98thPercentile()` -| `p99` | `getSnapshot().get99thPercentile()` -| `p999` | `getSnapshot().get999thPercentile()` -|=== - -.Example Histogram JSON GET Response -[source, json] ----- -{ - "daily_value_changes": { - "count": 2, - "sum": -1598, - "min": -1624, - "max": 26, - "p50": 26.0, - "p75": 26.0, - "p95": 26.0, - "p98": 26.0, - "p99": 26.0, - "p999": 26.0, - "count;servlet=two": 2, - "sum;servlet=two": -1598, - "min;servlet=two": -1624, - "max;servlet=two": 26, - "p50;servlet=two": 26.0, - "p75;servlet=two": 26.0, - "p95;servlet=two": 26.0, - "p98;servlet=two": 26.0, - "p99;servlet=two": 26.0, - "p999;servlet=two": 26.0 - } -} ----- - - -==== Timer JSON Format - -`Timer` is a complex metric type comprised of multiple key/values. The format is specified by the table below. -The JSON node is named ``. The JSON leaves are named `[';''=']+` with tags in alphabetical order and keys according to below table. - -.JSON mapping for a Timer metric -[cols="1,4"] -|=== -| JSON Key | Value (Equivalent Timer method) - -| `count` | `getCount()` -| `elapsedTime` | `getElapsedTime()` -| `min` | `getSnapshot().getMin()` -| `max` | `getSnapshot().getMax()` -| `p50` | `getSnapshot().getMedian()` -| `p75` | `getSnapshot().get75thPercentile()` -| `p95` | `getSnapshot().get95thPercentile()` -| `p98` | `getSnapshot().get98thPercentile()` -| `p99` | `getSnapshot().get99thPercentile()` -| `p999` | `getSnapshot().get999thPercentile()` -|=== - -.Example Timer JSON GET Response -[source, json] ----- -{ - "responseTime": { - "count": 29382, - "elapsedTime": 25608694, - "min": 169916, - "max": 5608694, - "p50": 293324.0, - "p75": 344914.0, - "p95": 543647.0, - "p98": 2706543.0, - "p99": 5608694.0, - "p999": 5608694.0, - "count;servlet=two": 29382, - "elapsedTime;servlet=two": 25608694, - "min;servlet=two": 169916, - "max;servlet=two": 5608694, - "p50;servlet=two": 293324.0, - "p75;servlet=two": 344914.0, - "p95;servlet=two": 543647.0, - "p98;servlet=two": 2706543.0, - "p99;servlet=two": 5608694.0, - "p999;servlet=two": 5608694.0 - } -} ----- - -==== Metadata - - -Metadata is exposed in a tree-like fashion with sub-trees for the sub-resources mentioned previously. -Tags from metrics associated with the metric name are also included. The 'tags' attribute is an array of nested arrays which hold tags from different metrics that are associated with the metadata. Tags in each inner array are in alphabetical order. - -Example: - -If `GET /metrics/base/fooVal` exposes: - -[source] ----- -{ - "fooVal;store=webshop": 12345 -} ----- - -then `OPTIONS /metrics/base/fooVal` will expose: - -[source] ----- - -{ - "fooVal": { - "unit": "milliseconds", - "type": "gauge", - "description": "The size of foo after each request", - "displayName": "Size of foo", - "tags": [ - [ - "store=webshop" - ] - ] - } -} - ----- - -If `GET /metrics/base` exposes multiple values like this: - -.Example of exposed metrics data -[source] ----- -{ - "fooVal;store=webshop": 12345, - "barVal;component=backend;store=webshop": 42, - "barVal;component=frontend;store=webshop": 63 -} ----- - -then `OPTIONS /metrics/base` exposes: - -.Example of JSON output of Metadata -[source] ----- -{ - "fooVal": { - "unit": "milliseconds", - "type": "gauge", - "description": "The average duration of foo requests during last 5 minutes", - "displayName": "Duration of foo", - "tags": [ - [ - "store=webshop" - ] - ] - }, - "barVal": { - "unit": "megabytes", - "type": "gauge", - "tags": [ - [ - "component=backend", - "store=webshop" - ], - [ - "component=frontend", - "store=webshop" - ] - ] - } -} ----- - - === Prometheus / OpenMetrics formats The REST API must respond to GET requests with data formatted according to the Prometheus text-based exposition format, version 0.0.4 (hereafter Prometheus format). For details of how to format metrics data in this format, see https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details[Prometheus format]. diff --git a/tck/optional/src/main/java/org/eclipse/microprofile/metrics/test/optional/MpMetricOptionalTest.java b/tck/optional/src/main/java/org/eclipse/microprofile/metrics/test/optional/MpMetricOptionalTest.java index 01b47b05..a56ca64d 100644 --- a/tck/optional/src/main/java/org/eclipse/microprofile/metrics/test/optional/MpMetricOptionalTest.java +++ b/tck/optional/src/main/java/org/eclipse/microprofile/metrics/test/optional/MpMetricOptionalTest.java @@ -1,6 +1,6 @@ /* ********************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation + * Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation * * See the NOTICES file(s) distributed with this work for additional * information regarding copyright ownership. @@ -24,9 +24,6 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertTrue; import java.net.MalformedURLException; import java.net.URL; @@ -48,20 +45,14 @@ import io.restassured.RestAssured; import io.restassured.builder.ResponseBuilder; import io.restassured.http.Header; -import io.restassured.path.json.JsonPath; import io.restassured.response.Response; @SuppressWarnings("CdiInjectionPointsInspection") @RunWith(Arquillian.class) public class MpMetricOptionalTest { - private static final String JSON_APP_LABEL_REGEX = ";_app=[-/A-Za-z0-9]+([;\\\"]?)"; - private static final String JSON_APP_LABEL_REGEXS_SUB = "$1"; - private static final String OPENMETRICS_APP_LABEL_REGEX = "_app=\"[-/A-Za-z0-9]+\""; - private static final String APPLICATION_JSON = "application/json"; - // context root under which the application JAX-RS resources are expected to be private static String contextRoot; @@ -93,18 +84,6 @@ public class MpMetricOptionalTest { private static final String NAME_OBJECT_PARAM = "_org.eclipse.microprofile.metrics.test.optional.NameObject"; private static final String AYNC_RESP_PARAM = "_jakarta.ws.rs.container.AsyncResponse"; - private static final String JSON_BASE_REQUEST_COUNT_START = - "'REST.request'.'count;class=org.eclipse.microprofile.metrics.test.optional.MetricAppBeanOptional;method="; - private static final String JSON_BASE_REQUEST_UNMAPPED_EXCEPTION_START = - "'REST.request.unmappedException.total;class=org.eclipse.microprofile.metrics.test.optional.MetricAppBeanOptional;method="; - private static final String JSON_BASE_REQUEST_TIME_START = - "'REST.request'.'elapsedTime;class=org.eclipse.microprofile.metrics.test.optional.MetricAppBeanOptional;method="; - private static final String JSON_BASE_MAX_TIME_START = - "'REST.request'.'maxTimeDuration;class=org.eclipse.microprofile.metrics.test.optional.MetricAppBeanOptional;method="; - private static final String JSON_BASE_MIN_TIME_START = - "'REST.request'.'minTimeDuration;class=org.eclipse.microprofile.metrics.test.optional.MetricAppBeanOptional;method="; - private static final String JSON_BASE_REQUEST_END = ";tier=integration'"; - private static final String OM_BASE_REQUEST_COUNT_START = "base_REST_request_total" + "{class=\"org.eclipse.microprofile.metrics.test.optional.MetricAppBeanOptional\",method=\""; private static final String OM_BASE_REQUEST_TIME_START = "base_REST_request_elapsedTime_seconds" @@ -130,10 +109,6 @@ public class MpMetricOptionalTest { private static final String DEFAULT_HOST = "localhost"; private static final int DEFAULT_PORT = 8080; - private static String filterOutAppLabelJSON(String responseBody) { - return responseBody.replaceAll(JSON_APP_LABEL_REGEX, JSON_APP_LABEL_REGEXS_SUB); - } - private static String filterOutAppLabelOpenMetrics(String responseBody) { return responseBody.replaceAll(OPENMETRICS_APP_LABEL_REGEX, "").replaceAll("\\{,", "{").replaceAll(",\\}", "}"); } @@ -632,24 +607,26 @@ public void testGetAsync() throws InterruptedException { // Proceed to test that expected duration has elapsed - acceptHeader = new Header("Accept", APPLICATION_JSON); - - resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - Object asyncDurationObject = resp.then().statusCode(200).contentType(APPLICATION_JSON).extract() - .path(JSON_BASE_REQUEST_TIME_START + "getAsync" + AYNC_RESP_PARAM + JSON_BASE_REQUEST_END); - - String asyncDurationString = (asyncDurationObject instanceof Number) - ? ((Number) asyncDurationObject).toString() - : (String) asyncDurationObject; - Double asyncDurationDouble = Double.parseDouble(asyncDurationString); - - assertTrue("Expected duration to be greater than 5000000000 nanoseconds (i.e 5 seconds)", - (asyncDurationDouble >= 5000000000.00)); + // TODO: Need to rewrite this in PROM - no implementation available + // TODO: Need to to this in a separate PR + // acceptHeader = new Header("Accept", APPLICATION_JSON); + + // resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); + // JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); + // responseBuilder = new ResponseBuilder(); + // responseBuilder.clone(resp); + // responseBuilder.setBody(filteredJSONPath.prettify()); + // resp = responseBuilder.build(); + // Object asyncDurationObject = resp.then().statusCode(200).contentType(APPLICATION_JSON).extract() + // .path(JSON_BASE_REQUEST_TIME_START + "getAsync" + AYNC_RESP_PARAM + JSON_BASE_REQUEST_END); + + // String asyncDurationString = (asyncDurationObject instanceof Number) + // ? ((Number) asyncDurationObject).toString() + // : (String) asyncDurationObject; + // Double asyncDurationDouble = Double.parseDouble(asyncDurationString); + + // assertTrue("Expected duration to be greater than 5000000000 nanoseconds (i.e 5 seconds)", + // (asyncDurationDouble >= 5000000000.00)); } /* @@ -705,226 +682,6 @@ public void testPostMultiParam() throws InterruptedException { } - /* - * TEST GET REQUEST JSON TO RETRIEVE ABOVE VALUES - */ - - @Test - @RunAsClient - @InSequence(16) - public void testValidateGetJSONnoParam() throws InterruptedException { - Header acceptHeader = new Header("Accept", APPLICATION_JSON); - - Response resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - ResponseBuilder responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_COUNT_START + "getNoParam" + JSON_BASE_REQUEST_END, equalTo(2)) // end-point was - // hit twice - .body(JSON_BASE_REQUEST_TIME_START + "getNoParam" + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "getNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - - .body(JSON_BASE_REQUEST_COUNT_START + "optionsNoParam" + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "optionsNoParam" + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "optionsNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "optionsNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - - .body(JSON_BASE_REQUEST_COUNT_START + "headNoParam" + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "headNoParam" + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "headNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "headNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - - .body(JSON_BASE_REQUEST_COUNT_START + "putNoParam" + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "putNoParam" + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "putNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "putNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - - .body(JSON_BASE_REQUEST_COUNT_START + "postNoParam" + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "postNoParam" + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "postNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "postNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - - .body(JSON_BASE_REQUEST_COUNT_START + "deleteNoParam" + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "deleteNoParam" + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "deleteNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "deleteNoParam" + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()); - - } - - @Test - @RunAsClient - @InSequence(17) - public void testValidateGetJSONParam() throws InterruptedException { - Header acceptHeader = new Header("Accept", APPLICATION_JSON); - Response resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - ResponseBuilder responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getListParam1" + LIST_PARAM + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getListParam1" + LIST_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getListParam1" + LIST_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getListParam1" + LIST_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getListParam2" + LIST_PARAM + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getListParam2" + LIST_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getListParam2" + LIST_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getListParam2" + LIST_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getListParam3" + LIST_PARAM + LIST_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getListParam3" + LIST_PARAM + LIST_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getListParam3" + LIST_PARAM + LIST_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getListParam3" + LIST_PARAM + LIST_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleStringParam" + STRING_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleIntParam" + INT_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleDoubleParam" + DOUBLE_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleLongParam" + LONG_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getSingleBooleanParam" + BOOLEAN_PARAM - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - not(0)) - .body(JSON_BASE_MAX_TIME_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getSingleBooleanParam" + BOOLEAN_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "getMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "getMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "getMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "postMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "postMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "postMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "postMultipleParam1" + BOOLEAN_PARAM + INT_PARAM + DOUBLE_PARAM - + STRING_PARAM + LONG_PARAM + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "postMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "postMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "postMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "postMultipleParam2" + STRING_PARAM + LIST_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "postMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "postMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "postMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "postMultipleParam4" + SET_PARAM + SORTED_SET_PARAM - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_REQUEST_COUNT_START + "getAsync" + AYNC_RESP_PARAM + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getAsync" + AYNC_RESP_PARAM + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "getAsync" + AYNC_RESP_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getAsync" + AYNC_RESP_PARAM + JSON_BASE_REQUEST_END, - nullOrGreaterThanZero()); - } - @Test @RunAsClient @InSequence(18) @@ -957,38 +714,6 @@ public void testGetMappedArithException() throws InterruptedException { resp = responseBuilder.build(); resp.then().statusCode(200).contentType(TEXT_PLAIN).body(containsString( OM_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "getMappedArithException" + OM_BASE_REQUEST_END + " 0")); - - /* - * Check JSON - */ - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_COUNT_START + "getMappedArithException" - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "getMappedArithException" - + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "getMappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getMappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()); - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_UNMAPPED_EXCEPION_METRIC_ENDPOINT); - filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "getMappedArithException" - + JSON_BASE_REQUEST_END, equalTo(0)); } @Test @@ -1023,38 +748,6 @@ public void testPostMappedArithException() { resp = responseBuilder.build(); resp.then().statusCode(200).contentType(TEXT_PLAIN).body(containsString( OM_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "postMappedArithException" + OM_BASE_REQUEST_END + " 0")); - - /* - * Check JSON - */ - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_COUNT_START + "postMappedArithException" - + JSON_BASE_REQUEST_END, equalTo(1)) - .body(JSON_BASE_REQUEST_TIME_START + "postMappedArithException" - + JSON_BASE_REQUEST_END, not(0)) - .body(JSON_BASE_MAX_TIME_START + "postMappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "postMappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()); - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_UNMAPPED_EXCEPION_METRIC_ENDPOINT); - filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "postMappedArithException" - + JSON_BASE_REQUEST_END, equalTo(0)); } @Test @@ -1089,37 +782,6 @@ public void testGetUnmappedArithException() { resp = responseBuilder.build(); resp.then().statusCode(200).contentType(TEXT_PLAIN).body(containsString( OM_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "getUnmappedArithException" + OM_BASE_REQUEST_END + " 1")); - /* - * Check JSON - */ - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_COUNT_START + "getUnmappedArithException" - + JSON_BASE_REQUEST_END, zero()) - .body(JSON_BASE_REQUEST_TIME_START + "getUnmappedArithException" - + JSON_BASE_REQUEST_END, zero()) - .body(JSON_BASE_MAX_TIME_START + "getUnmappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "getUnmappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()); - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_UNMAPPED_EXCEPION_METRIC_ENDPOINT); - filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "getUnmappedArithException" - + JSON_BASE_REQUEST_END, equalTo(1)); } @Test @@ -1154,38 +816,6 @@ public void testPostUnmappedArithException() { resp = responseBuilder.build(); resp.then().statusCode(200).contentType(TEXT_PLAIN).body(containsString( OM_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "postUnmappedArithException" + OM_BASE_REQUEST_END + " 1")); - - /* - * Check JSON - */ - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT); - JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_COUNT_START + "postUnmappedArithException" - + JSON_BASE_REQUEST_END, zero()) - .body(JSON_BASE_REQUEST_TIME_START + "postUnmappedArithException" - + JSON_BASE_REQUEST_END, zero()) - .body(JSON_BASE_MAX_TIME_START + "postUnmappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()) - .body(JSON_BASE_MIN_TIME_START + "postUnmappedArithException" - + JSON_BASE_REQUEST_END, nullOrGreaterThanZero()); - - acceptHeader = new Header("Accept", APPLICATION_JSON); - resp = given().header(acceptHeader).when().get(RESTREQUEST_UNMAPPED_EXCEPION_METRIC_ENDPOINT); - filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); - responseBuilder = new ResponseBuilder(); - responseBuilder.clone(resp); - responseBuilder.setBody(filteredJSONPath.prettify()); - resp = responseBuilder.build(); - resp.then().statusCode(200).contentType(APPLICATION_JSON) - .body(JSON_BASE_REQUEST_UNMAPPED_EXCEPTION_START + "postUnmappedArithException" - + JSON_BASE_REQUEST_END, equalTo(1)); } Matcher nullOrGreaterThanZero() { diff --git a/tck/rest/src/main/base_metrics.xml b/tck/rest/src/main/base_metrics.xml index fdd7ffc3..6bd14df1 100644 --- a/tck/rest/src/main/base_metrics.xml +++ b/tck/rest/src/main/base_metrics.xml @@ -1,6 +1,6 @@