From d6fa30dc61702a026a4b12936f13fa26c1b20baa Mon Sep 17 00:00:00 2001 From: anilkumar Date: Wed, 7 Aug 2024 11:35:26 +0530 Subject: [PATCH] Integrate StopWatch for detailed function tracking --- .../operation/Neo4JBoltSearchOperations.java | 11 ++++++++++- .../service/util/SearchQueryGenerationUtil.java | 8 +++++++- .../graph/dac/mgr/impl/Neo4JBoltSearchMgrImpl.java | 8 ++++++++ .../graph/engine/mgr/impl/NodeManagerImpl.java | 8 +++++++- .../graph/engine/mgr/impl/SearchManagerImpl.java | 7 +++++++ .../learning/framework/FrameworkHierarchy.java | 14 +++++++++++++- .../learning/hierarchy/store/HierarchyStore.java | 7 +++++++ .../org/sunbird/common/mgr/ConvertToGraphNode.java | 14 ++++++++++++++ .../framework/mgr/impl/BaseFrameworkManager.java | 8 +++++++- 9 files changed, 80 insertions(+), 5 deletions(-) diff --git a/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/operation/Neo4JBoltSearchOperations.java b/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/operation/Neo4JBoltSearchOperations.java index 671f435420..99c8464df4 100644 --- a/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/operation/Neo4JBoltSearchOperations.java +++ b/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/operation/Neo4JBoltSearchOperations.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.dto.Property; import org.sunbird.common.dto.Request; import org.sunbird.common.exception.ResourceNotFoundException; @@ -109,8 +110,10 @@ public static Node getNodeById(String graphId, Long nodeId, Boolean getTags, Req * @return the node by unique id */ public static Node getNodeByUniqueId(String graphId, String nodeId, Boolean getTags, Request request) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); TelemetryManager.log("Graph Id: " + graphId + "\nNode Id: " + nodeId + "\nGet Tags:" + getTags); - + TelemetryManager.log("Neo4JBoltSearchOperations getNodeByUniqueId function started"); if (StringUtils.isBlank(graphId)) throw new ClientException(DACErrorCodeConstants.INVALID_GRAPH.name(), DACErrorMessageConstants.INVALID_GRAPH_ID + " | ['Get Node By Unique Id' Operation Failed.]"); @@ -122,6 +125,9 @@ public static Node getNodeByUniqueId(String graphId, String nodeId, Boolean getT Node node = (Node) NodeCacheManager.getDataNode(graphId, nodeId); if (null != node) { + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for Neo4JBoltSearchOperations getNodeByUniqueId function returning node from cache: " + durationInSeconds + " seconds"); TelemetryManager.info("Fetched node from in-memory cache: "+node.getIdentifier()); return node; } else { @@ -156,6 +162,9 @@ public static Node getNodeByUniqueId(String graphId, String nodeId, Boolean getT startNodeMap, endNodeMap); } } + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for Neo4JBoltSearchOperations getNodeByUniqueId function: " + durationInSeconds + " seconds"); return node; } } diff --git a/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/util/SearchQueryGenerationUtil.java b/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/util/SearchQueryGenerationUtil.java index 82376bd25e..c9eb3d6127 100644 --- a/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/util/SearchQueryGenerationUtil.java +++ b/platform-core/graph-engine/module/graph-dac-api/src/main/java/org/sunbird/graph/service/util/SearchQueryGenerationUtil.java @@ -3,6 +3,7 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.dto.Property; import org.sunbird.graph.dac.enums.GraphDACParams; import org.sunbird.graph.dac.enums.SystemProperties; @@ -38,7 +39,9 @@ public static String generateGetNodeByIdCypherQuery(Map paramete } public static String generateGetNodeByUniqueIdCypherQuery(Map parameterMap) { - + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("SearchQueryGenerationUtil generateGetNodeByUniqueIdCypherQuery function started"); StringBuilder query = new StringBuilder(); if (null != parameterMap) { String graphId = (String) parameterMap.get(GraphDACParams.graphId.name()); @@ -58,6 +61,9 @@ public static String generateGetNodeByUniqueIdCypherQuery(Map pa } TelemetryManager.log("Returning Get Node By Unique Id Cypher Query: " + query); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for SearchQueryGenerationUtil generateGetNodeByUniqueIdCypherQuery function : " + durationInSeconds + " seconds"); return query.toString(); } diff --git a/platform-core/graph-engine/module/graph-dac/src/main/java/org/sunbird/graph/dac/mgr/impl/Neo4JBoltSearchMgrImpl.java b/platform-core/graph-engine/module/graph-dac/src/main/java/org/sunbird/graph/dac/mgr/impl/Neo4JBoltSearchMgrImpl.java index b330fd4328..ee8c29d8c9 100644 --- a/platform-core/graph-engine/module/graph-dac/src/main/java/org/sunbird/graph/dac/mgr/impl/Neo4JBoltSearchMgrImpl.java +++ b/platform-core/graph-engine/module/graph-dac/src/main/java/org/sunbird/graph/dac/mgr/impl/Neo4JBoltSearchMgrImpl.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.dto.Property; import org.sunbird.common.dto.Request; import org.sunbird.common.dto.Response; @@ -23,6 +24,7 @@ import org.sunbird.graph.dac.model.SubGraph; import org.sunbird.graph.dac.model.Traverser; import org.sunbird.graph.service.operation.Neo4JBoltSearchOperations; +import org.sunbird.telemetry.logger.TelemetryManager; public class Neo4JBoltSearchMgrImpl extends BaseDACMgr implements IGraphDACSearchMgr { @@ -43,6 +45,9 @@ public Response getNodeById(Request request) { @Override public Response getNodeByUniqueId(Request request) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("Neo4jBoltSearchMgrImpl getNodeByUniqueId function started"); String graphId = (String) request.getContext().get(GraphHeaderParams.graph_id.name()); String nodeId = (String) request.get(GraphDACParams.node_id.name()); Boolean getTags = (Boolean) request.get(GraphDACParams.get_tags.name()); @@ -51,6 +56,9 @@ public Response getNodeByUniqueId(Request request) { } else { try { Node node = Neo4JBoltSearchOperations.getNodeByUniqueId(graphId, nodeId, getTags, request); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.log("Neo4jBoltSearchMgrImpl getNodeByUniqueId function completed in " + durationInSeconds + " seconds"); return OK(GraphDACParams.node.name(), node); } catch (Exception e) { return ERROR(e); diff --git a/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/NodeManagerImpl.java b/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/NodeManagerImpl.java index 890c7aa1a1..6ed1ffc1cd 100644 --- a/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/NodeManagerImpl.java +++ b/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/NodeManagerImpl.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.dto.Request; import org.sunbird.common.dto.Response; import org.sunbird.common.exception.ClientException; @@ -324,6 +325,9 @@ public void validateNode(Request request) { */ @Override public void updateDataNode(final Request request) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("NodeManagerImpl updateDataNode function started"); final ActorRef parent = getSender(); String graphId = (String) request.getContext().get(GraphHeaderParams.graph_id.name()); String nodeId = (String) request.get(GraphDACParams.node_id.name()); @@ -407,8 +411,10 @@ public void updateDataNode(final Request request) { ERROR(GraphEngineErrorCodes.ERR_GRAPH_UPDATE_NODE_NOT_FOUND.name(), "Node Not Found", ResponseCode.RESOURCE_NOT_FOUND, GraphDACParams.messages.name(), messages, parent); } - } + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; + TelemetryManager.log("NodeManagerImpl updateDataNode function completed in " + durationInSeconds + " seconds"); } @SuppressWarnings("unchecked") diff --git a/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/SearchManagerImpl.java b/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/SearchManagerImpl.java index f74a2ce2da..7ef0dcacff 100644 --- a/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/SearchManagerImpl.java +++ b/platform-core/graph-engine/module/graph-engine/src/main/java/org/sunbird/graph/engine/mgr/impl/SearchManagerImpl.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.dto.Property; import org.sunbird.common.dto.Request; import org.sunbird.common.exception.ClientException; @@ -102,6 +103,9 @@ public void getNodeDefinitionFromCache(Request request) { @Override public void getDataNode(Request request) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("SearchManagerImpl getDataNode function started"); String nodeId = (String) request.get(GraphDACParams.node_id.name()); if (!validateRequired(nodeId)) { throw new ClientException(GraphEngineErrorCodes.ERR_GRAPH_SEARCH_MISSING_REQ_PARAMS.name(), @@ -115,6 +119,9 @@ public void getDataNode(Request request) { handleException(e, getSender()); } } + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.log("SearchManagerImpl getDataNode function completed in " + durationInSeconds + " seconds"); } @SuppressWarnings("unchecked") diff --git a/platform-modules/actors/src/main/java/org/sunbird/learning/framework/FrameworkHierarchy.java b/platform-modules/actors/src/main/java/org/sunbird/learning/framework/FrameworkHierarchy.java index 007720f3a3..fc77806379 100644 --- a/platform-modules/actors/src/main/java/org/sunbird/learning/framework/FrameworkHierarchy.java +++ b/platform-modules/actors/src/main/java/org/sunbird/learning/framework/FrameworkHierarchy.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.Platform; import org.sunbird.common.dto.Request; import org.sunbird.common.dto.Response; @@ -53,6 +54,9 @@ public class FrameworkHierarchy extends BaseManager { * @throws Exception */ public void generateFrameworkHierarchy(String id) throws Exception { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("FrameworkHierarchy generateFrameworkHierarchy function started"); Response responseNode = getDataNode(GRAPH_ID, id); if (checkError(responseNode)) throw new ResourceNotFoundException("ERR_DATA_NOT_FOUND", "Data not found with id : " + id); @@ -61,7 +65,6 @@ public void generateFrameworkHierarchy(String id) throws Exception { FrameworkCache.delete(id); Map frameworkDocument = new HashMap<>(); Map frameworkHierarchy = getHierarchy(node.getIdentifier(), 0, false, true); - TelemetryManager.info("frameworkHierarchy map::: "+frameworkHierarchy); CategoryCache.setFramework(node.getIdentifier(), frameworkHierarchy); frameworkDocument.putAll(frameworkHierarchy); @@ -74,6 +77,9 @@ public void generateFrameworkHierarchy(String id) throws Exception { frameworkDocument.put(field, node.getMetadata().get(field)); } hierarchyStore.saveOrUpdateHierarchy(node.getIdentifier(),frameworkDocument); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for FrameworkHierarchy generateFrameworkHierarchy function: " + durationInSeconds + " seconds"); } else { throw new ClientException(ResponseCode.CLIENT_ERROR.name(), "The object with given identifier is not a framework: " + id); } @@ -96,6 +102,9 @@ public Map getFrameworkHierarchy(String frameworkId) throws Exce @SuppressWarnings("unchecked") private Map getHierarchy(String id, int index, boolean includeMetadata, boolean includeRelations) throws Exception { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("FrameworkHierarchy getHierarchy function started"); Map data = new HashMap(); Response responseNode = getDataNode(GRAPH_ID, id); if (checkError(responseNode)) @@ -184,6 +193,9 @@ private Map getHierarchy(String id, int index, boolean includeMe } String jsonData = mapper.writeValueAsString(data); TelemetryManager.info("printing Hierarchy data: "+jsonData); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for FrameworkHierarchy getHierarchy function: " + durationInSeconds + " seconds"); return data; } diff --git a/platform-modules/actors/src/main/java/org/sunbird/learning/hierarchy/store/HierarchyStore.java b/platform-modules/actors/src/main/java/org/sunbird/learning/hierarchy/store/HierarchyStore.java index 3d4f2396ab..abce5906a4 100644 --- a/platform-modules/actors/src/main/java/org/sunbird/learning/hierarchy/store/HierarchyStore.java +++ b/platform-modules/actors/src/main/java/org/sunbird/learning/hierarchy/store/HierarchyStore.java @@ -6,6 +6,7 @@ import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.cassandra.connector.util.CassandraConnector; import org.sunbird.cassandra.store.CassandraStore; import org.sunbird.common.Platform; @@ -40,12 +41,18 @@ public HierarchyStore(String keyspace, String table, String objectType, boolean public void saveOrUpdateHierarchy(String contentId, Map hierarchy) { try { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("HierarchyStore saveOrUpdateHierarchy function started"); String query = "UPDATE " + getKeyspace() + "." + getTable() + " SET hierarchy = ? WHERE identifier = ?"; String hierarchyData = mapper.writeValueAsString(hierarchy); Session session = CassandraConnector.getSession(); PreparedStatement statement = session.prepare(query); BoundStatement boundStatement = new BoundStatement(statement); session.execute(boundStatement.bind(hierarchyData, contentId)); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for HierarchyStore saveOrUpdateHierarchy function: " + durationInSeconds + " seconds"); } catch (JsonProcessingException e) { TelemetryManager.error("Error while updating collection hierarchy for ID" + contentId, e); } diff --git a/platform-modules/common/src/main/java/org/sunbird/common/mgr/ConvertToGraphNode.java b/platform-modules/common/src/main/java/org/sunbird/common/mgr/ConvertToGraphNode.java index 971a7b6b30..e3fc0500d9 100644 --- a/platform-modules/common/src/main/java/org/sunbird/common/mgr/ConvertToGraphNode.java +++ b/platform-modules/common/src/main/java/org/sunbird/common/mgr/ConvertToGraphNode.java @@ -7,6 +7,7 @@ import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.codehaus.jackson.map.ObjectMapper; import org.sunbird.common.dto.NodeDTO; import org.sunbird.graph.dac.enums.SystemProperties; @@ -22,6 +23,9 @@ public class ConvertToGraphNode { @SuppressWarnings({ "unchecked", "rawtypes" }) public static Node convertToGraphNode(Map map, DefinitionDTO definition, Node graphNode) throws Exception { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.info("Started convertToGraphNode function"); Node node = new Node(); if (null != map && !map.isEmpty()) { Map inRelDefMap = new HashMap(); @@ -89,6 +93,10 @@ public static Node convertToGraphNode(Map map, DefinitionDTO def node.setInRelations(inRelations); node.setOutRelations(outRelations); node.setMetadata(metadata); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for convertToGraphNode function: " + durationInSeconds + " seconds"); + TelemetryManager.log("NodeData inRelations and nodeMetadata and outRelations "+(List) node.getInRelations()+", ::"+(Map)node.getMetadata() + ", ::" +(List)node.getOutRelations()); } return node; } @@ -114,6 +122,9 @@ private static void getRelDefMaps(DefinitionDTO definition, Map } private static Map> getDBRelations(DefinitionDTO definition, Node graphNode, Map map) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("ConvertToGraphNode getDBRelations started"); List inRelations = null; List outRelations = null; if (null != graphNode) { @@ -152,6 +163,9 @@ private static Map> getDBRelations(DefinitionDTO definiti Map> relationMaps = new HashMap>(); relationMaps.put("in", inRelations); relationMaps.put("out", outRelations); + stopWatch.stop(); + long durationInSeconds = stopWatch.getTime() / 1000; // Duration in seconds + TelemetryManager.info("Execution time for getDBRelations function: " + durationInSeconds + " seconds"); return relationMaps; } diff --git a/platform-modules/sunbird-framework/src/main/java/org/sunbird/framework/mgr/impl/BaseFrameworkManager.java b/platform-modules/sunbird-framework/src/main/java/org/sunbird/framework/mgr/impl/BaseFrameworkManager.java index 3ee147d5ff..765b16a7dc 100644 --- a/platform-modules/sunbird-framework/src/main/java/org/sunbird/framework/mgr/impl/BaseFrameworkManager.java +++ b/platform-modules/sunbird-framework/src/main/java/org/sunbird/framework/mgr/impl/BaseFrameworkManager.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.StopWatch; import org.sunbird.common.Platform; import org.sunbird.common.Slug; import org.sunbird.common.dto.Request; @@ -102,7 +103,9 @@ protected Response read(String identifier, String objectType, String responseObj protected Response update(String identifier, String objectType, Map map) { if (map.containsKey("translations")) validateTranslation(map); - + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + TelemetryManager.log("BaseFramework update function started"); DefinitionDTO definition = getDefinition(GRAPH_ID, objectType); Response getNodeResponse = getDataNode(GRAPH_ID, identifier); Node graphNode = (Node) getNodeResponse.get(GraphDACParams.node.name()); @@ -112,6 +115,9 @@ protected Response update(String identifier, String objectType, Map