You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by el...@apache.org on 2020/04/02 11:22:48 UTC
[hadoop-ozone] branch master updated: HDDS-3130. Add jaeger trace
span in s3gateway
This is an automated email from the ASF dual-hosted git repository.
elek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 6384b8d HDDS-3130. Add jaeger trace span in s3gateway
6384b8d is described below
commit 6384b8de4cbabf3d4aa66bd7d7682fe21caee1d8
Author: runzhiwang <ru...@tencent.com>
AuthorDate: Thu Apr 2 13:22:05 2020 +0200
HDDS-3130. Add jaeger trace span in s3gateway
Closes #645
---
.../java/org/apache/hadoop/ozone/s3/Gateway.java | 2 +
.../org/apache/hadoop/ozone/s3/TracingFilter.java | 78 ++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/Gateway.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/Gateway.java
index 09fcb01..5d34181 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/Gateway.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/Gateway.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,6 +48,7 @@ public class Gateway extends GenericCli {
@Override
public Void call() throws Exception {
OzoneConfiguration ozoneConfiguration = createOzoneConfiguration();
+ TracingUtil.initTracing("S3gateway", ozoneConfiguration);
OzoneConfigurationHolder.setConfiguration(ozoneConfiguration);
ozoneConfiguration.set("hadoop.http.authentication.type", "simple");
httpServer = new S3GatewayHttpServer(ozoneConfiguration, "s3gateway");
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java
new file mode 100644
index 0000000..80b28b5
--- /dev/null
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java
@@ -0,0 +1,78 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.s3;
+
+import io.opentracing.Scope;
+import io.opentracing.ScopeManager;
+import io.opentracing.Span;
+import io.opentracing.util.GlobalTracer;
+
+import javax.ws.rs.container.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Filter used to add jaeger tracing span.
+ */
+
+@Provider
+public class TracingFilter implements ContainerRequestFilter,
+ ContainerResponseFilter {
+
+ public static final String TRACING_SCOPE = "TRACING_SCOPE";
+
+ @Context
+ private ResourceInfo resourceInfo;
+
+ private void closeScope(Scope scope) {
+ if (scope != null) {
+ Span span = scope.span();
+ if (span != null) {
+ span.finish();
+ }
+
+ scope.close();
+ }
+ }
+
+ private void closeActiveScope() {
+ ScopeManager manager = GlobalTracer.get().scopeManager();
+
+ if (manager != null) {
+ Scope scope = manager.active();
+ closeScope(scope);
+ }
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) {
+ closeActiveScope();
+
+ Scope scope = GlobalTracer.get().buildSpan(
+ resourceInfo.getResourceClass().getSimpleName() + "." +
+ resourceInfo.getResourceMethod().getName()).startActive(true);
+ requestContext.setProperty(TRACING_SCOPE, scope);
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext,
+ ContainerResponseContext responseContext) {
+ Scope scope = (Scope)requestContext.getProperty(TRACING_SCOPE);
+ closeScope(scope);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-commits-help@hadoop.apache.org