Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API consistency review updates #24130

Merged
merged 5 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions sdk/monitor/azure-monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
.buildClient();

LogsQueryResult queryResults = logsQueryClient.query("{workspace-id}", "{kusto-query}",
new TimeInterval(Duration.ofDays(2)));
new MonitorQueryTimeInterval(Duration.ofDays(2)));

for (LogsTableRow row : queryResults.getTable().getRows()) {
System.out.println(row.getColumnValue("OperationName") + " " + row.getColumnValue("ResourceGroup"));
Expand Down Expand Up @@ -186,7 +186,7 @@ LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
.buildClient();

List<CustomLogModel> customLogModels = logsQueryClient.query("{workspace-id}", "{kusto-query}",
new TimeInterval(Duration.ofDays(2)), CustomLogModel.class);
new MonitorQueryTimeInterval(Duration.ofDays(2)), CustomLogModel.class);

for (CustomLogModel customLogModel : customLogModels) {
System.out.println(customLogModel.getOperationName() + " " + customLogModel.getResourceGroup());
Expand All @@ -201,9 +201,9 @@ LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
.buildClient();

LogsBatchQuery logsBatchQuery = new LogsBatchQuery();
String query1 = logsBatchQuery.addQuery("{workspace-id}", "{query-1}", new TimeInterval(Duration.ofDays(2)));
String query2 = logsBatchQuery.addQuery("{workspace-id}", "{query-2}", new TimeInterval(Duration.ofDays(30)));
String query3 = logsBatchQuery.addQuery("{workspace-id}", "{query-3}", new TimeInterval(Duration.ofDays(10)));
String query1 = logsBatchQuery.addQuery("{workspace-id}", "{query-1}", new MonitorQueryTimeInterval(Duration.ofDays(2)));
String query2 = logsBatchQuery.addQuery("{workspace-id}", "{query-2}", new MonitorQueryTimeInterval(Duration.ofDays(30)));
String query3 = logsBatchQuery.addQuery("{workspace-id}", "{query-3}", new MonitorQueryTimeInterval(Duration.ofDays(10)));

LogsBatchQueryResultCollection batchResults = logsQueryClient
.queryBatchWithResponse(logsBatchQuery, Context.NONE).getValue();
Expand Down Expand Up @@ -237,7 +237,7 @@ LogsQueryOptions options = new LogsQueryOptions()
.setServerTimeout(Duration.ofMinutes(10));

Response<LogsQueryResult> response = logsQueryClient.queryWithResponse("{workspace-id}",
"{kusto-query}", new TimeInterval(Duration.ofDays(2)), options, Context.NONE);
"{kusto-query}", new MonitorQueryTimeInterval(Duration.ofDays(2)), options, Context.NONE);
```

### Get logs from multiple workspaces
Expand All @@ -254,7 +254,7 @@ LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
.buildClient();

Response<LogsQueryResult> response = logsQueryClient.queryWithResponse("{workspace-id}", "{kusto-query}",
new TimeInterval(Duration.ofDays(2)), new LogsQueryOptions()
new MonitorQueryTimeInterval(Duration.ofDays(2)), new LogsQueryOptions()
.setAdditionalWorkspaces(Arrays.asList("{additional-workspace-identifiers}")),
Context.NONE);
LogsQueryResult result = response.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ServiceResponseException;
import com.azure.core.experimental.models.HttpResponseError;
import com.azure.core.experimental.models.TimeInterval;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.BinaryData;
Expand All @@ -31,11 +31,14 @@
import com.azure.monitor.query.models.LogsBatchQueryResultCollection;
import com.azure.monitor.query.models.LogsQueryOptions;
import com.azure.monitor.query.models.LogsQueryResult;
import com.azure.monitor.query.models.LogsQueryResultStatus;
import com.azure.monitor.query.models.LogsTable;
import com.azure.monitor.query.models.LogsTableCell;
import com.azure.monitor.query.models.LogsTableColumn;
import com.azure.monitor.query.models.LogsTableRow;
import com.azure.monitor.query.models.MonitorQueryTimeInterval;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SynchronousSink;

import java.time.Duration;
import java.util.ArrayList;
Expand Down Expand Up @@ -69,15 +72,15 @@ public final class LogsQueryAsyncClient {
* Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
*
* <p><strong>Query logs from the last 24 hours</strong></p>
* {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.query#String-String-TimeInterval}
* {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.query#String-String-MonitorQueryTimeInterval}
*
* @param workspaceId The workspaceId where the query should be executed.
* @param query The Kusto query to fetch the logs.
* @param timeInterval The time period for which the logs should be looked up.
* @return The logs matching the query.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<LogsQueryResult> query(String workspaceId, String query, TimeInterval timeInterval) {
public Mono<LogsQueryResult> query(String workspaceId, String query, MonitorQueryTimeInterval timeInterval) {
return queryWithResponse(workspaceId, query, timeInterval, new LogsQueryOptions())
.map(Response::getValue);
}
Expand All @@ -92,7 +95,7 @@ public Mono<LogsQueryResult> query(String workspaceId, String query, TimeInterva
* @return The logs matching the query as a list of objects of type T.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval timeInterval, Class<T> type) {
public <T> Mono<List<T>> query(String workspaceId, String query, MonitorQueryTimeInterval timeInterval, Class<T> type) {
return query(workspaceId, query, timeInterval)
.map(result -> LogsQueryHelper.toObject(result.getTable(), type));
}
Expand All @@ -108,7 +111,7 @@ public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval ti
* @return The logs matching the query as a list of objects of type T.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval timeInterval,
public <T> Mono<List<T>> query(String workspaceId, String query, MonitorQueryTimeInterval timeInterval,
Class<T> type, LogsQueryOptions options) {
return queryWithResponse(workspaceId, query, timeInterval, options, Context.NONE)
.map(response -> LogsQueryHelper.toObject(response.getValue().getTable(), type));
Expand All @@ -119,7 +122,7 @@ public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval ti
*
* <p><strong>Query logs from the last 7 days and set the service timeout to 2 minutes</strong></p>
*
* {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.queryWithResponse#String-String-TimeInterval-LogsQueryOptions}
* {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.queryWithResponse#String-String-MonitorQueryTimeInterval-LogsQueryOptions}
*
* @param workspaceId The workspaceId where the query should be executed.
* @param query The Kusto query to fetch the logs.
Expand All @@ -130,7 +133,7 @@ public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval ti
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String query,
TimeInterval timeInterval, LogsQueryOptions options) {
MonitorQueryTimeInterval timeInterval, LogsQueryOptions options) {
return withContext(context -> queryWithResponse(workspaceId, query, timeInterval, options, context));
}

Expand All @@ -147,7 +150,7 @@ public Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, Str
* @return The logs matching the query including the HTTP response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<Response<List<T>>> queryWithResponse(String workspaceId, String query, TimeInterval timeInterval,
public <T> Mono<Response<List<T>>> queryWithResponse(String workspaceId, String query, MonitorQueryTimeInterval timeInterval,
Class<T> type, LogsQueryOptions options) {
return queryWithResponse(workspaceId, query, timeInterval, options)
.map(response -> new SimpleResponse<>(response.getRequest(),
Expand All @@ -164,7 +167,7 @@ public <T> Mono<Response<List<T>>> queryWithResponse(String workspaceId, String
* @return A collection of query results corresponding to the input batch of queries.
*/
Mono<LogsBatchQueryResultCollection> queryBatch(String workspaceId, List<String> queries,
TimeInterval timeInterval) {
MonitorQueryTimeInterval timeInterval) {
LogsBatchQuery logsBatchQuery = new LogsBatchQuery();
queries.forEach(query -> logsBatchQuery.addQuery(workspaceId, query, timeInterval));
return queryBatchWithResponse(logsBatchQuery).map(Response::getValue);
Expand Down Expand Up @@ -263,14 +266,14 @@ private HttpResponseError mapLogsQueryError(ErrorInfo errors) {
return null;
}

Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String query, TimeInterval timeInterval,
Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String query, MonitorQueryTimeInterval timeInterval,
LogsQueryOptions options, Context context) {
String preferHeader = LogsQueryHelper.buildPreferHeaderString(options);
context = updateContext(options.getServerTimeout(), context);

QueryBody queryBody = new QueryBody(query);
if (timeInterval != null) {
queryBody.setTimespan(timeInterval.toIso8601Format());
queryBody.setTimespan(LogsQueryHelper.toIso8601Format(timeInterval));
}
queryBody.setWorkspaces(getAllWorkspaces(options));
return innerClient
Expand All @@ -288,7 +291,16 @@ Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String que
}
return ex;
})
.map(this::convertToLogQueryResult);
.map(this::convertToLogQueryResult)
.handle((Response<LogsQueryResult> response, SynchronousSink<Response<LogsQueryResult>> sink) -> {
if (response.getValue().getQueryResultStatus() == LogsQueryResultStatus.PARTIAL_FAILURE) {
sink.error(new ServiceResponseException("Query execution returned partial errors. To "
+ "disable exceptions on partial errors, set disableExceptionOnPartialErrors in "
+ "LogsQueryOptions to true."));
} else {
sink.next(response);
}
});
}

private Response<LogsQueryResult> convertToLogQueryResult(Response<QueryResults> response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.experimental.models.TimeInterval;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
Expand All @@ -15,6 +14,7 @@
import com.azure.monitor.query.models.LogsBatchQueryResultCollection;
import com.azure.monitor.query.models.LogsQueryOptions;
import com.azure.monitor.query.models.LogsQueryResult;
import com.azure.monitor.query.models.MonitorQueryTimeInterval;

import java.util.List;

Expand Down Expand Up @@ -43,14 +43,14 @@ public final class LogsQueryClient {
*
* <p><strong>Query logs from the last 24 hours</strong></p>
*
* {@codesnippet com.azure.monitor.query.LogsQueryClient.query#String-String-TimeInterval}
* {@codesnippet com.azure.monitor.query.LogsQueryClient.query#String-String-MonitorQueryTimeInterval}
* @param workspaceId The workspaceId where the query should be executed.
* @param query The Kusto query to fetch the logs.
* @param timeInterval The time period for which the logs should be looked up.
* @return The logs matching the query.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public LogsQueryResult query(String workspaceId, String query, TimeInterval timeInterval) {
public LogsQueryResult query(String workspaceId, String query, MonitorQueryTimeInterval timeInterval) {
return asyncClient.query(workspaceId, query, timeInterval).block();
}

Expand All @@ -64,7 +64,7 @@ public LogsQueryResult query(String workspaceId, String query, TimeInterval time
* @return The logs matching the query as a list of objects of type T.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> List<T> query(String workspaceId, String query, TimeInterval timeInterval, Class<T> type) {
public <T> List<T> query(String workspaceId, String query, MonitorQueryTimeInterval timeInterval, Class<T> type) {
LogsQueryResult logsQueryResult = asyncClient.query(workspaceId, query, timeInterval).block();
if (logsQueryResult != null) {
return LogsQueryHelper.toObject(logsQueryResult.getTable(), type);
Expand All @@ -84,7 +84,7 @@ public <T> List<T> query(String workspaceId, String query, TimeInterval timeInte
* @return The logs matching the query as a list of objects of type T.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> List<T> query(String workspaceId, String query, TimeInterval timeInterval,
public <T> List<T> query(String workspaceId, String query, MonitorQueryTimeInterval timeInterval,
Class<T> type, LogsQueryOptions options) {
LogsQueryResult logsQueryResult = queryWithResponse(workspaceId, query, timeInterval, options, Context.NONE)
.getValue();
Expand All @@ -99,7 +99,7 @@ public <T> List<T> query(String workspaceId, String query, TimeInterval timeInte
*
* <p><strong>Query logs from the last 7 days and set the service timeout to 2 minutes</strong></p>
*
* {@codesnippet com.azure.monitor.query.LogsQueryClient.queryWithResponse#String-String-TimeInterval-LogsQueryOptions-Context}
* {@codesnippet com.azure.monitor.query.LogsQueryClient.queryWithResponse#String-String-MonitorQueryTimeInterval-LogsQueryOptions-Context}
* @param workspaceId The workspaceId where the query should be executed.
* @param query The Kusto query to fetch the logs.
* @param timeInterval The time period for which the logs should be looked up.
Expand All @@ -110,7 +110,7 @@ public <T> List<T> query(String workspaceId, String query, TimeInterval timeInte
* @return The logs matching the query including the HTTP response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<LogsQueryResult> queryWithResponse(String workspaceId, String query, TimeInterval timeInterval,
public Response<LogsQueryResult> queryWithResponse(String workspaceId, String query, MonitorQueryTimeInterval timeInterval,
LogsQueryOptions options, Context context) {
return asyncClient.queryWithResponse(workspaceId, query, timeInterval, options, context).block();
}
Expand All @@ -130,7 +130,7 @@ public Response<LogsQueryResult> queryWithResponse(String workspaceId, String qu
* @return The logs matching the query including the HTTP response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Response<List<T>> queryWithResponse(String workspaceId, String query, TimeInterval timeInterval,
public <T> Response<List<T>> queryWithResponse(String workspaceId, String query, MonitorQueryTimeInterval timeInterval,
Class<T> type, LogsQueryOptions options, Context context) {
return asyncClient.queryWithResponse(workspaceId, query, timeInterval, options, context)
.map(response -> new SimpleResponse<>(response.getRequest(),
Expand All @@ -146,7 +146,7 @@ public <T> Response<List<T>> queryWithResponse(String workspaceId, String query,
* @param timeInterval The time period for which the logs should be looked up.
* @return A collection of query results corresponding to the input batch of queries.
*/
LogsBatchQueryResultCollection queryBatch(String workspaceId, List<String> queries, TimeInterval timeInterval) {
LogsBatchQueryResultCollection queryBatch(String workspaceId, List<String> queries, MonitorQueryTimeInterval timeInterval) {
return asyncClient.queryBatch(workspaceId, queries, timeInterval).block();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.experimental.models.HttpResponseError;
import com.azure.core.experimental.models.TimeInterval;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.monitor.query.implementation.logs.models.LogsQueryHelper;
import com.azure.monitor.query.implementation.metrics.models.Metric;
import com.azure.monitor.query.implementation.metrics.MonitorManagementClientImpl;
import com.azure.monitor.query.implementation.metrics.models.MetadataValue;
Expand All @@ -28,6 +28,7 @@
import com.azure.monitor.query.models.MetricNamespace;
import com.azure.monitor.query.models.MetricsQueryOptions;
import com.azure.monitor.query.models.MetricsQueryResult;
import com.azure.monitor.query.models.MonitorQueryTimeInterval;
import com.azure.monitor.query.models.TimeSeriesElement;
import com.azure.monitor.query.models.MetricValue;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -189,7 +190,8 @@ Mono<Response<MetricsQueryResult>> queryWithResponse(String resourceUri, List<St
.map(type -> String.valueOf(type.ordinal()))
.collect(Collectors.joining(","));
}
String timespan = options.getTimeInterval() == null ? null : options.getTimeInterval().toIso8601Format();
String timespan = options.getTimeInterval() == null ? null
: LogsQueryHelper.toIso8601Format(options.getTimeInterval());
return metricsClient
.getMetrics()
.listWithResponseAsync(resourceUri, timespan, options.getGranularity(),
Expand All @@ -202,7 +204,7 @@ private Response<MetricsQueryResult> convertToMetricsQueryResult(Response<Metric
MetricsResponse metricsResponse = response.getValue();
MetricsQueryResult metricsQueryResult = new MetricsQueryResult(
metricsResponse.getCost(),
metricsResponse.getTimespan() == null ? null : TimeInterval.parse(metricsResponse.getTimespan()),
metricsResponse.getTimespan() == null ? null : MonitorQueryTimeInterval.parse(metricsResponse.getTimespan()),
metricsResponse.getInterval(),
metricsResponse.getNamespace(), metricsResponse.getResourceregion(), mapMetrics(metricsResponse.getValue()));

Expand Down
Loading