Skip to content

Commit

Permalink
Add unit tests for getMetric and batchGetMetrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
riemanli committed Apr 25, 2023
1 parent c7d1c37 commit 62d4dd9
Show file tree
Hide file tree
Showing 2 changed files with 411 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ class MetricsService(
getInternalMetric(metricKey.cmmsMeasurementConsumerId, apiIdToExternalId(metricKey.metricId))

// Early exit when the metric is at a terminal state.
if (determineMetricState(internalMetric) != Metric.State.RUNNING) {
if (internalMetric.state != Metric.State.RUNNING) {
return internalMetric.toMetric()
}

Expand Down Expand Up @@ -942,7 +942,7 @@ class MetricsService(
// Only syncs pending measurements which can only be in metrics that are still running.
val toBeSyncedInternalMeasurements: List<InternalMeasurement> =
internalMetrics
.filter { internalMetric -> determineMetricState(internalMetric) == Metric.State.RUNNING }
.filter { internalMetric -> internalMetric.state == Metric.State.RUNNING }
.flatMap { internalMetric -> internalMetric.weightedMeasurementsList }
.map { weightedMeasurement -> weightedMeasurement.measurement }
.filter { internalMeasurement ->
Expand Down Expand Up @@ -1073,7 +1073,12 @@ class MetricsService(
return try {
batchGetInternalMetrics(cmmsMeasurementConsumerId, listOf(externalMetricId)).first()
} catch (e: StatusException) {
throw Exception("Unable to get metrics from the reporting database.", e)
val metricName =
MetricKey(cmmsMeasurementConsumerId, externalIdToApiId(externalMetricId)).toName()
throw Exception(
"Unable to get the metric with name = [${metricName}] from the reporting database.",
e
)
}
}

Expand Down
Loading

0 comments on commit 62d4dd9

Please sign in to comment.