Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEOMESA-3400 Micrometer - remove geomesa-utils dependency #3210

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions geomesa-metrics/geomesa-metrics-micrometer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<name>GeoMesa Metrics Micrometer</name>

<dependencies>
<dependency>
<groupId>org.locationtech.geomesa</groupId>
<artifactId>geomesa-utils_${scala.binary.version}</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
Expand All @@ -28,6 +24,10 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe.scala-logging</groupId>
<artifactId>scala-logging_${scala.binary.version}</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
package org.locationtech.geomesa.metrics.micrometer
package prometheus
import com.typesafe.config.Config
import com.typesafe.scalalogging.LazyLogging
import io.micrometer.core.instrument.{MeterRegistry, Tag}
import io.micrometer.prometheusmetrics.{PrometheusMeterRegistry, PrometheusRenameFilter}
import io.prometheus.metrics.exporter.httpserver.HTTPServer
import io.prometheus.metrics.exporter.pushgateway.{Format, PushGateway, Scheme}
import org.locationtech.geomesa.utils.io.CloseWithLogging
import pureconfig.{ConfigReader, ConfigSource}
import pureconfig.generic.semiauto.deriveReader
import pureconfig.{ConfigReader, ConfigSource}

import java.io.Closeable
import java.util.Locale
import java.util.concurrent.atomic.AtomicReference
import scala.util.control.NonFatal

object PrometheusFactory extends RegistryFactory {
object PrometheusFactory extends RegistryFactory with LazyLogging {

import scala.collection.JavaConverters._

Expand All @@ -33,7 +34,12 @@ object PrometheusFactory extends RegistryFactory {
val dependentClose = new AtomicReference[Closeable]()
val registry = new PrometheusMeterRegistry(k => config.properties.getOrElse(k, null)) {
override def close(): Unit = {
CloseWithLogging(Option(dependentClose.get()))
val child = dependentClose.get()
if (child != null) {
try { child.close() } catch {
case NonFatal(e) => logger.error("Error on close:", e)
}
}
super.close()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
package org.locationtech.geomesa.metrics.micrometer

import com.typesafe.config.ConfigFactory
import io.micrometer.core.instrument.util.IOUtils
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import org.apache.commons.io.IOUtils
import org.junit.runner.RunWith
import org.locationtech.geomesa.utils.io.WithClose
import org.mortbay.jetty.handler.AbstractHandler
import org.mortbay.jetty.{Request, Server}
import org.specs2.mutable.Specification
Expand All @@ -27,7 +26,12 @@ import scala.collection.mutable.ArrayBuffer
@RunWith(classOf[JUnitRunner])
class PrometheusReporterTest extends Specification {

private def getFreePort: Int = WithClose(new ServerSocket(0))(_.getLocalPort)
private def getFreePort: Int = {
val socket = new ServerSocket(0)
try { socket.getLocalPort } finally {
socket.close()
}
}

"Prometheus reporter" should {
"expose metrics over http" in {
Expand All @@ -40,12 +44,15 @@ class PrometheusReporterTest extends Specification {

val metrics = ArrayBuffer.empty[String]
val url = new URL(s"http://localhost:$port/metrics")
WithClose(new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { is =>
var line = is.readLine()
val reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))
try {
var line = reader.readLine()
while (line != null) {
metrics += line
line = is.readLine()
line = reader.readLine()
}
} finally {
reader.close()
}

metrics must contain("foo_total 10.0")
Expand All @@ -64,12 +71,15 @@ class PrometheusReporterTest extends Specification {

val metrics = ArrayBuffer.empty[String]
val url = new URL(s"http://localhost:$port/metrics")
WithClose(new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { is =>
var line = is.readLine()
val reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))
try {
var line = reader.readLine()
while (line != null) {
metrics += line
line = is.readLine()
line = reader.readLine()
}
} finally {
reader.close()
}

metrics must contain("""foo_total{foo="bar"} 10.0""")
Expand Down
Loading