-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #669 from ptrdom/e2e-test-fix
Fix e2e tests
- Loading branch information
Showing
7 changed files
with
178 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
e2e-test/src/it/scala/io/scalac/mesmer/e2e/PrometheusExporterMetrics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.scalac.mesmer.e2e | ||
|
||
import io.scalac.mesmer.e2e.E2ETest.OpenTelemetryCollectorApi | ||
import org.scalatest.EitherValues | ||
import org.scalatest.Suite | ||
import org.scalatest.concurrent.Eventually | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
trait PrometheusExporterMetrics extends Eventually with Matchers with EitherValues { this: Suite => | ||
import PrometheusExporterMetrics._ | ||
|
||
def assertMetricsExists(collectorApi: OpenTelemetryCollectorApi, metricNamePrefix: String)( | ||
metrics: Seq[Metric] | ||
): Unit = | ||
eventually { | ||
collectorApi.assertMetrics { response => | ||
val expected = metrics.map { | ||
case Metric.Counter(name) => | ||
s"# TYPE ${metricNamePrefix}_$name counter" | ||
case Metric.Gauge(name) => | ||
s"# TYPE ${metricNamePrefix}_$name gauge" | ||
case Metric.Histogram(name) => | ||
s"# TYPE ${metricNamePrefix}_$name histogram" | ||
} | ||
|
||
val actual = response | ||
.lines() | ||
.iterator() | ||
.asScala | ||
.filter(_.startsWith("# TYPE")) | ||
.toSeq | ||
|
||
val result = expected.diff(actual) | ||
|
||
if (result.nonEmpty) { | ||
fail( | ||
s"Prometheus exporter missing expected metrics - [${result.mkString("[", ",", "]")}], \nexpected - ${expected | ||
.mkString("[", ",", "]")}, \nactual - ${actual.mkString("[", ",", "]")}" | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
object PrometheusExporterMetrics { | ||
sealed trait Metric { | ||
val name: String | ||
} | ||
object Metric { | ||
case class Counter(name: String) extends Metric | ||
case class Gauge(name: String) extends Metric | ||
case class Histogram(name: String) extends Metric | ||
} | ||
} |
Oops, something went wrong.