atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shweth...@apache.org
Subject [1/2] incubator-atlas git commit: ATLAS-1116 Performance monitoring of backend methods in API requests (shwethags)
Date Mon, 21 Nov 2016 11:07:25 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 94a827220 -> 1fa052643


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1fa05264/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
index ac89869..a5ef57d 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
@@ -21,6 +21,7 @@ package org.apache.atlas.web.resources;
 import com.google.common.base.Preconditions;
 import org.apache.atlas.AtlasClient;
 import org.apache.atlas.AtlasConfiguration;
+import org.apache.atlas.aspect.Monitored;
 import org.apache.atlas.classification.InterfaceAudience;
 import org.apache.atlas.discovery.DiscoveryException;
 import org.apache.atlas.discovery.DiscoveryService;
@@ -82,6 +83,7 @@ public class MetadataDiscoveryResource {
      * @param offset offset to the results returned, used for pagination. offset >= 0.
-1 maps to offset 0
      * @return JSON representing the type and results.
      */
+    @Monitored
     @GET
     @Path("search")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
@@ -89,11 +91,6 @@ public class MetadataDiscoveryResource {
     public Response search(@QueryParam("query") String query,
                            @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit,
                            @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int
offset) {
-        AtlasPerfTracer perf = null;
-        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.search("
+ query + ", " + limit + ", " + offset + ")");
-        }
-
         boolean dslQueryFailed = false;
         Response response = null;
         try {
@@ -109,7 +106,6 @@ public class MetadataDiscoveryResource {
         if ( dslQueryFailed ) {
             response = searchUsingFullText(query, limit, offset);
         }
-        AtlasPerfTracer.log(perf);
         return response;
     }
 
@@ -125,6 +121,7 @@ public class MetadataDiscoveryResource {
      *
      * @return JSON representing the type and results.
      */
+    @Monitored
     @GET
     @Path("search/dsl")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
@@ -132,12 +129,7 @@ public class MetadataDiscoveryResource {
     public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery,
                                         @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit")
int limit,
                                         @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset")
int offset) {
-        AtlasPerfTracer perf = null;
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingQueryDSL("
+ dslQuery + ", " + limit + ", " + offset + ")");
-            }
-
             dslQuery = ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null");
             QueryParams queryParams = validateQueryParams(limit, offset);
             final String jsonResultStr = discoveryService.searchByDSL(dslQuery, queryParams);
@@ -151,8 +143,6 @@ public class MetadataDiscoveryResource {
         } catch (Throwable e) {
             LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 
@@ -184,18 +174,14 @@ public class MetadataDiscoveryResource {
      * @param gremlinQuery search query in raw gremlin format.
      * @return JSON representing the type and results.
      */
+    @Monitored
     @GET
     @Path("search/gremlin")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
     @InterfaceAudience.Private
     public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) {
-        AtlasPerfTracer perf = null;
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingGremlinQuery("
+ gremlinQuery + ")");
-            }
-
             gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null
or empty");
             final List<Map<String, String>> results = discoveryService.searchByGremlin(gremlinQuery);
 
@@ -218,8 +204,6 @@ public class MetadataDiscoveryResource {
         } catch (Throwable e) {
             LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 
@@ -231,6 +215,7 @@ public class MetadataDiscoveryResource {
      * @param offset offset to the results returned, used for pagination. offset >= 0.
-1 maps to offset 0
      * @return JSON representing the type and results.
      */
+    @Monitored
     @GET
     @Path("search/fulltext")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
@@ -238,12 +223,7 @@ public class MetadataDiscoveryResource {
     public Response searchUsingFullText(@QueryParam("query") String query,
                                         @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit")
int limit,
                                         @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset")
int offset) {
-        AtlasPerfTracer perf = null;
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingFullText("
+ query + ", " + limit + ", " + offset + ")");
-            }
-
             query = ParamChecker.notEmpty(query, "query cannot be null or empty");
             QueryParams queryParams = validateQueryParams(limit, offset);
             final String jsonResultStr = discoveryService.searchByFullText(query, queryParams);
@@ -257,8 +237,6 @@ public class MetadataDiscoveryResource {
         } catch (Throwable e) {
             LOG.error("Unable to get entity list for query {}", query, e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1fa05264/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
index e899fcf..7a9840b 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
@@ -20,10 +20,9 @@ package org.apache.atlas.web.resources;
 
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.core.ResourceContext;
-
 import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.AtlasException;
+import org.apache.atlas.aspect.Monitored;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.typedef.AtlasClassificationDef;
@@ -89,19 +88,15 @@ public class TypesResource {
      * Submits a type definition corresponding to a given type representing a meta model
of a
      * domain. Could represent things like Hive Database, Hive Table, etc.
      */
+    @Monitored
     @POST
     @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public Response submit(@Context HttpServletRequest request) {
         TypesREST typesRest = resourceContext.getResource(TypesREST.class);
-        AtlasPerfTracer perf = null;
         JSONArray typesResponse = new JSONArray();
 
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
-            }
-
             final String typeDefinition = Servlets.getRequestPayload(request);
             LOG.info("Creating type with definition {} ", typeDefinition);
 
@@ -129,8 +124,6 @@ public class TypesResource {
         } catch (Throwable e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 
@@ -143,18 +136,14 @@ public class TypesResource {
      * @param request
      * @return
      */
+    @Monitored
     @PUT
     @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public Response update(@Context HttpServletRequest request) {
         TypesREST typesRest = resourceContext.getResource(TypesREST.class);
-        AtlasPerfTracer perf = null;
         JSONArray typesResponse = new JSONArray();
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
-            }
-
             final String typeDefinition = Servlets.getRequestPayload(request);
             LOG.info("Updating type with definition {} ", typeDefinition);
 
@@ -182,8 +171,6 @@ public class TypesResource {
         } catch (Throwable e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 
@@ -192,19 +179,15 @@ public class TypesResource {
      *
      * @param typeName name of a type which is unique.
      */
+    @Monitored
     @GET
     @Path("{typeName}")
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName")
String typeName) {
         TypesREST typesRest = resourceContext.getResource(TypesREST.class);
         JSONObject response = new JSONObject();
-        AtlasPerfTracer perf = null;
 
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition("
+ typeName + ")");
-            }
-
             TypeCategory typeCategory = typeRegistry.getType(typeName).getTypeCategory();
             TypesDef typesDef = null;
 
@@ -247,8 +230,6 @@ public class TypesResource {
         } catch (Throwable e) {
             LOG.error("Unable to get type definition for type {}", typeName, e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 
@@ -264,6 +245,7 @@ public class TypesResource {
      * For example, typeCategory = TRAIT && supertype contains 'X' && supertype
!contains 'Y'
      * If there is no filter, all the types are returned
      */
+    @Monitored
     @GET
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public Response getTypesByFilter(@Context HttpServletRequest request, @QueryParam("type")
String typeCategory,
@@ -271,12 +253,7 @@ public class TypesResource {
                                      @QueryParam("notsupertype") String notsupertype) throws
AtlasBaseException {
         TypesREST typesRest  = resourceContext.getResource(TypesREST.class);
         JSONObject response  = new JSONObject();
-        AtlasPerfTracer perf = null;
         try {
-            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter("
+ typeCategory + ")");
-            }
-
             List<String> result = RestUtils.getTypeNames(typesRest.getTypeDefHeaders());
 
             response.put(AtlasClient.RESULTS, new JSONArray(result));
@@ -291,8 +268,6 @@ public class TypesResource {
         } catch (Throwable e) {
             LOG.error("Unable to get types list", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
-        } finally {
-            AtlasPerfTracer.log(perf);
         }
     }
 }


Mime
View raw message