Skip to content

Commit ca17afa

Browse files
committed
Redis Connector call counters
1 parent a98cc78 commit ca17afa

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

obp-api/src/main/scala/code/api/cache/Redis.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ object Redis extends MdcLoggable {
177177
jedisConnection.head.del(key).toString
178178
}else if (method ==JedisMethod.GET) {
179179
jedisConnection.head.get(key)
180+
} else if (method == JedisMethod.SCAN) {
181+
import scala.collection.JavaConverters._
182+
jedisConnection.head.keys(key).asScala.mkString(",")
180183
} else if(method ==JedisMethod.SET && value.isDefined){
181184
if (ttlSeconds.isDefined) {//if set ttl, call `setex` method to set the expired seconds.
182185
jedisConnection.head.setex(key, ttlSeconds.get, value.get).toString

obp-api/src/main/scala/code/api/v6_0_0/APIMethods600.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8187,13 +8187,22 @@ trait APIMethods600 {
81878187
|Counters automatically reset every hour (rolling window).
81888188
|The ttl_seconds field shows when the current hour window resets.
81898189
|
8190-
|Requires the props: write_connector_metrics_redis=true
8190+
|Requires the prop: write_connector_metrics_redis=true
8191+
|
8192+
|Redis key format:
8193+
|
8194+
|- Outbound (before connector call): {instance}_{env}_connector_outbound_{version}_{connectorName}_{methodName}_PER_HOUR
8195+
|- Inbound success (after connector call): {instance}_{env}_connector_inbound_{version}_{connectorName}_{methodName}_success_PER_HOUR
8196+
|- Inbound failure (after connector call): {instance}_{env}_connector_inbound_{version}_{connectorName}_{methodName}_failure_PER_HOUR
8197+
|
8198+
|For example: obp_dev_connector_outbound_1_star_getBanks_PER_HOUR
81918199
|
81928200
|Authentication is Required
81938201
|
81948202
|""".stripMargin,
81958203
EmptyBody,
81968204
ConnectorCountsJsonV600(
8205+
enabled = true,
81978206
connector_counts = List(
81988207
ConnectorCountJsonV600(
81998208
connector_name = "mapped",
@@ -8221,6 +8230,7 @@ trait APIMethods600 {
82218230
} yield {
82228231
val counts = ConnectorCountsRedis.getAllCounts()
82238232
val json = ConnectorCountsJsonV600(
8233+
enabled = ConnectorCountsRedis.isEnabled,
82248234
connector_counts = counts.map(c => ConnectorCountJsonV600(
82258235
connector_name = c.connector_name,
82268236
method_name = c.method_name,

obp-api/src/main/scala/code/api/v6_0_0/JSONFactory6.0.0.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ case class ConnectorCountJsonV600(
753753
)
754754

755755
case class ConnectorCountsJsonV600(
756+
enabled: Boolean,
756757
connector_counts: List[ConnectorCountJsonV600]
757758
)
758759

obp-api/src/main/scala/code/metrics/ConnectorMetricsRedis.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object ConnectorCountsRedis extends MdcLoggable {
9292

9393
// Scan for outbound keys
9494
val outboundPattern = s"${outboundPrefix}*_PER_HOUR"
95-
val outboundKeys = Redis.use(JedisMethod.SCAN, outboundPattern).map(_.split(",").toList.filter(_.nonEmpty)).getOrElse(List.empty)
95+
val outboundKeys = Redis.scanKeys(outboundPattern)
9696

9797
// Build a map of connectorName_methodName -> outbound count
9898
val outboundMap: Map[String, Long] = outboundKeys.flatMap { key =>
@@ -104,7 +104,7 @@ object ConnectorCountsRedis extends MdcLoggable {
104104

105105
// Scan for inbound keys
106106
val inboundPattern = s"${inboundPrefix}*_PER_HOUR"
107-
val inboundKeys = Redis.use(JedisMethod.SCAN, inboundPattern).map(_.split(",").toList.filter(_.nonEmpty)).getOrElse(List.empty)
107+
val inboundKeys = Redis.scanKeys(inboundPattern)
108108

109109
// Build maps for success and failure inbound counts
110110
val inboundSuccessMap = scala.collection.mutable.Map[String, Long]()

0 commit comments

Comments
 (0)