PromQL service: query API support RFC3399 time format. (#12644)
This commit is contained in:
parent
10cd558f24
commit
9cf79f7282
|
|
@ -57,7 +57,7 @@ jobs:
|
|||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- run: ./mvnw -q -Dmaven.test.skip=true clean install || ./mvnw -q -Dmaven.test.skip=true clean install
|
||||
- run: ./mvnw -q -Dmaven.test.skip=true clean install -Dgpg.skip || ./mvnw -q -Dmaven.test.skip=true clean install -Dgpg.skip
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
|
|
|||
|
|
@ -145,11 +145,11 @@ sum(http_requests_total{service='$service', layer='$layer'})
|
|||
GET|POST /api/v1/query
|
||||
```
|
||||
|
||||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------|---------|------------|
|
||||
| query | prometheus expression | yes | no |
|
||||
| time | **The latest metrics value from current time to this time is returned. If time is empty, the default look-back time is 2 minutes.** | yes | yes |
|
||||
| timeout | evaluation timeout | **no** | **ignore** |
|
||||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|------------|
|
||||
| query | prometheus expression | yes | no |
|
||||
| time | **The latest metrics value from current time to this time is returned. If time is empty, the default look-back time is 2 minutes.** time format: RFC3399 or unix_timestamp in seconds | yes | yes |
|
||||
| timeout | evaluation timeout | **no** | **ignore** |
|
||||
|
||||
For example:
|
||||
```text
|
||||
|
|
@ -191,8 +191,8 @@ GET|POST /api/v1/query_range
|
|||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|--------------------------------------------------------------------------------------|---------|------------|
|
||||
| query | prometheus expression | yes | no |
|
||||
| start | start timestamp, **seconds** | yes | no |
|
||||
| end | end timestamp, **seconds** | yes | no |
|
||||
| start | start timestamp, format: RFC3399 or unix_timestamp in seconds | yes | no |
|
||||
| end | end timestamp, format: RFC3399 or unix_timestamp in seconds | yes | no |
|
||||
| step | **SkyWalking will automatically fit Step(DAY, HOUR, MINUTE) through start and end.** | **no** | **ignore** |
|
||||
| timeout | evaluation timeout | **no** | **ignore** |
|
||||
|
||||
|
|
@ -256,11 +256,11 @@ Result:
|
|||
GET|POST /api/v1/series
|
||||
```
|
||||
|
||||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|------------------------------|---------|----------|
|
||||
| match[] | series selector | yes | no |
|
||||
| start | start timestamp, **seconds** | yes | no |
|
||||
| end | end timestamp, **seconds** | yes | no |
|
||||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|-----------------------------------------------------|---------|----------|
|
||||
| match[] | series selector | yes | no |
|
||||
| start | start, format: RFC3399 or unix_timestamp in seconds | yes | no |
|
||||
| end | end, format: RFC3399 or unix_timestamp in seconds | yes | no |
|
||||
|
||||
For example:
|
||||
```text
|
||||
|
|
@ -321,7 +321,7 @@ GET|POST /api/v1/labels
|
|||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|---------------------------------------------------------------------------------|---------|----------|
|
||||
| match[] | series selector | yes | yes |
|
||||
| start | start timestamp | **no** | yes |
|
||||
| start | start, format: RFC3399 or unix_timestamp in seconds | **no** | yes |
|
||||
| end | end timestamp, if end time is not present, use current time as default end time | yes | yes |
|
||||
|
||||
For example:
|
||||
|
|
@ -351,11 +351,11 @@ Result:
|
|||
GET /api/v1/label/<label_name>/values
|
||||
```
|
||||
|
||||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|---------------------------------------------------------------------------------|---------|----------|
|
||||
| match[] | series selector | yes | yes |
|
||||
| start | start timestamp | **no** | yes |
|
||||
| end | end timestamp, if end time is not present, use current time as default end time | yes | yes |
|
||||
| Parameter | Definition | Support | Optional |
|
||||
|-----------|---------------------------------------------------------------------------------------------------------------------|---------|----------|
|
||||
| match[] | series selector | yes | yes |
|
||||
| start | start, format: RFC3399 or unix_timestamp in seconds | **no** | yes |
|
||||
| end | end, format: RFC3399 or unix_timestamp in seconds, if end time is not present, use current time as default end time | yes | yes |
|
||||
|
||||
For example:
|
||||
```text
|
||||
|
|
|
|||
|
|
@ -66,12 +66,13 @@
|
|||
* Fix the previous analysis result missing in the ALS `k8s-mesh` analyzer.
|
||||
* Fix `findEndpoint` query require `keyword` when using BanyanDB.
|
||||
* Support to analysis the ztunnel mapped IP address in eBPF Access Log Receiver.
|
||||
* Adapt BanyanDB Java Client 0.7.0-rc3.
|
||||
* Adapt BanyanDB Java Client 0.7.0.
|
||||
* Add SkyWalking Java Agent self observability dashboard.
|
||||
* Add Component ID(5022) for the GoFrame framework.
|
||||
* Bump up protobuf java dependencies to 3.25.5.
|
||||
* BanyanDB: support using native term searching for `keyword` in query `findEndpoint` and `getAlarm`.
|
||||
* BanyanDB: support TLS connection and configuration.
|
||||
* PromQL service: query API support RFC3399 time format.
|
||||
|
||||
#### UI
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ import org.apache.skywalking.oap.server.library.util.StringUtil;
|
|||
import org.apache.skywalking.promql.rt.grammar.PromQLLexer;
|
||||
import org.apache.skywalking.promql.rt.grammar.PromQLParser;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
import static org.apache.skywalking.oap.query.promql.rt.PromOpUtils.formatDoubleValue;
|
||||
|
||||
|
|
@ -582,7 +583,15 @@ public class PromQLApiHandler {
|
|||
}
|
||||
|
||||
private static long formatTimestamp2Millis(String timestamp) {
|
||||
return Double.valueOf(timestamp).longValue() * 1000;
|
||||
long time;
|
||||
try {
|
||||
// if Unix timestamp in seconds, such as 1627756800
|
||||
time = Double.valueOf(timestamp).longValue() * 1000;
|
||||
} catch (NumberFormatException e) {
|
||||
// if RFC3399 format, such as 2024-09-19T20:11:00.781Z
|
||||
time = ISODateTimeFormat.dateTime().parseMillis(timestamp);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
private List<String> buildLabelNames(Scope scope, ValueColumnMetadata.ValueColumn metaData) {
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ public class PromQLExprQueryVisitor extends PromQLParserBaseVisitor<ParseResult>
|
|||
}
|
||||
|
||||
String timeRange = ctx.DURATION().getText().toUpperCase();
|
||||
long endTS = System.currentTimeMillis();
|
||||
long endTS = this.duration.getEndTimestamp();
|
||||
long startTS = endTS - formatDuration(timeRange).getMillis();
|
||||
duration = DurationUtils.timestamp2Duration(startTS, endTS);
|
||||
ParseResult result = visit(ctx.metricInstant());
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ cases:
|
|||
# traffics query
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/series -d 'match[]=service_traffic{layer="GENERAL"}&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
expected: expected/service-traffic.yml
|
||||
#RFC3399
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/series -d 'match[]=service_traffic{layer="GENERAL"}&start='$(($(date +%s)-1800))'&end='$(date -u +%Y-%m-%dT%H:%M:%S.111Z)
|
||||
expected: expected/service-traffic.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/series -d 'match[]=instance_traffic{layer="GENERAL", service="e2e-service-provider"}&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
expected: expected/instance-traffic.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/series -d 'match[]=endpoint_traffic{layer="GENERAL", service="e2e-service-provider", keyword="POST:/users"}&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
|
|
@ -29,11 +32,15 @@ cases:
|
|||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/series -d 'match[]=endpoint_cpm&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
expected: expected/endpoint-metric-series.yml
|
||||
# metrics names query
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/label/__name__/values
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/label/__name__/values
|
||||
expected: expected/metrics-names.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/label/__name__/values -d 'start='$(($(date +%s)-1800))'&end='$(date -u +%Y-%m-%dT%H:%M:%S.111Z)
|
||||
expected: expected/metrics-names.yml
|
||||
# labels query
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/labels -d 'match[]=service_cpm'
|
||||
expected: expected/service-metric-label.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/labels -d 'match[]=service_cpm&start='$(($(date +%s)-1800))'&end='$(date -u +%Y-%m-%dT%H:%M:%S.111Z)
|
||||
expected: expected/service-metric-label.yml
|
||||
- query: |
|
||||
sleep 30;
|
||||
curl -X GET http://${oap_host}:${oap_9090}/api/v1/labels -d 'match[]=service_percentile'
|
||||
|
|
@ -54,6 +61,9 @@ cases:
|
|||
expected: expected/service-metric-vector.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=service_sla{service="e2e-service-consumer", layer="GENERAL"}[30m]'
|
||||
expected: expected/service-metric-matrix.yml
|
||||
#RFC3399
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=service_sla{service="e2e-service-consumer", layer="GENERAL"}[30m]&time='$(date -u +%Y-%m-%dT%H:%M:%S.111Z)
|
||||
expected: expected/service-metric-matrix.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=service_percentile{service="e2e-service-consumer", layer="GENERAL", p="50,75,90"}'
|
||||
expected: expected/service-metric-labeled-vector.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=service_percentile_old{service="e2e-service-consumer", layer="GENERAL", labels="0,1,2", relabels="P50,P75,P90"}'
|
||||
|
|
@ -72,6 +82,9 @@ cases:
|
|||
## query_range
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query_range -d 'query=service_sla{service="e2e-service-consumer", layer="GENERAL"}&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
expected: expected/service-metric-matrix.yml
|
||||
#RFC3399
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query_range -d 'query=service_sla{service="e2e-service-consumer", layer="GENERAL"}&start='$(($(date +%s)-1800))'&end='$(date -u +%Y-%m-%dT%H:%M:%S.111Z)
|
||||
expected: expected/service-metric-matrix.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query_range -d 'query=service_percentile{service="e2e-service-consumer", layer="GENERAL", p="50,75,90"}&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
expected: expected/service-metric-labeled-matrix.yml
|
||||
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query_range -d 'query=sum by (p) (service_percentile{service="e2e-service-consumer", layer="GENERAL", p="50,75,90"})&start='$(($(date +%s)-1800))'&end='$(date +%s)
|
||||
|
|
|
|||
Loading…
Reference in New Issue