Skip to content

Commit

Permalink
Refactor CloudWatch reporting by adding dedicated reporter class (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Séamus Ó Ceanainn authored Apr 12, 2022
1 parent e07f0cf commit ff763ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/main/scala/RemoraApp.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import java.io.IOException
import java.net.ConnectException
import java.util.concurrent.{TimeUnit, TimeoutException}

import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Supervision}
import com.amazonaws.services.cloudwatch.{AmazonCloudWatchAsync, AmazonCloudWatchAsyncClientBuilder}
Expand All @@ -10,7 +9,7 @@ import com.codahale.metrics.jvm.{GarbageCollectorMetricSet, MemoryUsageGaugeSet,
import com.typesafe.scalalogging.LazyLogging
import config.{KafkaSettings, MetricsSettings}
import kafka.admin.RemoraKafkaConsumerGroupService
import reporter.RemoraDatadogReporter
import reporter.{RemoraCloudWatchReporter, RemoraDatadogReporter}
import filter.CloudWatchMetricFilter

import scala.concurrent.duration._
Expand Down Expand Up @@ -54,17 +53,8 @@ object RemoraApp extends App with nl.grons.metrics.scala.DefaultInstrumented wit

if (metricsSettings.cloudWatch.enabled) {
logger.info("Reporting metricsRegistry to Cloudwatch")
val amazonCloudWatchAsync: AmazonCloudWatchAsync = AmazonCloudWatchAsyncClientBuilder.defaultClient

val logMetricFilter = new CloudWatchMetricFilter(metricsSettings.cloudWatch.metricFilter)

new CloudWatchReporterBuilder()
.withNamespace(metricsSettings.cloudWatch.name)
.withRegistry(metricRegistry)
.withClient(amazonCloudWatchAsync)
.withFilter(logMetricFilter)
.build()
.start(metricsSettings.cloudWatch.intervalMinutes, TimeUnit.MINUTES)
val cloudWatchReporter = new RemoraCloudWatchReporter(metricRegistry, metricsSettings.cloudWatch)
cloudWatchReporter.startReporter()
}

if (metricsSettings.dataDog.enabled) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/scala/reporter/RemoraCloudWatchReporter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package reporter

import com.amazonaws.services.cloudwatch.{AmazonCloudWatchAsync, AmazonCloudWatchAsyncClientBuilder}
import com.blacklocus.metrics.CloudWatchReporterBuilder
import com.codahale.metrics.MetricRegistry
import config.CloudWatch
import filter.CloudWatchMetricFilter

import java.util.concurrent.TimeUnit

class RemoraCloudWatchReporter(metricRegistry: MetricRegistry, cloudWatchConfig: CloudWatch) {
val amazonCloudWatchAsync: AmazonCloudWatchAsync = AmazonCloudWatchAsyncClientBuilder.defaultClient

val logMetricFilter = new CloudWatchMetricFilter(cloudWatchConfig.metricFilter)

def startReporter(): Unit = new CloudWatchReporterBuilder()
.withNamespace(cloudWatchConfig.name)
.withRegistry(metricRegistry)
.withClient(amazonCloudWatchAsync)
.withFilter(logMetricFilter)
.build()
.start(cloudWatchConfig.intervalMinutes, TimeUnit.MINUTES)
}

0 comments on commit ff763ef

Please sign in to comment.