You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wa...@apache.org on 2022/07/01 12:36:48 UTC
[skywalking] branch master updated: Add Zipkin query exception handler, response error message for illegal arguments. (#9296)
This is an automated email from the ASF dual-hosted git repository.
wankai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new b9196966cd Add Zipkin query exception handler, response error message for illegal arguments. (#9296)
b9196966cd is described below
commit b9196966cd7763631a8333a0706e1733d51ffbc4
Author: Wan Kai <wa...@foxmail.com>
AuthorDate: Fri Jul 1 20:36:33 2022 +0800
Add Zipkin query exception handler, response error message for illegal arguments. (#9296)
---
docs/en/changes/changes.md | 3 +-
.../handler/ZipkinQueryExceptionHandler.java | 41 ++++++++++++++++++++++
.../query/zipkin/handler/ZipkinQueryHandler.java | 2 ++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index c233ead30f..2f008074cf 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -12,7 +12,8 @@
* Support sending alarm messages to PagerDuty.
* Support Zipkin kafka collector.
* Add `VIRTUAL` detect type to Process for Network Profiling.
-* Add component ID(128) for Java Hutool plugin
+* Add component ID(128) for Java Hutool plugin.
+* Add Zipkin query exception handler, response error message for illegal arguments.
#### UI
diff --git a/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryExceptionHandler.java b/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryExceptionHandler.java
new file mode 100644
index 0000000000..7c1c71beae
--- /dev/null
+++ b/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryExceptionHandler.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.query.zipkin.handler;
+
+import com.linecorp.armeria.common.HttpRequest;
+import com.linecorp.armeria.common.HttpResponse;
+import com.linecorp.armeria.server.ServiceRequestContext;
+import com.linecorp.armeria.server.annotation.ExceptionHandlerFunction;
+
+import static com.linecorp.armeria.common.HttpStatus.BAD_REQUEST;
+import static com.linecorp.armeria.common.HttpStatus.INTERNAL_SERVER_ERROR;
+import static com.linecorp.armeria.common.MediaType.ANY_TEXT_TYPE;
+
+public class ZipkinQueryExceptionHandler implements ExceptionHandlerFunction {
+ @Override
+ public HttpResponse handleException(final ServiceRequestContext ctx, final HttpRequest req, final Throwable cause) {
+ String rspMsg = cause.getMessage() != null ? cause.getMessage() : cause.getClass().getSimpleName();
+ // Response msg for illegal query args.
+ if (cause instanceof IllegalArgumentException) {
+ return HttpResponse.of(BAD_REQUEST, ANY_TEXT_TYPE, rspMsg);
+ } else {
+ return HttpResponse.of(INTERNAL_SERVER_ERROR, ANY_TEXT_TYPE, rspMsg);
+ }
+ }
+}
diff --git a/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryHandler.java b/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryHandler.java
index 2b06942378..8ad88b3421 100644
--- a/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryHandler.java
+++ b/oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryHandler.java
@@ -29,6 +29,7 @@ import com.linecorp.armeria.common.ResponseHeaders;
import com.linecorp.armeria.common.ResponseHeadersBuilder;
import com.linecorp.armeria.server.annotation.Blocking;
import com.linecorp.armeria.server.annotation.Default;
+import com.linecorp.armeria.server.annotation.ExceptionHandler;
import com.linecorp.armeria.server.annotation.Get;
import com.linecorp.armeria.server.annotation.Param;
import java.io.IOException;
@@ -63,6 +64,7 @@ import static com.linecorp.armeria.common.MediaType.ANY_TEXT_TYPE;
/**
* Reference from zipkin2.server.internal.ZipkinQueryApiV2 for the API consistent.
*/
+@ExceptionHandler(ZipkinQueryExceptionHandler.class)
public class ZipkinQueryHandler {
private final ZipkinQueryConfig config;
private final ModuleManager moduleManager;