Skip to content
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
4 changes: 2 additions & 2 deletions sdk/monitor/azure-monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@ MetricsClient metricsBatchQueryClient = new MetricsClientBuilder()
.endpoint("{endpoint}")
.buildClient();

MetricsBatchQueryResult metricsBatchQueryResult = metricsBatchQueryClient.queryBatch(
MetricsQueryResourcesResult metricsQueryResourcesResult = metricsBatchQueryClient.queryResources(
Arrays.asList("{resourceId1}", "{resourceId2}"),
Arrays.asList("{metric1}", "{metric2}"),
"{metricNamespace}");

for (MetricsQueryResult metricsQueryResult : metricsBatchQueryResult.getMetricsQueryResults()) {
for (MetricsQueryResult metricsQueryResult : metricsQueryResourcesResult.getMetricsQueryResults()) {
// Each MetricsQueryResult corresponds to one of the resourceIds in the batch request.
List<MetricResult> metrics = metricsQueryResult.getMetrics();
metrics.forEach(metric -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.azure.monitor.query.implementation.metricsbatch.models.MetricResultsResponseValuesItem;
import com.azure.monitor.query.implementation.metricsbatch.models.ResourceIdList;
import com.azure.monitor.query.models.AggregationType;
import com.azure.monitor.query.models.MetricsBatchQueryResult;
import com.azure.monitor.query.models.MetricsBatchQueryOptions;
import com.azure.monitor.query.models.MetricsQueryResourcesOptions;
import com.azure.monitor.query.models.MetricsQueryResourcesResult;
import com.azure.monitor.query.models.MetricsQueryResult;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -46,34 +46,34 @@ public final class MetricsAsyncClient {
/**
* Returns all the Azure Monitor metrics requested for the batch of resources.
*
* @param resourceUris The resource URIs for which the metrics is requested.
* @param resourceIds The resource ids for which the metrics is requested.
* @param metricsNames The names of the metrics to query.
* @param metricsNamespace The namespace of the metrics to query.
* @return A time-series metrics result for the requested metric names.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<MetricsBatchQueryResult> queryBatch(List<String> resourceUris, List<String> metricsNames, String metricsNamespace) {
return this.queryBatchWithResponse(resourceUris, metricsNames, metricsNamespace, new MetricsBatchQueryOptions())
public Mono<MetricsQueryResourcesResult> queryResources(List<String> resourceIds, List<String> metricsNames, String metricsNamespace) {
return this.queryResourcesWithResponse(resourceIds, metricsNames, metricsNamespace, new MetricsQueryResourcesOptions())
.map(Response::getValue);
}

/**
* Returns all the Azure Monitor metrics requested for the batch of resources.
*
* @param resourceUris The resource URIs for which the metrics is requested.
* @param resourceIds The resource ids for which the metrics is requested.
* @param metricsNames The names of the metrics to query.
* @param metricsNamespace The namespace of the metrics to query.
* @param options The {@link MetricsBatchQueryOptions} to include for the request.
* @param options The {@link MetricsQueryResourcesOptions} to include for the request.
* @return A time-series metrics result for the requested metric names.
* @throws IllegalArgumentException thrown if {@code resourceUris}, {@code metricsNames} or {@code metricsNamespace} are empty.
* @throws NullPointerException thrown if {@code resourceUris}, {@code metricsNames} or {@code metricsNamespace} are null.
* @throws IllegalArgumentException thrown if {@code resourceIds}, {@code metricsNames} or {@code metricsNamespace} are empty.
* @throws NullPointerException thrown if {@code resourceIds}, {@code metricsNames} or {@code metricsNamespace} are null.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<MetricsBatchQueryResult>> queryBatchWithResponse(List<String> resourceUris, List<String> metricsNames,
String metricsNamespace, MetricsBatchQueryOptions options) {
public Mono<Response<MetricsQueryResourcesResult>> queryResourcesWithResponse(List<String> resourceIds, List<String> metricsNames,
String metricsNamespace, MetricsQueryResourcesOptions options) {

if (CoreUtils.isNullOrEmpty(Objects.requireNonNull(resourceUris, "'resourceUris cannot be null."))) {
return monoError(LOGGER, new IllegalArgumentException("resourceUris cannot be empty"));
if (CoreUtils.isNullOrEmpty(Objects.requireNonNull(resourceIds, "'resourceIds cannot be null."))) {
return monoError(LOGGER, new IllegalArgumentException("resourceIds cannot be empty"));
}

if (CoreUtils.isNullOrEmpty(Objects.requireNonNull(metricsNames, "metricsNames cannot be null"))) {
Expand Down Expand Up @@ -119,9 +119,9 @@ public Mono<Response<MetricsBatchQueryResult>> queryBatchWithResponse(List<Strin
top = options.getTop();
orderBy = options.getOrderBy();
}
String subscriptionId = getSubscriptionFromResourceId(resourceUris.get(0));
String subscriptionId = getSubscriptionFromResourceId(resourceIds.get(0));
ResourceIdList resourceIdList = new ResourceIdList();
resourceIdList.setResourceids(resourceUris);
resourceIdList.setResourceids(resourceIds);
Mono<Response<MetricResultsResponse>> responseMono = this.serviceClient.getMetricsBatches()
.batchWithResponseAsync(subscriptionId, metricsNamespace, metricsNames, resourceIdList, startTime,
endTime, granularity, aggregations, top, orderBy, filter, rollupBy);
Expand All @@ -133,9 +133,9 @@ public Mono<Response<MetricsBatchQueryResult>> queryBatchWithResponse(List<Strin
List<MetricsQueryResult> metricsQueryResults = values.stream()
.map(result -> mapToMetricsQueryResult(result))
.collect(Collectors.toList());
MetricsBatchQueryResult metricsBatchQueryResult = new MetricsBatchQueryResult(metricsQueryResults);
MetricsQueryResourcesResult metricsQueryResourcesResult = new MetricsQueryResourcesResult(metricsQueryResults);
return new SimpleResponse<>(response.getRequest(), response.getStatusCode(),
response.getHeaders(), metricsBatchQueryResult);
response.getHeaders(), metricsQueryResourcesResult);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.azure.monitor.query.implementation.metricsbatch.models.MetricResultsResponseValuesItem;
import com.azure.monitor.query.implementation.metricsbatch.models.ResourceIdList;
import com.azure.monitor.query.models.AggregationType;
import com.azure.monitor.query.models.MetricsBatchQueryResult;
import com.azure.monitor.query.models.MetricsBatchQueryOptions;
import com.azure.monitor.query.models.MetricsQueryResourcesOptions;
import com.azure.monitor.query.models.MetricsQueryResourcesResult;
import com.azure.monitor.query.models.MetricsQueryResult;

import java.time.Duration;
Expand Down Expand Up @@ -45,34 +45,34 @@ public final class MetricsClient {
/**
* Returns all the Azure Monitor metrics requested for the batch of resources.
*
* @param resourceUris The resource URIs for which the metrics is requested.
* @param resourceIds The resource ids for which the metrics is requested.
* @param metricsNames The names of the metrics to query.
* @param metricsNamespace The namespace of the metrics to query.
* @return A time-series metrics result for the requested metric names.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public MetricsBatchQueryResult queryBatch(List<String> resourceUris, List<String> metricsNames, String metricsNamespace) {
return this.queryBatchWithResponse(resourceUris, metricsNames, metricsNamespace, new MetricsBatchQueryOptions(),
public MetricsQueryResourcesResult queryResources(List<String> resourceIds, List<String> metricsNames, String metricsNamespace) {
return this.queryResourcesWithResponse(resourceIds, metricsNames, metricsNamespace, new MetricsQueryResourcesOptions(),
Context.NONE).getValue();
}

/**
* Returns all the Azure Monitor metrics requested for the batch of resources.
*
* @param resourceUris The resource URIs for which the metrics is requested.
* @param resourceIds The resource ids for which the metrics is requested.
* @param metricsNames The names of the metrics to query.
* @param metricsNamespace The namespace of the metrics to query.
* @param options The {@link MetricsBatchQueryOptions} to include for the request.
* @param options The {@link MetricsQueryResourcesOptions} to include for the request.
* @param context The context to associate with this operation.
* @return A time-series metrics result for the requested metric names.
* @throws IllegalArgumentException thrown if {@code resourceUris}, {@code metricsNames} or {@code metricsNamespace} are empty.
* @throws NullPointerException thrown if {@code resourceUris}, {@code metricsNames} or {@code metricsNamespace} are null.
* @throws IllegalArgumentException thrown if {@code resourceIds}, {@code metricsNames} or {@code metricsNamespace} are empty.
* @throws NullPointerException thrown if {@code resourceIds}, {@code metricsNames} or {@code metricsNamespace} are null.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<MetricsBatchQueryResult> queryBatchWithResponse(List<String> resourceUris, List<String> metricsNames,
String metricsNamespace, MetricsBatchQueryOptions options, Context context) {
if (CoreUtils.isNullOrEmpty(Objects.requireNonNull(resourceUris, "'resourceUris cannot be null."))) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("resourceUris cannot be empty"));
public Response<MetricsQueryResourcesResult> queryResourcesWithResponse(List<String> resourceIds, List<String> metricsNames,
String metricsNamespace, MetricsQueryResourcesOptions options, Context context) {
if (CoreUtils.isNullOrEmpty(Objects.requireNonNull(resourceIds, "'resourceIds cannot be null."))) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("resourceIds cannot be empty"));
}

if (CoreUtils.isNullOrEmpty(Objects.requireNonNull(metricsNames, "metricsNames cannot be null"))) {
Expand Down Expand Up @@ -118,9 +118,9 @@ public Response<MetricsBatchQueryResult> queryBatchWithResponse(List<String> res
top = options.getTop();
orderBy = options.getOrderBy();
}
String subscriptionId = getSubscriptionFromResourceId(resourceUris.get(0));
String subscriptionId = getSubscriptionFromResourceId(resourceIds.get(0));
ResourceIdList resourceIdList = new ResourceIdList();
resourceIdList.setResourceids(resourceUris);
resourceIdList.setResourceids(resourceIds);
Response<MetricResultsResponse> response = this.serviceClient.getMetricsBatches()
.batchWithResponse(subscriptionId, metricsNamespace, metricsNames, resourceIdList, startTime,
endTime, granularity, aggregations, top, orderBy, filter, rollupBy, context);
Expand All @@ -129,10 +129,10 @@ public Response<MetricsBatchQueryResult> queryBatchWithResponse(List<String> res
List<MetricsQueryResult> metricsQueryResults = values.stream()
.map(result -> mapToMetricsQueryResult(result))
.collect(Collectors.toList());
MetricsBatchQueryResult metricsBatchQueryResult = new MetricsBatchQueryResult(metricsQueryResults);
MetricsQueryResourcesResult metricsQueryResourcesResult = new MetricsQueryResourcesResult(metricsQueryResults);

return new SimpleResponse<>(response.getRequest(), response.getStatusCode(),
response.getHeaders(), metricsBatchQueryResult);
response.getHeaders(), metricsQueryResourcesResult);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public enum MetricsQueryServiceVersion implements ServiceVersion {
/**
* Service version {@code 2018-01-01}.
*/
V2018_01_01("2018-01-01");
V2018_01_01("2018-01-01"),
/**
* Service version {@code 2024-02-01}.
*/
V2024_02_01("2024-02-01");

String version;

Expand All @@ -29,7 +33,7 @@ public enum MetricsQueryServiceVersion implements ServiceVersion {
* @return The latest supported service version by this library.
*/
public static MetricsQueryServiceVersion getLatest() {
return V2018_01_01;
return V2024_02_01;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum MetricsServiceVersion implements ServiceVersion {
/**
* The preview version of the Metrics Query service.
*/
V2023_10_01("2023-10-01");
V2024_02_01("2024-02-01");

private final String version;

Expand All @@ -30,6 +30,6 @@ public String getVersion() {
* @return the latest {@link MetricsServiceVersion}.
*/
public static MetricsServiceVersion getLatest() {
return V2023_10_01;
return V2024_02_01;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static MetricsQueryResult mapToMetricsQueryResult(MetricResultsResponseVa
.map(metric -> mapToMetrics(metric))
.collect(Collectors.toList());

MetricsQueryResult metricsQueryResult = new MetricsQueryResult(/* TODO (srnagar): fix this item.getCost() */ null,
MetricsQueryResult metricsQueryResult = new MetricsQueryResult(null,
QueryTimeInterval.parse(item.getStarttime() + "/" + item.getEndtime()), Duration.parse(item.getInterval()), item.getNamespace(), item.getResourceregion(), metrics);
return metricsQueryResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* The model class to configure the metrics batch query options.
*/
@Fluent
public final class MetricsBatchQueryOptions {
public final class MetricsQueryResourcesOptions {
private QueryTimeInterval timeInterval;
private Duration granularity;
private List<AggregationType> aggregations;
Expand All @@ -37,7 +37,7 @@ public QueryTimeInterval getTimeInterval() {
*
* @return The updated options instance
*/
public MetricsBatchQueryOptions setTimeInterval(QueryTimeInterval timeInterval) {
public MetricsQueryResourcesOptions setTimeInterval(QueryTimeInterval timeInterval) {
this.timeInterval = timeInterval;
return this;
}
Expand All @@ -56,7 +56,7 @@ public Duration getGranularity() {
*
* @return The updated options instance
*/
public MetricsBatchQueryOptions setGranularity(Duration granularity) {
public MetricsQueryResourcesOptions setGranularity(Duration granularity) {
this.granularity = granularity;
return this;
}
Expand All @@ -74,7 +74,7 @@ public List<AggregationType> getAggregations() {
* @param aggregations the list of aggregations that should be applied to the metrics data.
* @return The updated options instance
*/
public MetricsBatchQueryOptions setAggregations(List<AggregationType> aggregations) {
public MetricsQueryResourcesOptions setAggregations(List<AggregationType> aggregations) {
this.aggregations = aggregations;
return this;
}
Expand All @@ -93,7 +93,7 @@ public Integer getTop() {
*
* @return The updated options instance
*/
public MetricsBatchQueryOptions setTop(Integer top) {
public MetricsQueryResourcesOptions setTop(Integer top) {
this.top = top;
return this;
}
Expand All @@ -112,7 +112,7 @@ public String getOrderBy() {
*
* @return The updated options instance
*/
public MetricsBatchQueryOptions setOrderBy(String orderBy) {
public MetricsQueryResourcesOptions setOrderBy(String orderBy) {
this.orderBy = orderBy;
return this;
}
Expand All @@ -131,7 +131,7 @@ public String getFilter() {
*
* @return The updated options instance
*/
public MetricsBatchQueryOptions setFilter(String filter) {
public MetricsQueryResourcesOptions setFilter(String filter) {
this.filter = filter;
return this;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public String getRollupBy() {
* specify 'RollUpBy=City' to see the results for Seattle and Tacoma rolled up into one timeseries.
* @return The updated options instance
*/
public MetricsBatchQueryOptions setRollupBy(String rollupBy) {
public MetricsQueryResourcesOptions setRollupBy(String rollupBy) {
this.rollupBy = rollupBy;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* The result of a metrics query batch. It contains the results of individual queries.
*/
public final class MetricsBatchQueryResult {
public final class MetricsQueryResourcesResult {
private final List<MetricsQueryResult> metricsQueryResults;

/**
* Creates an instance of MetricsBatchResult.
* @param metricsQueryResults the metrics results for individual queries
*/
public MetricsBatchQueryResult(List<MetricsQueryResult> metricsQueryResults) {
public MetricsQueryResourcesResult(List<MetricsQueryResult> metricsQueryResults) {
this.metricsQueryResults = metricsQueryResults;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.monitor.query.models.MetricResult;
import com.azure.monitor.query.models.MetricsBatchQueryResult;
import com.azure.monitor.query.models.MetricsQueryResourcesResult;
import com.azure.monitor.query.models.MetricsQueryResult;

import java.util.Arrays;
Expand All @@ -26,12 +26,12 @@ public static void main(String[] args) {
.endpoint("https://westus2.monitoring.azure.com")
.buildClient();

MetricsBatchQueryResult metricsBatchQueryResult = metricsBatchQueryClient.queryBatch(
MetricsQueryResourcesResult metricsQueryResourcesResult = metricsBatchQueryClient.queryResources(
Arrays.asList("{resourceId1}", "{resourceId2}"),
Arrays.asList("{metric1}", "{metric2}"),
"{metricNamespace}");

for (MetricsQueryResult metricsQueryResult : metricsBatchQueryResult.getMetricsQueryResults()) {
for (MetricsQueryResult metricsQueryResult : metricsQueryResourcesResult.getMetricsQueryResults()) {
// Each MetricsQueryResult corresponds to one of the resourceIds in the batch request.
List<MetricResult> metrics = metricsQueryResult.getMetrics();
metrics.forEach(metric -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.azure.monitor.query.models.LogsTableRow;
import com.azure.monitor.query.models.MetricResult;
import com.azure.monitor.query.models.MetricValue;
import com.azure.monitor.query.models.MetricsBatchQueryResult;
import com.azure.monitor.query.models.MetricsQueryResourcesResult;
import com.azure.monitor.query.models.MetricsQueryOptions;
import com.azure.monitor.query.models.MetricsQueryResult;
import com.azure.monitor.query.models.QueryTimeInterval;
Expand Down Expand Up @@ -453,12 +453,12 @@ public void getMetricsBatch() {
.endpoint("{endpoint}")
.buildClient();

MetricsBatchQueryResult metricsBatchQueryResult = metricsBatchQueryClient.queryBatch(
MetricsQueryResourcesResult metricsQueryResourcesResult = metricsBatchQueryClient.queryResources(
Arrays.asList("{resourceId1}", "{resourceId2}"),
Arrays.asList("{metric1}", "{metric2}"),
"{metricNamespace}");

for (MetricsQueryResult metricsQueryResult : metricsBatchQueryResult.getMetricsQueryResults()) {
for (MetricsQueryResult metricsQueryResult : metricsQueryResourcesResult.getMetricsQueryResults()) {
// Each MetricsQueryResult corresponds to one of the resourceIds in the batch request.
List<MetricResult> metrics = metricsQueryResult.getMetrics();
metrics.forEach(metric -> {
Expand Down
Loading