Skip to content

Commit 91895b9

Browse files
committed
add error handler
1 parent db407db commit 91895b9

File tree

12 files changed

+338
-146
lines changed

12 files changed

+338
-146
lines changed

oap-server/server-query-plugin/traceql-plugin/src/main/antlr4/org/apache/skywalking/oap/query/tempo/grammar/TraceQLLexer.g4

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ NIL: 'nil';
2929
// Scope selectors
3030
RESOURCE: 'resource';
3131
SPAN: 'span';
32-
INTRINSIC: 'intrinsic';
33-
EVENT: 'event';
34-
LINK: 'link';
32+
// Not support yet
33+
//INTRINSIC: 'intrinsic';
34+
//EVENT: 'event';
35+
//LINK: 'link';
3536

3637
// Operators
3738
DOT: '.';
@@ -50,8 +51,9 @@ LT: '<';
5051
LTE: '<=';
5152
GT: '>';
5253
GTE: '>=';
53-
RE: '=~'; // Regex match
54-
NRE: '!~'; // Regex not match
54+
// Not support yet
55+
//RE: '=~'; // Regex match
56+
//NRE: '!~'; // Regex not match
5557

5658
// Arithmetic operators
5759
PLUS: '+';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.traceql.entity;
20+
21+
import com.fasterxml.jackson.annotation.JsonInclude;
22+
import lombok.Builder;
23+
import lombok.Data;
24+
25+
/**
26+
* Error response entity for Tempo API.
27+
* Used when requests fail with 4xx or 5xx status codes.
28+
*/
29+
@Data
30+
@Builder
31+
@JsonInclude(JsonInclude.Include.NON_NULL)
32+
public class ErrorResponse {
33+
/**
34+
* Error message describing what went wrong.
35+
*/
36+
private String error;
37+
38+
/**
39+
* Optional error code for programmatic error handling.
40+
*/
41+
private String errorType;
42+
}
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.traceql.exception;
20+
21+
public class IllegalExpressionException extends Exception {
22+
public IllegalExpressionException(String message) {
23+
super(message);
24+
}
25+
}

oap-server/server-query-plugin/traceql-plugin/src/main/java/org/apache/skywalking/oap/query/traceql/handler/TraceQLApiHandler.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@
3333
import java.util.Optional;
3434
import org.apache.commons.codec.DecoderException;
3535
import org.apache.skywalking.oap.query.traceql.entity.BuildInfoResponse;
36+
import org.apache.skywalking.oap.query.traceql.entity.ErrorResponse;
3637
import org.apache.skywalking.oap.query.traceql.entity.QueryResponse;
3738

3839
/**
3940
* Handler for Grafana Tempo API endpoints.
4041
* Implements the Tempo API specification for trace querying and search.
42+
*
43+
* Error Handling:
44+
* - 200 OK: Successful request
45+
* - 400 Bad Request: Invalid request parameters (malformed TraceQL query, invalid duration format, etc.)
4146
*/
4247
public abstract class TraceQLApiHandler {
4348
private static final ObjectMapper MAPPER = new ObjectMapper();
@@ -318,5 +323,32 @@ protected HttpResponse successResponse(QueryResponse response) throws JsonProces
318323
HttpData.ofUtf8(MAPPER.writeValueAsString(response))
319324
);
320325
}
326+
327+
/**
328+
* Create an error response with appropriate HTTP status code.
329+
*
330+
* @param status HTTP status code
331+
* @param message Error message
332+
* @return HTTP response with error details
333+
*/
334+
protected HttpResponse errorResponse(HttpStatus status, String message) throws JsonProcessingException {
335+
ErrorResponse error = ErrorResponse.builder()
336+
.error(message)
337+
.build();
338+
return HttpResponse.of(
339+
ResponseHeaders.builder(status)
340+
.contentType(MediaType.JSON)
341+
.build(),
342+
HttpData.ofUtf8(MAPPER.writeValueAsString(error))
343+
);
344+
}
345+
346+
/**
347+
* Create a 400 Bad Request error response.
348+
* Used for invalid request parameters like malformed TraceQL queries.
349+
*/
350+
protected HttpResponse badRequestResponse(String message) throws JsonProcessingException {
351+
return errorResponse(HttpStatus.BAD_REQUEST, message);
352+
}
321353
}
322354

0 commit comments

Comments
 (0)