Hi community,

When our application using the following code to create a Histogram for
reporting latency, this metric under prometheus will be created as COUNTER
metric type, instead of HISTOGRAM metric type:

import org.apache.flink.api.common.functions.RichMapFunction
import org.apache.flink.api.common.typeinfo.TypeInformation
import org.apache.flink.configuration.Configuration
import org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper
import org.apache.flink.metrics.Histogram
import org.apache.flink.streaming.api.functions.ProcessFunction
import org.apache.flink.streaming.api.scala.DataStream
import org.apache.flink.util.Collector

private class ReportLatency[T](
name: String,
extractTimestampMillis: T => Long,
userScope: String = ""
)(implicit clock: Clock)
extends RichMapFunction[T, T] {
@transient private var histogram: Histogram = _

override def open(parameters: Configuration): Unit = {
val dropwizardHistogram = new com.codahale.metrics.Histogram(new
SlidingWindowReservoir(500))

val metricGroupBase = getRuntimeContext.getMetricGroup
val metricGroup = if (userScope.isEmpty) metricGroupBase else
metricGroupBase.addGroup(userScope)
histogram = metricGroup
.histogram(
name,
new DropwizardHistogramWrapper(dropwizardHistogram)
)
}

override def map(record: T): T = {
val timestamp: Long = extractTimestampMillis(record)

calculateLatencyInMillis(timestamp) match {
case Some(latency) => histogram.update(latency)
case None => logger.warn("Latency could not be calculated for timestamp {}",
timestamp)
}

record
}
}

Is this an issue from flink AbstractPrometheusReporter.java?

Regards,
-- 
Eddie Cheung

Reply via email to