diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index b65ec2aaa7..8183dd8716 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -103,6 +103,7 @@ * Support prometheus HTTP API and promQL. * `Scope` in the Entity of Metrics query v1 protocol is not required and automatical correction. The scope is determined based on the metric itself. * Add explicit `ReadTimeout` for ConsulConfigurationWatcher to avoid `IllegalArgumentException: Cache watchInterval=10sec >= networkClientReadTimeout=10000ms`. +* Fix `DurationUtils.getDurationPoints` exceed, when `startTimeBucket` equals `endTimeBucket`. #### UI diff --git a/docs/en/setup/backend/configuration-vocabulary.md b/docs/en/setup/backend/configuration-vocabulary.md index 134719a116..8ab8681e6d 100644 --- a/docs/en/setup/backend/configuration-vocabulary.md +++ b/docs/en/setup/backend/configuration-vocabulary.md @@ -242,7 +242,7 @@ The Configuration Vocabulary lists all available configurations provided by `app | - | - | maxQueryComplexity | Maximum complexity allowed for the GraphQL query that can be used to abort a query if the total number of data fields queried exceeds the defined threshold. | SW_QUERY_MAX_QUERY_COMPLEXITY | 1000 | | - | - | enableUpdateUITemplate | Allow user add,disable and update UI template. | SW_ENABLE_UPDATE_UI_TEMPLATE | false | | - | - | enableOnDemandPodLog | Ondemand Pod log: fetch the Pod logs on users' demand, the logs are fetched and displayed in real time, and are not persisted in any kind. This is helpful when users want to do some experiments and monitor the logs and see what's happing inside the service. Note: if you print secrets in the logs, they are also visible to the UI, so for the sake of security, this feature is disabled by default, please set this configuration to enable the feature manually. | SW_ENABLE_ON_DEMAND_POD_LOG | false | -| query | graphql | - | GraphQL query implementation. | - | | +| query-zipkin | default | - | This module is for Zipkin query API and support zipkin-lens UI | - | | | - | - | restHost | Binding IP of RESTful services. | SW_QUERY_ZIPKIN_REST_HOST | 0.0.0.0 | | - | - | restPort | Binding port of RESTful services. | SW_QUERY_ZIPKIN_REST_PORT | 9412 | | - | - | restContextPath | Web context path of RESTful services. | SW_QUERY_ZIPKIN_REST_CONTEXT_PATH | zipkin | @@ -253,6 +253,13 @@ The Configuration Vocabulary lists all available configurations provided by `app | - | - | namesMaxAge | The Cache-Control max-age (seconds) for serviceNames, remoteServiceNames and spanNames | SW_QUERY_ZIPKIN_NAMES_MAX_AGE | 300 | | - | - | uiQueryLimit | Default traces query max size | SW_QUERY_ZIPKIN_UI_QUERY_LIMIT | 10 | | - | - | uiDefaultLookback | Default look back on the UI for search traces, 15 minutes in millis | SW_QUERY_ZIPKIN_UI_DEFAULT_LOOKBACK | 900000 | +| promql | default | - | This module is for PromQL API. | - | | +| - | - | restHost | Binding IP of RESTful services. | SW_PROMQL_REST_HOST | 0.0.0.0 | +| - | - | restPort | Binding port of RESTful services. | SW_PROMQL_REST_PORT | 9090 | +| - | - | restContextPath | Web context path of RESTful services. | SW_PROMQL_REST_CONTEXT_PATH | / | +| - | - | restMaxThreads | Maximum thread number of RESTful services. | SW_PROMQL_REST_MAX_THREADS | 200 | +| - | - | restIdleTimeOut | Connector idle timeout of RESTful services (in milliseconds). | SW_PROMQL_REST_IDLE_TIMEOUT | 30000 | +| - | - | restAcceptQueueSize | Maximum request header size accepted. | SW_PROMQL_REST_QUEUE_SIZE | 0 | | alarm | default | - | Read [alarm doc](backend-alarm.md) for more details. | - | | | telemetry | - | - | Read [telemetry doc](backend-telemetry.md) for more details. | - | | | - | none | - | No op implementation. | - | | diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/DurationUtils.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/DurationUtils.java index ac2cdaf6f7..cc53aa83f1 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/DurationUtils.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/DurationUtils.java @@ -88,6 +88,9 @@ public enum DurationUtils { List durations = new LinkedList<>(); durations.add(new PointOfTime(startTimeBucket)); + if (startTimeBucket == endTimeBucket) { + return durations; + } int i = 0; do { diff --git a/oap-server/server-query-plugin/promql-plugin/src/main/antlr4/org/apache/skywalking/promql/rt/grammar/PromQLLexer.g4 b/oap-server/server-query-plugin/promql-plugin/src/main/antlr4/org/apache/skywalking/promql/rt/grammar/PromQLLexer.g4 index 087f9b213a..c82dd1a0c8 100644 --- a/oap-server/server-query-plugin/promql-plugin/src/main/antlr4/org/apache/skywalking/promql/rt/grammar/PromQLLexer.g4 +++ b/oap-server/server-query-plugin/promql-plugin/src/main/antlr4/org/apache/skywalking/promql/rt/grammar/PromQLLexer.g4 @@ -47,7 +47,7 @@ GT: '>'; // Literals NUMBER: Digit+ (DOT Digit+)?; -DURATION: Digit+ ('s' | 'm' | 'h' | 'd' | 'w' | 'y'); +DURATION: Digit+ ('ms' | 's' | 'm' | 'h' | 'd' | 'w'); NAME_STRING: NameLetter+; VALUE_STRING: '\'' .*? '\'' | '"' .*? '"'; diff --git a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/handler/PromQLApiHandler.java b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/handler/PromQLApiHandler.java index 7a2dcc0eca..77ba7f0194 100644 --- a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/handler/PromQLApiHandler.java +++ b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/handler/PromQLApiHandler.java @@ -103,7 +103,6 @@ public class PromQLApiHandler { } @Get - @Post @Path("/api/v1/metadata") public HttpResponse metadata( @Param("limit") Optional limit, @@ -174,7 +173,6 @@ public class PromQLApiHandler { * reserve these param to keep consistent with API protocol. */ @Get - @Post @Path("/api/v1/label/{label_name}/values") public HttpResponse labelValues( @Param("label_name") String labelName, diff --git a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromOpUtils.java b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromOpUtils.java index 03da30769d..44f6bbd92f 100644 --- a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromOpUtils.java +++ b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromOpUtils.java @@ -35,6 +35,8 @@ import org.apache.skywalking.oap.server.core.query.input.Duration; import org.apache.skywalking.oap.server.core.query.type.MetricsValues; import org.apache.skywalking.promql.rt.grammar.PromQLParser; import org.joda.time.DateTime; +import org.joda.time.format.PeriodFormatter; +import org.joda.time.format.PeriodFormatterBuilder; public class PromOpUtils { //Adopt skywalking time step. @@ -252,4 +254,22 @@ public class PromOpUtils { DecimalFormat format = new DecimalFormat("#.##"); return format.format(v); } + + /** + * Format duration string to org.joda.time.Duration. + * Don't support year and month because the days vary in length. + * @param duration such as "5d", "30m", "5d30m, "1w, "1w5d" + * @return org.joda.time.Duration + */ + public static org.joda.time.Duration formatDuration(String duration) { + PeriodFormatter f = new PeriodFormatterBuilder() + .appendWeeks().appendSuffix("w") + .appendDays().appendSuffix("d") + .appendHours().appendSuffix("h") + .appendMinutes().appendSuffix("m") + .appendSeconds().appendSuffix("s") + .appendMillis().appendSuffix("ms") + .toFormatter(); + return f.parsePeriod(duration).toStandardDuration(); + } } diff --git a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java index 68c11aaf5e..05ac6940b0 100644 --- a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java +++ b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java @@ -58,6 +58,7 @@ import org.apache.skywalking.promql.rt.grammar.PromQLParser; import org.apache.skywalking.promql.rt.grammar.PromQLParserBaseVisitor; import static org.apache.skywalking.oap.query.promql.rt.PromOpUtils.buildMatrixValues; +import static org.apache.skywalking.oap.query.promql.rt.PromOpUtils.formatDuration; import static org.apache.skywalking.oap.query.promql.rt.PromOpUtils.matrixBinaryOp; import static org.apache.skywalking.oap.query.promql.rt.PromOpUtils.matrixCompareOp; import static org.apache.skywalking.oap.query.promql.rt.PromOpUtils.matrixScalarBinaryOp; @@ -247,9 +248,9 @@ public class PromQLExprQueryVisitor extends PromQLParserBaseVisitor return result; } - String timeRange = "PT" + ctx.DURATION().getText().toUpperCase(); + String timeRange = ctx.DURATION().getText().toUpperCase(); long endTS = System.currentTimeMillis(); - long startTS = endTS - java.time.Duration.parse(timeRange).toMillis(); + long startTS = endTS - formatDuration(timeRange).getMillis(); duration = timestamp2Duration(startTS, endTS); ParseResult result = visit(ctx.metricInstant()); result.setRangeExpression(true); diff --git a/oap-server/server-starter/src/main/resources/application.yml b/oap-server/server-starter/src/main/resources/application.yml index 9e73b3ce7f..c79cffeb21 100644 --- a/oap-server/server-starter/src/main/resources/application.yml +++ b/oap-server/server-starter/src/main/resources/application.yml @@ -435,12 +435,13 @@ query-zipkin: # Default look back on the UI for search traces, 15 minutes in millis uiDefaultLookback: ${SW_QUERY_ZIPKIN_UI_DEFAULT_LOOKBACK:900000} +#This module is for PromQL API. promql: selector: ${SW_PROMQL:default} default: # For HTTP server restHost: ${SW_PROMQL_REST_HOST:0.0.0.0} - restPort: ${SW_PROMQL_REST_PORT:9099} + restPort: ${SW_PROMQL_REST_PORT:9090} restContextPath: ${SW_PROMQL_REST_CONTEXT_PATH:/} restMaxThreads: ${SW_PROMQL_REST_MAX_THREADS:200} restIdleTimeOut: ${SW_PROMQL_REST_IDLE_TIMEOUT:30000}