forked from Sunbird-Obsrv/obsrv-core
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#OBS-I27: Hudi Metrics generation logic changes
- Loading branch information
Manjunath
authored and
Manjunath
committed
Jan 3, 2025
1 parent
8bed04c
commit 2579a43
Showing
3 changed files
with
66 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
pipeline/hudi-connector/src/main/scala/org/sunbird/obsrv/util/HMetrics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.sunbird.obsrv.util | ||
|
||
|
||
import org.apache.flink.metrics.Gauge | ||
|
||
import scala.collection.concurrent.TrieMap | ||
|
||
class HMetrics { | ||
private val metricStore = TrieMap[(String, String), Long]() | ||
|
||
def increment(dataset: String, metric: String, value: Long): Unit = { | ||
metricStore.synchronized { | ||
val key = (dataset, metric) | ||
val current = metricStore.getOrElse(key, 0L) | ||
metricStore.put(key, current + value) | ||
} | ||
} | ||
|
||
def getAndReset(dataset: String, metric: String): Long = { | ||
metricStore.synchronized { | ||
val key = (dataset, metric) | ||
val current = metricStore.getOrElse(key, 0L) | ||
metricStore.remove(key) | ||
current | ||
} | ||
} | ||
} | ||
|
||
case class ScalaGauge[T](getValueFn: () => T) extends Gauge[T] { | ||
override def getValue: T = getValueFn() | ||
} |