-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prometheus select metric and stats queries. (#956)
* Prometheus select metric and stats queries. Signed-off-by: reddyvam-amazon <[email protected]>
- Loading branch information
1 parent
1a52511
commit be4512e
Showing
41 changed files
with
2,181 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusCatalogCommandsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.prometheus.data.constants.PrometheusFieldConstants.TIMESTAMP; | ||
import static org.opensearch.sql.prometheus.data.constants.PrometheusFieldConstants.VALUE; | ||
import static org.opensearch.sql.util.MatcherUtils.schema; | ||
import static org.opensearch.sql.util.MatcherUtils.verifySchema; | ||
|
||
import lombok.SneakyThrows; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PrometheusCatalogCommandsIT extends PPLIntegTestCase { | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testSourceMetricCommand() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total"); | ||
verifySchema(response, | ||
schema(VALUE, "double"), | ||
schema(TIMESTAMP, "timestamp"), | ||
schema("handler", "string"), | ||
schema("code", "string"), | ||
schema("instance", "string"), | ||
schema("job", "string")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(6, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testMetricAvgAggregationCommand() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total | stats avg(@value) by span(@timestamp, 15s), handler, job"); | ||
verifySchema(response, | ||
schema("avg(@value)", "double"), | ||
schema("span(@timestamp,15s)", "timestamp"), | ||
schema("handler", "string"), | ||
schema("job", "string")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(4, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testMetricAvgAggregationCommandWithAlias() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total | stats avg(@value) as agg by span(@timestamp, 15s), handler, job"); | ||
verifySchema(response, | ||
schema("agg", "double"), | ||
schema("span(@timestamp,15s)", "timestamp"), | ||
schema("handler", "string"), | ||
schema("job", "string")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(4, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
@SneakyThrows | ||
public void testMetricMaxAggregationCommand() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total | stats max(@value) by span(@timestamp, 15s)"); | ||
verifySchema(response, | ||
schema("max(@value)", "double"), | ||
schema("span(@timestamp,15s)", "timestamp")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(2, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
@SneakyThrows | ||
public void testMetricMinAggregationCommand() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total | stats min(@value) by span(@timestamp, 15s), handler"); | ||
verifySchema(response, | ||
schema("min(@value)", "double"), | ||
schema("span(@timestamp,15s)", "timestamp"), | ||
schema("handler", "string")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(3, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testMetricCountAggregationCommand() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total | stats count() by span(@timestamp, 15s), handler, job"); | ||
verifySchema(response, | ||
schema("count()", "integer"), | ||
schema("span(@timestamp,15s)", "timestamp"), | ||
schema("handler", "string"), | ||
schema("job", "string")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(4, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testMetricSumAggregationCommand() { | ||
JSONObject response = | ||
executeQuery("source=my_prometheus.prometheus_http_requests_total | stats sum(@value) by span(@timestamp, 15s), handler, job"); | ||
verifySchema(response, | ||
schema("sum(@value)", "double"), | ||
schema("span(@timestamp,15s)", "timestamp"), | ||
schema("handler", "string"), | ||
schema("job", "string")); | ||
Assertions.assertTrue(response.getInt("size") > 0); | ||
Assertions.assertEquals(4, response.getJSONArray("datarows").getJSONArray(0).length()); | ||
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0); | ||
for (int i = 0; i < firstRow.length(); i++) { | ||
Assertions.assertNotNull(firstRow.get(i)); | ||
Assertions.assertTrue(StringUtils.isNotEmpty(firstRow.get(i).toString())); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.