Skip to content

Commit 2e8d6e3

Browse files
authored
PromQL Service: traffic query support limit and regex match. (#13162)
1 parent dc95380 commit 2e8d6e3

File tree

16 files changed

+477
-99
lines changed

16 files changed

+477
-99
lines changed

docs/en/api/promql-service.md

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,31 @@ GET|POST /api/v1/series
268268
| match[] | series selector | yes | no |
269269
| start | start, format: RFC3399 or unix_timestamp in seconds | yes | no |
270270
| end | end, format: RFC3399 or unix_timestamp in seconds | yes | no |
271+
| limit | integer, maximum number of returned series | yes | yes |
272+
273+
**For metadata metrics**:
274+
**Note: SkyWalking's metadata exists in the following metrics(traffics):**
275+
276+
| Name | Require Labels | Optional Labels | Support Label Match |
277+
|------------------|----------------|--------------------------|-----------------------------------------------------|
278+
| service_traffic | layer | service, limit | =, (only service label support !=, =~, !~) |
279+
| instance_traffic | layer, service | service_instance, limit | =, (only service_instance label support !=, =~, !~) |
280+
| endpoint_traffic | layer, service | endpoint, keyword, limit | =, (only endpoint label support !=, =~, !~) |
281+
282+
- **=**: Label value equals the provided string.
283+
- **!=**: Label value does not equal the provided string.
284+
- **=~**: Label value regex-match the provided string.
285+
- **!~**: Label value does not regex-match the provided string
286+
287+
**If the `limit` is not set by parameter or label, the default value is 100. If the `limit ' is also set in the query parameter, it returns the minimum of the two.**
271288

272289
For example:
273290
```text
274-
/api/v1/series?match[]=service_traffic{layer='GENERAL'}&start=1677479336&end=1677479636
291+
/api/v1/series?match[]=service_traffic{layer='GENERAL'}&start=1677479336&end=1677479636&limit=5
292+
```
293+
or
294+
```text
295+
/api/v1/series?match[]=service_traffic{layer='GENERAL', limit='5'}&start=1677479336&end=1677479636
275296
```
276297

277298
Result:
@@ -313,10 +334,23 @@ Result:
313334
}
314335
```
315336

316-
**Note: SkyWalking's metadata exists in the following metrics(traffics):**
317-
- service_traffic
318-
- instance_traffic
319-
- endpoint_traffic
337+
- You can use the `service` label to filter the service_traffic result.
338+
```text
339+
/api/v1/series?match[]=service_traffic{layer='GENERAL', service='agent::songs'}&start=1677479336&end=1677479636
340+
```
341+
use regex:
342+
```text
343+
/api/v1/series?match[]=service_traffic{layer='GENERAL', service=~'agent::songs|agent::recommendation'}&start=1677479336&end=1677479636
344+
```
345+
- You can use the `service_instance` label to filter the instance_traffic result.
346+
```text
347+
/api/v1/series?match[]=service_traffic{layer='GENERAL', service='agent::songs', service_instance=~'instance1|instance2'}&start=1677479336&end=1677479636
348+
```
349+
- You can use the `endpoint` label to filter the endpoint_traffic result.
350+
```text
351+
/api/v1/series?match[]=service_traffic{layer='GENERAL', service='agent::songs', endpoint=~'endpoint1|endpoint2'}&start=1677479336&end=1677479636
352+
```
353+
320354

321355
#### Getting label names
322356
[Prometheus Docs Reference](https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names)
@@ -330,6 +364,7 @@ GET|POST /api/v1/labels
330364
| match[] | series selector | yes | yes |
331365
| start | start, format: RFC3399 or unix_timestamp in seconds | **no** | yes |
332366
| end | end timestamp, if end time is not present, use current time as default end time | yes | yes |
367+
| limit | integer, maximum number of returned labels, default 100 | yes | yes |
333368

334369
For example:
335370
```text
@@ -363,11 +398,12 @@ GET /api/v1/label/<label_name>/values
363398
| match[] | series selector | yes | yes |
364399
| start | start, format: RFC3399 or unix_timestamp in seconds | **no** | yes |
365400
| end | end, format: RFC3399 or unix_timestamp in seconds, if end time is not present, use current time as default end time | yes | yes |
401+
| limit | integer, maximum number of returned label values, default 100 | yes | yes |
366402

367403
For example:
368404
```text
369405
/api/v1/label/__name__/values
370-
```
406+
```
371407

372408
Result:
373409
```json
@@ -391,6 +427,39 @@ Result:
391427
}
392428
```
393429

430+
**For metadata metrics**:
431+
432+
| Name | Require Labels | Optional Labels | Support Label Match |
433+
|------------------|----------------|--------------------------|-----------------------------------------------------|
434+
| service_traffic | layer | service, limit | =, (only service label support !=, =~, !~) |
435+
| instance_traffic | layer, service | service_instance, limit | =, (only service_instance label support !=, =~, !~) |
436+
| endpoint_traffic | layer, service | endpoint, keyword, limit | =, (only endpoint label support !=, =~, !~) |
437+
438+
- **=**: Label value equal to the provided string.
439+
- **!=**: Label value not equal to the provided string.
440+
- **=~**: Label value regex-match the provided string.
441+
- **!~**: Label value do not regex-match the provided string
442+
443+
**If the `limit` is not set by parameter or label, the default value is 100. And If the `limit` also set in the query parameter, will return the min number of the two.**
444+
445+
For example:
446+
- If you want to query the label values of the `service` label in the `service_traffic` metric:
447+
```text
448+
/api/v1/label/service/values?match[]=service_traffic{layer='GENERAL', service='agent::songs|agent::recommendation'}&limit=1
449+
```
450+
or
451+
```text
452+
/api/v1/label/service/values?match[]=service_traffic{layer='GENERAL', service='agent::songs|agent::recommendation',limit='1'}
453+
```
454+
- If you want to query the label values of the `service_instance` label in the `instance_traffic` metric:
455+
```text
456+
/api/v1/label/service_instance/values?match[]=instance_traffic{layer='GENERAL', service='agent::songs', service_instance='instance1|instance2'}
457+
```
458+
- If you want to query the label values of the `endpoint` label in the `endpoint_traffic` metric:
459+
```text
460+
/api/v1/label/endpoint/values?match[]=endpoint_traffic{layer='GENERAL', service='agent::songs', endpoint='endpoint1|endpoint2'}
461+
```
462+
394463
#### Querying metric metadata
395464
[Prometheus Docs Reference](https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata)
396465

docs/en/changes/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* BanyanDB: Support `hot/warm/cold` stages configuration.
88
* Fix query continues profiling policies error when the policy is already in the cache.
99
* Support `hot/warm/cold` stages TTL query in the status API.
10+
* PromQL Service: traffic query support `limit` and regex match.
1011

1112
#### UI
1213

oap-server/server-query-plugin/promql-plugin/src/main/antlr4/org/apache/skywalking/promql/rt/grammar/PromQLLexer.g4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ L_BRACE: '{';
3232
R_BRACE: '}';
3333
EQ: '=';
3434

35+
//regex-match
36+
RM: '=~';
37+
//regex-not-match
38+
NRM: '!~';
39+
3540
// Scalar Binary operators
3641
SUB: '-';
3742
ADD: '+';

oap-server/server-query-plugin/promql-plugin/src/main/antlr4/org/apache/skywalking/promql/rt/grammar/PromQLParser.g4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ metricRange: metricInstant L_BRACKET DURATION R_BRACKET;
5050

5151
labelName: NAME_STRING;
5252
labelValue: VALUE_STRING;
53-
label: labelName EQ labelValue;
53+
label: labelName matchOp labelValue;
5454
labelList: label (COMMA label)*;
5555
labelNameList: labelName (COMMA labelName)*;
5656

57+
matchOp: EQ | NEQ | RM | NRM;
58+
5759
numberLiteral: NUMBER;
5860

5961
badRange: NUMBER L_BRACKET DURATION R_BRACKET;

oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/entity/response/LabelsQueryRsp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
@EqualsAndHashCode(callSuper = true)
2727
@Data
2828
public class LabelsQueryRsp extends QueryResponse {
29-
private final List<String> data = new ArrayList<>();
29+
private List<String> data = new ArrayList<>();
3030
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.oap.query.promql.entity.response;
20+
21+
import lombok.Data;
22+
import lombok.EqualsAndHashCode;
23+
24+
@EqualsAndHashCode(callSuper = true)
25+
@Data
26+
public class QueryFormatRsp extends QueryResponse {
27+
private String data;
28+
}

0 commit comments

Comments
 (0)