'Spark 3 custom Source not exported to Prometheus

I wrote a custom Source, that successfully exports my metrics to ConsoleSink. However, it doesn't export it to the Prometheus endpoint.

Is there a special way to enable Prometheus export to metrics?

class TestMetricsSource extends Source {
  override val sourceName: String = "TestMetricSource"

  override val metricRegistry: MetricRegistry = new MetricRegistry
  val METRIC: Counter = metricRegistry.counter(MetricRegistry.name("testCounter"))
}

Registered it

val source = new TestMetricsSource
SparkEnv.get.metricsSystem.registerSource(source)

Set value

source.METRIC.update(100);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source