-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collect data rate for raw input, intermediate input and final output
- Loading branch information
Showing
6 changed files
with
114 additions
and
54 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
13 changes: 13 additions & 0 deletions
13
atlas-eval/src/main/scala/com/netflix/atlas/eval/model/EvalDataRate.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,13 @@ | ||
package com.netflix.atlas.eval.model | ||
|
||
import com.netflix.atlas.json.JsonSupport | ||
|
||
case class EvalDataRate( | ||
timestamp: Long, | ||
step: Long, | ||
inputCount: Map[String, Int], | ||
intermediateCount: Map[String, Int], | ||
outputCount: Int | ||
) extends JsonSupport { | ||
val `type`: String = "rate" | ||
} |
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
79 changes: 79 additions & 0 deletions
79
atlas-eval/src/main/scala/com/netflix/atlas/eval/stream/EvalDataRateCollector.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,79 @@ | ||
package com.netflix.atlas.eval.stream | ||
|
||
import com.netflix.atlas.core.model.DataExpr | ||
import com.netflix.atlas.core.util.RefIntHashMap | ||
import com.netflix.atlas.eval.model.EvalDataRate | ||
|
||
import scala.collection.mutable | ||
|
||
class EvalDataRateCollector(timestamp: Long, step: Long) { | ||
|
||
private val inputCounts = mutable.Map.empty[String, RefIntHashMap[DataExpr]] | ||
private val intermediateCounts = mutable.Map.empty[String, RefIntHashMap[DataExpr]] | ||
private val outputCounts = new RefIntHashMap[String] | ||
|
||
def incrementOutput(id: String, amount: Int): Unit = { | ||
outputCounts.increment(id, amount) | ||
} | ||
|
||
def incrementIntermediate(id: String, dataExpr: DataExpr, amount: Int): Unit = { | ||
increment(intermediateCounts, id, dataExpr, amount) | ||
} | ||
|
||
def incrementInput(id: String, dataExpr: DataExpr, amount: Int): Unit = { | ||
increment(inputCounts, id, dataExpr, amount) | ||
} | ||
|
||
def getAll: Map[String, EvalDataRate] = { | ||
inputCounts.map { | ||
case (id, _) => { | ||
id -> EvalDataRate( | ||
timestamp, | ||
step, | ||
getDataRate(inputCounts, id), | ||
getDataRate(intermediateCounts, id), | ||
outputCounts.get(id, 0) | ||
) | ||
} | ||
}.toMap | ||
} | ||
|
||
private def getDataRate( | ||
counts: mutable.Map[String, RefIntHashMap[DataExpr]], | ||
id: String | ||
): Map[String, Int] = { | ||
counts.get(id) match { | ||
case Some(v: RefIntHashMap[DataExpr]) => | ||
var total = 0 | ||
val builder = Map.newBuilder[String, Int] | ||
v.foreach { (dataExpr, count) => | ||
builder += dataExpr.toString -> count | ||
total += count | ||
} | ||
builder += EvalDataRateCollector.Total -> total | ||
builder.result() | ||
case None => EvalDataRateCollector.EmptyCounts | ||
} | ||
} | ||
|
||
private def increment( | ||
counts: mutable.Map[String, RefIntHashMap[DataExpr]], | ||
id: String, | ||
dataExpr: DataExpr, | ||
amount: Int | ||
): Unit = { | ||
counts.get(id) match { | ||
case Some(v: RefIntHashMap[DataExpr]) => v.increment(dataExpr, amount) | ||
case None => | ||
val temp = new RefIntHashMap[DataExpr] | ||
temp.increment(dataExpr, amount) | ||
counts += (id -> temp) | ||
} | ||
} | ||
|
||
} | ||
|
||
object EvalDataRateCollector { | ||
val Total = "total" | ||
val EmptyCounts = Map(Total -> 0) | ||
} |
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