Sergey Postument
09/20/2023, 12:20 PM<https://nightlies.apache.org/flink/flink-docs-master/docs/ops/metrics/>
but we have no idea how to add custom labels for metrics. even it’s possible or not, or what’s best practice for it
in example:
class MyMapper extends RichMapFunction[String,String] {
@transient private var counter: Counter = _
override def open(parameters: Configuration): Unit = {
counter = getRuntimeContext()
.getMetricGroup()
.counter("myCounter")
}
override def map(value: String): String = {
value match {
case "OK" => counter.inc("customLabel: SUCCESS")
case "KO" => counter.inc("customLabel: FAIL")
case _ => counter.inc("customLabel: UNKNOWN")
}
value
}
}
so depends on data we want to add some labels
Is that possible?
crazy idea comes to my head about create side output, generate metrics there and sink them via httpSink to prometheus push gateway 😄Alexey Seleznev
09/20/2023, 12:55 PMgetRuntimeContext()
.getMetricGroup()
.addGroup("valid", result.toString)
.addGroup("event", event)
.addGroup("team", team)
.counter("count")
Sergey Postument
09/20/2023, 1:24 PMprocessFunction
it’s fully static thing, and we want to make it a bit dynamicAlexey Seleznev
09/20/2023, 2:51 PMSergey Postument
09/20/2023, 2:54 PMmetric = getRuntimeContext()
.getMetricGroup()
.addGroup("valid", result.toString)
.addGroup("event", event)
.addGroup("team", team)
.counter("count")
metric.inc()
inside process function, not in open()
?Alexey Seleznev
09/20/2023, 2:57 PM_val nameToCounter_: mutable.HashMap[String, _Counter_]
When I first get specific set of values for this metric I put this counter into hashMap and use this HashMap in .process()Alexey Seleznev
09/20/2023, 2:58 PMdef process()....
nameToCounter(hashedSetOfValues).inc()
Trystan
09/20/2023, 5:02 PM