SLS to DQL¶
POST /api/v1/sls/convert
Overview¶
Converts Alibaba Cloud SLS query statements to Log DQL without querying data in the Workspace.
Prerequisites and Usage Steps¶
- Copy the query expression from the Alibaba Cloud SLS query. If you need to limit the Log Index used for the results, first obtain the Log Index List for the current Workspace.
- Initiate the conversion request. This API does not execute the query in the Workspace.
- Check status and diagnostics. For approximate conversions, manually confirm the differences, and after confirmation pass dql to the DQL query API.
For example, when query is "* | SHOW TABLES", the result may be unsupported. In this case, use diagnostics to determine the parts that require manual adjustment.
Request Headers¶
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| DF-API-KEY | string | Y | AK identifier, AK UUID Example: <DF-API-KEY>How to obtain or enter: Create or obtain a Key with permissions for this API in API Key Management of the target Workspace. |
Body Request Parameters¶
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| query | string | Y | Alibaba Cloud SLS query statement Null allowed: False Empty string allowed: False Example: status:200How to obtain or enter: Copy the part to be converted from the SLS query statement; use double quotes for JSON strings. |
| indexes | array | Optional. List of Log Index names; if omitted or an empty array is passed, indexes are not restricted Null allowed: False Example: ["default"]How to obtain or enter: Enter an array of existing Log Index names; take values from content.data[*].name returned by the Log Index List. |
Additional Parameter Notes¶
The returned status indicates the conversion equivalence level:
exact: The generated DQL is equivalent to the original SLS query;approximate: An approximate DQL has been generated; the caller should confirm the differences withdiagnosticsbefore execution;unsupported: The current SLS syntax is not supported, anddqlmay be empty.
Studio always uses the log namespace L. indexes is optional; if omitted or an empty array is passed, no index restriction is added.
Request Example¶
curl 'https://openapi.guance.com/api/v1/sls/convert' \
-H 'Content-Type: application/json' \
-H 'DF-API-KEY: <DF-API-KEY>' \
--data-raw '{"query":"status:200","indexes":["default"]}'
Response¶
HTTP 200, application/json. The example retains the status:200 and default index conditions from the request.
| Field | Type | Description |
|---|---|---|
| content.status | string | Conversion result. exact means exact conversion, approximate means approximate conversion, and unsupported means unsupported. |
| content.dql | string | Converted DQL; may be empty or omitted when the status is unsupported. |
| content.diagnostics | array | Conversion diagnostics. For an exact conversion with no diagnostics, this is []; otherwise, the value is as actually returned by the converter. |
| content.diagnostics[].severity | string | Diagnostic severity, such as warning or error. |
| content.diagnostics[].code | string | Diagnostic identifier. |
| content.diagnostics[].message | string | Diagnostic description. |
| content.diagnostics[].hint | string | Optional correction hint. |
| content.unsupported_class | string | Optional. Classification when the conversion is unsupported. |
{
"code": 200,
"content": {
"status": "exact",
"dql": "L(\"default\")::*:(*){ (`status` = 200) }",
"diagnostics": []
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE-EXAMPLE"
}
Error Response¶
For authentication, rate limiting, and common request errors, see Common Error Definitions.
| HTTP Status | errorCode | Trigger Condition | Message or Response Description | Resolution |
|---|---|---|---|---|
| 406 | ft.ParameterValidationFailed | Request parameters violate field declarations | The message indicates the invalid field or rule. | Correct the request according to the corresponding parameter table. |
| 400 | ft.RequestJsonFormatError | Request JSON syntax error | Request JSON format error. content contains reason, line, and column. | Fix the JSON syntax and retry. |
| 406 | ft.DqlParseError | The converter is unavailable, or a ParserError is thrown when calling parser | DQL parser parsing failed; the message contains the reason. | Check the syntax first; if the converter is unavailable, contact the service administrator. |
| 406 | ft.ParameterCheckFailed | query is empty after trimming leading and trailing whitespace, or an indexes member is not a string | Returns a generic parameter validation failure message. | Use a non-empty SLS statement and an array of string indexes. |