Skip to content
Snippets Groups Projects
Commit accfbcf0 authored by Aayushi Jain's avatar Aayushi Jain
Browse files

Merge branch 'latencyDebug' into 'azure/m12-master'

Added Logs to Debug Partition Latency Issue

See merge request !283
parents 13fef08a 90fc4f93
No related branches found
No related tags found
3 merge requests!299M14 Upgrade,!296M14 upgrade,!283Added Logs to Debug Partition Latency Issue
Pipeline #151638 failed
......@@ -14,6 +14,8 @@
package org.opengroup.osdu.partition.api;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.model.Property;
......@@ -22,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -40,10 +43,12 @@ import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@RestController
@RequestScope
@RequestMapping(path = "/partitions", produces = "application/json")
@Slf4j
public class PartitionApi {
@Autowired
......@@ -73,7 +78,10 @@ public class PartitionApi {
@GetMapping("/{partitionId}")
@PreAuthorize("@authorizationFilter.hasPermissions()")
public ResponseEntity<Map<String, Property>> get(@PathVariable("partitionId") String partitionId) {
Stopwatch stopwatch = Stopwatch.createStarted();
PartitionInfo partitionInfo = this.partitionService.getPartition(partitionId);
stopwatch.stop();
log.info(String.format("Total time taken to GetPartition Method: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
this.auditLogger.readPartitionSuccess(Collections.singletonList(partitionId));
return ResponseEntity.ok(partitionInfo.getProperties());
}
......@@ -90,8 +98,9 @@ public class PartitionApi {
@PreAuthorize("@authorizationFilter.hasPermissions()")
public List<String> list() {
List<String> partitions = this.partitionService.getAllPartitions();
log.info("Total Partition record in GetAll query {}", partitions.size());
this.auditLogger.readListPartitionSuccess(
Collections.singletonList(String.format("Partition list size = %s", partitions.size())));
Collections.singletonList(String.format("Partition list size = %s", partitions.size())));
return partitions;
}
}
......@@ -14,14 +14,19 @@
package org.opengroup.osdu.partition.provider.azure.persistence;
import com.google.common.base.Stopwatch;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.table.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@Component
@Slf4j
public class CloudTableStore {
@Autowired
......@@ -42,19 +47,33 @@ public class CloudTableStore {
public Iterable<? extends TableEntity> queryByKey(final Class<? extends TableEntity> clazzType, final String key, final String value) {
Stopwatch stopwatch = Stopwatch.createStarted();
String partitionFilter = TableQuery.generateFilterCondition(
key,
TableQuery.QueryComparisons.EQUAL,
value);
stopwatch.stop();
log.info(String.format("Time taken by generateFilterCondition Method: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
stopwatch.reset();
stopwatch.start();
TableQuery<? extends TableEntity> partitionQuery = TableQuery.from(clazzType)
.where(partitionFilter);
stopwatch.stop();
log.info(String.format("Time taken by Generate Table query Method: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
try {
stopwatch.reset();
stopwatch.start();
return this.cloudTableClient.execute(partitionQuery);
} catch (Exception e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "error getting partition", e.getMessage(), e);
}
finally {
stopwatch.stop();
log.info(String.format("Time taken to execute query: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
}
}
public Iterable<? extends TableEntity> queryByCompoundKey(final Class<? extends TableEntity> clazzType,
......
......@@ -14,16 +14,20 @@
package org.opengroup.osdu.partition.provider.azure.persistence;
import com.google.common.base.Stopwatch;
import com.microsoft.azure.storage.table.EntityProperty;
import com.microsoft.azure.storage.table.TableBatchOperation;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.model.Property;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Component
@Slf4j
public class PartitionTableStore {
private final static String ID = "id";
......@@ -68,8 +72,11 @@ public class PartitionTableStore {
public Map<String, Property> getPartition(String partitionId) {
Map<String, Property> out = new HashMap<>();
Stopwatch stopwatch = Stopwatch.createStarted();
List<PartitionEntity> partitionEntities = this.getAllByPartitionId(partitionId);
stopwatch.stop();
log.info(String.format("Total time taken by Get Partition Method based on PartitionId: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
if (partitionEntities.isEmpty()) {
return out;
}
......@@ -122,6 +129,7 @@ public class PartitionTableStore {
tableEntity.setName(tableEntity.getRowKey());
out.add(tableEntity);
}
log.info("Result Size {}", out.size());
return out;
}
......
......@@ -14,6 +14,8 @@
package org.opengroup.osdu.partition.provider.azure.service;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -30,8 +32,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class PartitionServiceImpl implements IPartitionService {
static final String PARTITION_LIST_KEY = "getAllPartitions";
......@@ -86,10 +90,17 @@ public class PartitionServiceImpl implements IPartitionService {
@Override
public PartitionInfo getPartition(String partitionId) {
Stopwatch stopwatch = Stopwatch.createStarted();
PartitionInfo pi = partitionServiceCache.get(partitionId);
stopwatch.stop();
log.info(String.format("Total time taken to fetch from PartitionCache: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
if (pi == null) {
stopwatch.reset();
stopwatch.start();
Map<String, Property> out = new HashMap<>(tableStore.getPartition(partitionId));
stopwatch.stop();
log.info(String.format("Total time taken to Fetch Data From Storage Table: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
if (out.isEmpty()) {
throw new AppException(HttpStatus.SC_NOT_FOUND, PARTITION_NOT_FOUND, String.format("%s partition not found", partitionId));
......@@ -125,8 +136,10 @@ public class PartitionServiceImpl implements IPartitionService {
List<String> partitions = partitionListCache.get(PARTITION_LIST_KEY);
if (partitions == null) {
Stopwatch stopwatch = Stopwatch.createStarted();
partitions = tableStore.getAllPartitions();
stopwatch.stop();
log.info(String.format("Total time taken to fetch all partition: %d", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
if (partitions != null) {
partitionListCache.put(PARTITION_LIST_KEY, partitions);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment