Azure / Azure/azure-sdk-for-java
[ARM] Metric not found after using list metric definition
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 2.2k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 178
Description
We are consuming metrics for different resources.
The way we do it is by first listing the metrics
```
def listMetricsV2(resourceId: String): Future[ResourceMetrics] =
Source
.fromPublisher[MetricDefinition](
underlying
.listByResourceAsync(resourceId)
.timeout(Duration.ofSeconds(5))
.retryWhen(AzureClient.retrySpec)
)
.runFold(List.empty[MetricDefinition])(_ :+ _)
.map(metricDefinitions =>
ResourceMetrics(
resourceId,
metricDefinitions.map { metric =>
metric.name.value -> metric
}.toMap,
)
)
```
and then with those metrics, we query specific ones.
```
....
val datapointsF: Future[Map[Instant, Double]] = metrics
.get(metricName)
.map { metric =>
val query = metric
.defineQuery()
.startingFrom(OffsetDateTime.ofInstant(start, ZoneId.systemDefault()))
.endsBefore(OffsetDateTime.ofInstant(end, ZoneId.systemDefault()))
.withAggregation(aggregation.entryName)
.withInterval(Duration.ofSeconds(period))
}.getOrElse {
log.debug("Requested metric was not under Azure available ones")
}
...
```
So with the metric present in the listMetric response, we are getting the following errors.
```
com.azure.core.management.exception.ManagementException: Status code 400, "{"code":"BadRequest","message":"Failed to find metric configuration for provider: Microsoft.Web, resource Type: serverfarms, metric: DiskQueueLength, Valid metrics: "}"
```
SDK Version:
`"com.azure.resourcemanager" % "azure-resourcemanager" % "2.42.0"`
Contributor guide
Assessment
This issue has not been assessed yet.