Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-28816 add timed metrics for repos #1157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.mosip.resident.aspect;

import static io.mosip.resident.constant.ResidentConstants.DB_QUERY_RESPONSE_TIME_DESCRIPTION;
import static io.mosip.resident.constant.ResidentConstants.DB_QUERY_RESPONSE_TIME_ID;

import java.util.concurrent.TimeUnit;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
/**
* Aspect class for database metrics to record the query time metrics
*
* @author Ritik Jain
*/
@Component
@Aspect
@EnableAspectJAutoProxy
@ConditionalOnProperty(value = "resident.db.metrics.aspect.enabled", havingValue = "true", matchIfMissing = false)
public class DatabaseMetricsAspect {

@Autowired
private MeterRegistry registry;

@Pointcut("execution(* io.mosip.resident.repository.ResidentTransactionRepository.*(..))")
public void repositoryMethods() {
}

@Around("repositoryMethods()")
public Object aroundAdvice(ProceedingJoinPoint jp) throws Throwable {
Timer timer = Timer.builder(DB_QUERY_RESPONSE_TIME_ID)
.tag("label", DB_QUERY_RESPONSE_TIME_DESCRIPTION)
.tag("method", jp.getSignature().toLongString())
.tag("target", jp.getTarget().getClass().getCanonicalName())
.register(registry);
long start = System.nanoTime();
Object result = jp.proceed();
timer.record(System.nanoTime() - start, TimeUnit.NANOSECONDS);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ private ResidentConstants() {
public static final String API_RESPONSE_TIME_DESCRIPTION = "API Response Time";

public static final String API_RESPONSE_TIME_ID = "api.response.time";

public static final String DB_QUERY_RESPONSE_TIME_DESCRIPTION = "DB Query Response Time";
public static final String DB_QUERY_RESPONSE_TIME_ID = "db.query.response.time";
public static final String UNDER_SCORE = "_";
public static final String IDENTITY = "identity";
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ public enum EventEnum {
"download service history failed", "RS-DOWN_SER", "Download service history", RESIDENT_APPLICATION_ID,
RESIDENT_APPLICATION_NAME),
INVALID_REQUEST_TYPE_CODE("RES-SER-267", FAILURE, "Invalid request type code",
"\"Invalid Request Type. Please input eventId only for VID_CARD_DOWNLOAD,\" +\n"
+ "\t\t\t\"DOWNLOAD_PERSONALIZED_CARD, UPDATE_MY_UIN",
"Invalid Request Type. Please input eventId only for VID_CARD_DOWNLOAD and UPDATE_MY_UIN",
"RS-VAL", "Validation", RESIDENT_APPLICATION_ID, RESIDENT_APPLICATION_NAME),
DOWNLOAD_REGISTRATION_CENTER_SUCCESS("RES-SER-269", SUCCESS, "download registration center: Success",
"download registration center success based on language code and hierarchy level", "RS-DOWN_CARD",
Expand Down