From 4dfa7134a5daa14c417f48f53559aa132914238d Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 8 Feb 2023 11:08:40 +0100 Subject: [PATCH] OBPv510/refactor new endpoint getAggregateMetrics-use isNewVersion Boolean --- .../main/scala/code/api/v3_0_0/APIMethods300.scala | 2 +- .../main/scala/code/api/v5_1_0/APIMethods510.scala | 2 +- obp-api/src/main/scala/code/metrics/APIMetrics.scala | 12 +++++++++--- .../scala/code/metrics/ElasticsearchMetrics.scala | 2 +- .../src/main/scala/code/metrics/MappedMetrics.scala | 8 ++++---- .../scala/code/remotedata/RemotedataMetrics.scala | 6 +++--- .../code/remotedata/RemotedataMetricsActor.scala | 6 +++--- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala index f7a07d815..d20b90cc2 100644 --- a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala +++ b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala @@ -2164,7 +2164,7 @@ trait APIMethods300 { _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadAggregateMetrics, callContext) httpParams <- NewStyle.function.extractHttpParamsFromUrl(cc.url) (obpQueryParams, callContext) <- createQueriesByHttpParamsFuture(httpParams, callContext) - aggregateMetrics <- APIMetrics.apiMetrics.vend.getAllAggregateMetricsFuture(obpQueryParams, ApiVersion.v3_0_0) map { + aggregateMetrics <- APIMetrics.apiMetrics.vend.getAllAggregateMetricsFuture(obpQueryParams, false) map { x => unboxFullOrFail(x, callContext, GetAggregateMetricsError) } } yield { diff --git a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala index 949170beb..16fb9e044 100644 --- a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala +++ b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala @@ -430,7 +430,7 @@ trait APIMethods510 { _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadAggregateMetrics, callContext) httpParams <- NewStyle.function.extractHttpParamsFromUrl(cc.url) (obpQueryParams, callContext) <- createQueriesByHttpParamsFuture(httpParams, callContext) - aggregateMetrics <- APIMetrics.apiMetrics.vend.getAllAggregateMetricsFuture(obpQueryParams,OBPAPI5_1_0.version) map { + aggregateMetrics <- APIMetrics.apiMetrics.vend.getAllAggregateMetricsFuture(obpQueryParams,true) map { x => unboxFullOrFail(x, callContext, GetAggregateMetricsError) } } yield { diff --git a/obp-api/src/main/scala/code/metrics/APIMetrics.scala b/obp-api/src/main/scala/code/metrics/APIMetrics.scala index a3c3e5412..9e113f57e 100644 --- a/obp-api/src/main/scala/code/metrics/APIMetrics.scala +++ b/obp-api/src/main/scala/code/metrics/APIMetrics.scala @@ -84,8 +84,14 @@ trait APIMetrics { // def getAllGroupedByUserId() : Map[String, List[APIMetric]] def getAllMetrics(queryParams: List[OBPQueryParam]): List[APIMetric] - - def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], apiVersion: ApiVersion): Future[Box[List[AggregateMetrics]]] + + /** + * + * @param queryParams + * @param isNewVersion from V510, we change the queryParams, use includeXxx instead of excludeXxxx, so add this flag + * @return + */ + def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], isNewVersion: Boolean): Future[Box[List[AggregateMetrics]]] def getTopApisFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopApi]]] @@ -102,7 +108,7 @@ class RemotedataMetricsCaseClasses { // case class getAllGroupedByDay() // case class getAllGroupedByUserId() case class getAllMetrics(queryParams: List[OBPQueryParam]) - case class getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], apiVersion: ApiVersion) + case class getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], isNewVersion: Boolean) case class getTopApisFuture(queryParams: List[OBPQueryParam]) case class getTopConsumersFuture(queryParams: List[OBPQueryParam]) case class bulkDeleteMetrics() diff --git a/obp-api/src/main/scala/code/metrics/ElasticsearchMetrics.scala b/obp-api/src/main/scala/code/metrics/ElasticsearchMetrics.scala index 6acd0d096..5a86442ef 100644 --- a/obp-api/src/main/scala/code/metrics/ElasticsearchMetrics.scala +++ b/obp-api/src/main/scala/code/metrics/ElasticsearchMetrics.scala @@ -55,7 +55,7 @@ object ElasticsearchMetrics extends APIMetrics { MappedMetric.findAll(optionalParams: _*) } - override def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], apiVersion: ApiVersion): Future[Box[List[AggregateMetrics]]] = ??? + override def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], isNewVersion: Boolean): Future[Box[List[AggregateMetrics]]] = ??? override def getTopApisFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopApi]]] = ??? diff --git a/obp-api/src/main/scala/code/metrics/MappedMetrics.scala b/obp-api/src/main/scala/code/metrics/MappedMetrics.scala index 28c34dad3..a4b70c9fe 100644 --- a/obp-api/src/main/scala/code/metrics/MappedMetrics.scala +++ b/obp-api/src/main/scala/code/metrics/MappedMetrics.scala @@ -264,7 +264,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{ } // TODO Cache this as long as fromDate and toDate are in the past (before now) - def getAllAggregateMetricsBox(queryParams: List[OBPQueryParam], apiVersion: ApiVersion): Box[List[AggregateMetrics]] = { + def getAllAggregateMetricsBox(queryParams: List[OBPQueryParam], isNewVersion: Boolean): Box[List[AggregateMetrics]] = { /** * Please note that "var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)" * is just a temporary value field with UUID values in order to prevent any ambiguity. @@ -309,7 +309,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{ val extendedIncludeImplementedByPartialFunctionsQueries = extendCurrentQuery(includeImplementedByPartialFunctionsNumberList) val result = scalikeDB readOnly { implicit session => - val sqlQuery = if(apiVersion.equals(ApiVersion.v5_1_0)) + val sqlQuery = if(isNewVersion) // in the version, we use includeXxx instead of excludeXxx, the performance should be better. sql"""SELECT count(*), avg(duration), min(duration), max(duration) FROM metric WHERE date_c >= ${new Timestamp(fromDate.get.getTime)} @@ -362,8 +362,8 @@ object MappedMetrics extends APIMetrics with MdcLoggable{ }} } - override def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], apiVersion: ApiVersion): Future[Box[List[AggregateMetrics]]] = Future{ - getAllAggregateMetricsBox(queryParams: List[OBPQueryParam],apiVersion) + override def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], isNewVersion: Boolean): Future[Box[List[AggregateMetrics]]] = Future{ + getAllAggregateMetricsBox(queryParams: List[OBPQueryParam], isNewVersion) } override def bulkDeleteMetrics(): Boolean = { diff --git a/obp-api/src/main/scala/code/remotedata/RemotedataMetrics.scala b/obp-api/src/main/scala/code/remotedata/RemotedataMetrics.scala index 51dcef273..19c3d4e4e 100644 --- a/obp-api/src/main/scala/code/remotedata/RemotedataMetrics.scala +++ b/obp-api/src/main/scala/code/remotedata/RemotedataMetrics.scala @@ -37,9 +37,9 @@ object RemotedataMetrics extends ObpActorInit with APIMetrics { (actor ? cc.getAllMetrics(queryParams)).mapTo[List[APIMetric]] ) - override def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], apiVersion: ApiVersion): Future[Box[List[AggregateMetrics]]] ={ - logger.debug(s"RemotedataMetrics.getAllAggregateMetrics($queryParams, $apiVersion)") - (actor ? cc.getAllAggregateMetricsFuture(queryParams,apiVersion)).mapTo[Box[List[AggregateMetrics]]] + override def getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], isNewVersion: Boolean): Future[Box[List[AggregateMetrics]]] ={ + logger.debug(s"RemotedataMetrics.getAllAggregateMetrics($queryParams, $isNewVersion)") + (actor ? cc.getAllAggregateMetricsFuture(queryParams,isNewVersion)).mapTo[Box[List[AggregateMetrics]]] } override def getTopApisFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopApi]]] = { diff --git a/obp-api/src/main/scala/code/remotedata/RemotedataMetricsActor.scala b/obp-api/src/main/scala/code/remotedata/RemotedataMetricsActor.scala index 6f3bba542..df8365cf4 100644 --- a/obp-api/src/main/scala/code/remotedata/RemotedataMetricsActor.scala +++ b/obp-api/src/main/scala/code/remotedata/RemotedataMetricsActor.scala @@ -40,9 +40,9 @@ class RemotedataMetricsActor extends Actor with ObpActorHelper with MdcLoggable logger.debug("getAllMetrics()") sender ! (mapper.getAllMetrics(queryParams)) - case cc.getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], apiVersion: ApiVersion) => - logger.debug(s"RemotedataMetricsActor.getAllAggregateMetricsFuture($queryParams, $apiVersion)") - sender ! (mapper.getAllAggregateMetricsBox(queryParams,apiVersion)) + case cc.getAllAggregateMetricsFuture(queryParams: List[OBPQueryParam], isNewVersion: Boolean) => + logger.debug(s"RemotedataMetricsActor.getAllAggregateMetricsFuture($queryParams, $isNewVersion)") + sender ! (mapper.getAllAggregateMetricsBox(queryParams, isNewVersion)) case cc.getTopApisFuture(queryParams: List[OBPQueryParam]) => logger.debug(s"getTopApisFuture($queryParams)")