Skip to content

Commit a9d4719

Browse files
authored
Rename query APIs (Azure#24523)
1 parent 6bb5653 commit a9d4719

32 files changed

+235
-256
lines changed

sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsBatchQueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public LogsBatchQueryTest(PerfStressOptions options) {
3434
@Override
3535
public void run() {
3636
LogsBatchQuery batchQuery = new LogsBatchQuery();
37-
LOGS_BATCH_QUERIES.forEach(query -> batchQuery.addQuery(workspaceId, query, null));
37+
LOGS_BATCH_QUERIES.forEach(query -> batchQuery.addWorkspaceQuery(workspaceId, query, null));
3838
logsQueryClient.queryBatch(batchQuery);
3939
}
4040

4141
@Override
4242
public Mono<Void> runAsync() {
4343
LogsBatchQuery batchQuery = new LogsBatchQuery();
44-
LOGS_BATCH_QUERIES.forEach(query -> batchQuery.addQuery(workspaceId, query, null));
44+
LOGS_BATCH_QUERIES.forEach(query -> batchQuery.addWorkspaceQuery(workspaceId, query, null));
4545
return logsQueryAsyncClient.queryBatch(batchQuery).then();
4646
}
4747
}

sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryAsModelTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public LogsQueryAsModelTest(PerfStressOptions options) {
2929

3030
@Override
3131
public void run() {
32-
logsQueryClient.query(workspaceId, LOGS_QUERY, null, CustomModel.class);
32+
logsQueryClient.queryWorkspace(workspaceId, LOGS_QUERY, null, CustomModel.class);
3333
}
3434

3535
@Override
3636
public Mono<Void> runAsync() {
37-
return logsQueryAsyncClient.query(workspaceId, LOGS_QUERY, null, CustomModel.class).then();
37+
return logsQueryAsyncClient.queryWorkspace(workspaceId, LOGS_QUERY, null, CustomModel.class).then();
3838
}
3939
}

sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public LogsQueryTest(PerfStressOptions options) {
3030

3131
@Override
3232
public void run() {
33-
logsQueryClient.query(workspaceId, LOGS_QUERY, null);
33+
logsQueryClient.queryWorkspace(workspaceId, LOGS_QUERY, null);
3434
}
3535

3636
@Override
3737
public Mono<Void> runAsync() {
38-
return logsQueryAsyncClient.query(workspaceId, LOGS_QUERY, null).then();
38+
return logsQueryAsyncClient.queryWorkspace(workspaceId, LOGS_QUERY, null).then();
3939
}
4040
}

sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/MetricsQueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public MetricsQueryTest(PerfStressOptions options) {
3333

3434
@Override
3535
public void run() {
36-
metricsQueryClient.queryWithResponse(resourceId, Arrays.asList("SuccessfulCalls"),
36+
metricsQueryClient.queryResourceWithResponse(resourceId, Arrays.asList("SuccessfulCalls"),
3737
new MetricsQueryOptions().setTop(100), Context.NONE);
3838
}
3939

4040
@Override
4141
public Mono<Void> runAsync() {
42-
return metricsQueryAsyncClient.queryWithResponse(resourceId, Arrays.asList("SuccessfulCalls"),
42+
return metricsQueryAsyncClient.queryResourceWithResponse(resourceId, Arrays.asList("SuccessfulCalls"),
4343
new MetricsQueryOptions().setTop(100)).then();
4444
}
4545
}

sdk/monitor/azure-monitor-query/README.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,44 @@ An authenticated client is required to query Logs or Metrics. The library includ
4444

4545
#### Synchronous clients
4646

47-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L39-L41 -->
47+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L40-L42 -->
4848
```java
49-
public void createLogsClients() {
50-
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
51-
.credential(new DefaultAzureCredentialBuilder().build())
49+
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
50+
.credential(new DefaultAzureCredentialBuilder().build())
51+
.buildClient();
5252
```
5353

5454
### Create Logs query async client
5555

56-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L43-L45 -->
56+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L44-L46 -->
5757
```java
58-
5958
LogsQueryAsyncClient logsQueryAsyncClient = new LogsQueryClientBuilder()
6059
.credential(new DefaultAzureCredentialBuilder().build())
60+
.buildAsyncClient();
6161
```
6262
### Create Metrics query client
6363

64-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L52-L54 -->
64+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L53-L55 -->
6565
```java
66-
public void createMetricsClients() {
67-
MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
68-
.credential(new DefaultAzureCredentialBuilder().build())
66+
MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
67+
.credential(new DefaultAzureCredentialBuilder().build())
68+
.buildClient();
6969
```
7070

7171
#### Asynchronous clients
7272

73-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L43-L45 -->
73+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L44-L46 -->
7474
```java
7575
LogsQueryAsyncClient logsQueryAsyncClient = new LogsQueryClientBuilder()
7676
.credential(new DefaultAzureCredentialBuilder().build())
7777
.buildAsyncClient();
7878
```
7979

80-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L56-L58 -->
80+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L57-L59 -->
8181
```java
82-
8382
MetricsQueryAsyncClient metricsQueryAsyncClient = new MetricsQueryClientBuilder()
8483
.credential(new DefaultAzureCredentialBuilder().build())
84+
.buildAsyncClient();
8585
```
8686

8787
### Execute the query
@@ -120,50 +120,50 @@ Each set of metric values is a time series with the following characteristics:
120120

121121
### Logs query
122122

123-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L65-L74 -->
123+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L66-L75 -->
124124
```java
125-
ic void queryLogs() {
126125
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
127126
.credential(new DefaultAzureCredentialBuilder().build())
128127
.buildClient();
129128

130-
LogsQueryResult queryResults = logsQueryClient.query("{workspace-id}", "{kusto-query}",
129+
LogsQueryResult queryResults = logsQueryClient.queryWorkspace("{workspace-id}", "{kusto-query}",
131130
new QueryTimeInterval(Duration.ofDays(2)));
132131

133132
for (LogsTableRow row : queryResults.getTable().getRows()) {
134133
System.out.println(row.getColumnValue("OperationName") + " " + row.getColumnValue("ResourceGroup"));
134+
}
135135
```
136136

137137
#### Map logs query results to a model
138138

139-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L80-L91 -->
139+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L81-L92 -->
140140
```java
141+
public class CustomLogModel {
142+
private String resourceGroup;
143+
private String operationName;
141144

142-
ic class CustomLogModel {
143-
private String resourceGroup;
144-
private String operationName;
145-
146-
public String getResourceGroup() {
147-
return resourceGroup;
148-
}
145+
public String getResourceGroup() {
146+
return resourceGroup;
147+
}
149148

150-
public String getOperationName() {
151-
return operationName;
149+
public String getOperationName() {
150+
return operationName;
151+
}
152152
}
153153
```
154154

155-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L97-L106 -->
155+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L98-L107 -->
156156
```java
157-
ic void queryLogsAsModel() {
158157
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
159158
.credential(new DefaultAzureCredentialBuilder().build())
160159
.buildClient();
161160

162-
List<CustomLogModel> customLogModels = logsQueryClient.query("{workspace-id}", "{kusto-query}",
161+
List<CustomLogModel> customLogModels = logsQueryClient.queryWorkspace("{workspace-id}", "{kusto-query}",
163162
new QueryTimeInterval(Duration.ofDays(2)), CustomLogModel.class);
164163

165164
for (CustomLogModel customLogModel : customLogModels) {
166165
System.out.println(customLogModel.getOperationName() + " " + customLogModel.getResourceGroup());
166+
}
167167
```
168168

169169
#### Handle logs query response
@@ -189,17 +189,16 @@ LogsQueryResult / LogsBatchQueryResult
189189

190190
### Batch logs query
191191

192-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L113-L138 -->
192+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L114-L139 -->
193193
```java
194-
ic void queryBatch() {
195194
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
196195
.credential(new DefaultAzureCredentialBuilder().build())
197196
.buildClient();
198197

199198
LogsBatchQuery logsBatchQuery = new LogsBatchQuery();
200-
String query1 = logsBatchQuery.addQuery("{workspace-id}", "{query-1}", new QueryTimeInterval(Duration.ofDays(2)));
201-
String query2 = logsBatchQuery.addQuery("{workspace-id}", "{query-2}", new QueryTimeInterval(Duration.ofDays(30)));
202-
String query3 = logsBatchQuery.addQuery("{workspace-id}", "{query-3}", new QueryTimeInterval(Duration.ofDays(10)));
199+
String query1 = logsBatchQuery.addWorkspaceQuery("{workspace-id}", "{query-1}", new QueryTimeInterval(Duration.ofDays(2)));
200+
String query2 = logsBatchQuery.addWorkspaceQuery("{workspace-id}", "{query-2}", new QueryTimeInterval(Duration.ofDays(30)));
201+
String query3 = logsBatchQuery.addWorkspaceQuery("{workspace-id}", "{query-3}", new QueryTimeInterval(Duration.ofDays(10)));
203202

204203
LogsBatchQueryResultCollection batchResults = logsQueryClient
205204
.queryBatchWithResponse(logsBatchQuery, Context.NONE).getValue();
@@ -217,15 +216,15 @@ for (CustomLogModel customLogModel : customLogModels) {
217216
LogsBatchQueryResult query3Result = batchResults.getResult(query3);
218217
if (query3Result.getQueryResultStatus() == LogsQueryResultStatus.FAILURE) {
219218
System.out.println(query3Result.getError().getMessage());
219+
}
220220
```
221221

222222
### Advanced logs query scenarios
223223

224224
#### Set logs query timeout
225225

226-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L146-L155 -->
226+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L147-L156 -->
227227
```java
228-
ic void getLogsWithServerTimeout() {
229228
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
230229
.credential(new DefaultAzureCredentialBuilder().build())
231230
.buildClient();
@@ -234,7 +233,8 @@ LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
234233
LogsQueryOptions options = new LogsQueryOptions()
235234
.setServerTimeout(Duration.ofMinutes(10));
236235

237-
Response<LogsQueryResult> response = logsQueryClient.queryWithResponse("{workspace-id}",
236+
Response<LogsQueryResult> response = logsQueryClient.queryWorkspaceWithResponse("{workspace-id}",
237+
"{kusto-query}", new QueryTimeInterval(Duration.ofDays(2)), options, Context.NONE);
238238
```
239239

240240
#### Query multiple workspaces
@@ -246,17 +246,17 @@ workspace from which it was retrieved. To identify the workspace of a row in the
246246
"TenantId" column in the result table. If this column is not in the table, then you may have to update your query string
247247
to include this column.
248248

249-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L162-L170 -->
249+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L163-L171 -->
250250
```java
251-
ic void getLogsQueryFromMultipleWorkspaces() {
252251
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
253252
.credential(new DefaultAzureCredentialBuilder().build())
254253
.buildClient();
255254

256-
Response<LogsQueryResult> response = logsQueryClient.queryWithResponse("{workspace-id}", "{kusto-query}",
255+
Response<LogsQueryResult> response = logsQueryClient.queryWorkspaceWithResponse("{workspace-id}", "{kusto-query}",
257256
new QueryTimeInterval(Duration.ofDays(2)), new LogsQueryOptions()
258257
.setAdditionalWorkspaces(Arrays.asList("{additional-workspace-identifiers}")),
259258
Context.NONE);
259+
LogsQueryResult result = response.getValue();
260260
```
261261

262262
### Metrics query
@@ -267,14 +267,13 @@ A resource ID, as denoted by the `{resource-id}` placeholder in the sample below
267267
2. From the **Overview** blade, select the **JSON View** link.
268268
3. In the resulting JSON, copy the value of the `id` property.
269269

270-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L178-L193 -->
270+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L179-L194 -->
271271
```java
272-
ic void getMetrics() {
273272
MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
274273
.credential(new DefaultAzureCredentialBuilder().build())
275274
.buildClient();
276275

277-
MetricsQueryResult metricsQueryResult = metricsQueryClient.query("{resource-uri}",
276+
MetricsQueryResult metricsQueryResult = metricsQueryClient.queryResource("{resource-uri}",
278277
Arrays.asList("SuccessfulCalls", "TotalCalls"));
279278

280279
for (MetricResult metric : metricsQueryResult.getMetrics()) {
@@ -285,6 +284,7 @@ for (MetricResult metric : metricsQueryResult.getMetrics()) {
285284
System.out.println(metricValue.getTimeStamp() + " " + metricValue.getTotal());
286285
}
287286
}
287+
}
288288
```
289289

290290
#### Handle metrics query response
@@ -316,15 +316,14 @@ MetricsQueryResult
316316

317317
#### Get average and count metrics
318318

319-
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L200-L221 -->
319+
<!-- embedme ./src/samples/java/com/azure/monitor/query/ReadmeSamples.java#L201-L222 -->
320320
```java
321-
ic void getMetricsWithOptions() {
322321
MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
323322
.credential(new DefaultAzureCredentialBuilder().build())
324323
.buildClient();
325324

326325
Response<MetricsQueryResult> metricsResponse = metricsQueryClient
327-
.queryWithResponse("{resource-id}", Arrays.asList("SuccessfulCalls", "TotalCalls"),
326+
.queryResourceWithResponse("{resource-id}", Arrays.asList("SuccessfulCalls", "TotalCalls"),
328327
new MetricsQueryOptions()
329328
.setGranularity(Duration.ofHours(1))
330329
.setAggregations(Arrays.asList(AggregationType.AVERAGE, AggregationType.COUNT)),
@@ -340,6 +339,7 @@ for (MetricResult metric : metricsQueryResult.getMetrics()) {
340339
System.out.println(metricValue.getTimeStamp() + " " + metricValue.getTotal());
341340
}
342341
}
342+
}
343343
```
344344

345345
## Troubleshooting

sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/LogsQueryAsyncClient.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public final class LogsQueryAsyncClient {
8080
* @return The logs matching the query.
8181
*/
8282
@ServiceMethod(returns = ReturnType.SINGLE)
83-
public Mono<LogsQueryResult> query(String workspaceId, String query, QueryTimeInterval timeInterval) {
84-
return queryWithResponse(workspaceId, query, timeInterval, new LogsQueryOptions())
83+
public Mono<LogsQueryResult> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval) {
84+
return queryWorkspaceWithResponse(workspaceId, query, timeInterval, new LogsQueryOptions())
8585
.map(Response::getValue);
8686
}
8787

@@ -95,8 +95,8 @@ public Mono<LogsQueryResult> query(String workspaceId, String query, QueryTimeIn
9595
* @return The logs matching the query as a list of objects of type T.
9696
*/
9797
@ServiceMethod(returns = ReturnType.SINGLE)
98-
public <T> Mono<List<T>> query(String workspaceId, String query, QueryTimeInterval timeInterval, Class<T> type) {
99-
return query(workspaceId, query, timeInterval)
98+
public <T> Mono<List<T>> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval, Class<T> type) {
99+
return queryWorkspace(workspaceId, query, timeInterval)
100100
.map(result -> LogsQueryHelper.toObject(result.getTable(), type));
101101
}
102102

@@ -111,9 +111,9 @@ public <T> Mono<List<T>> query(String workspaceId, String query, QueryTimeInterv
111111
* @return The logs matching the query as a list of objects of type T.
112112
*/
113113
@ServiceMethod(returns = ReturnType.SINGLE)
114-
public <T> Mono<List<T>> query(String workspaceId, String query, QueryTimeInterval timeInterval,
115-
Class<T> type, LogsQueryOptions options) {
116-
return queryWithResponse(workspaceId, query, timeInterval, options, Context.NONE)
114+
public <T> Mono<List<T>> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval,
115+
Class<T> type, LogsQueryOptions options) {
116+
return queryWorkspaceWithResponse(workspaceId, query, timeInterval, options, Context.NONE)
117117
.map(response -> LogsQueryHelper.toObject(response.getValue().getTable(), type));
118118
}
119119

@@ -132,9 +132,9 @@ public <T> Mono<List<T>> query(String workspaceId, String query, QueryTimeInterv
132132
* @return The logs matching the query.
133133
*/
134134
@ServiceMethod(returns = ReturnType.SINGLE)
135-
public Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String query,
136-
QueryTimeInterval timeInterval, LogsQueryOptions options) {
137-
return withContext(context -> queryWithResponse(workspaceId, query, timeInterval, options, context));
135+
public Mono<Response<LogsQueryResult>> queryWorkspaceWithResponse(String workspaceId, String query,
136+
QueryTimeInterval timeInterval, LogsQueryOptions options) {
137+
return withContext(context -> queryWorkspaceWithResponse(workspaceId, query, timeInterval, options, context));
138138
}
139139

140140
/**
@@ -150,9 +150,9 @@ public Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, Str
150150
* @return The logs matching the query including the HTTP response.
151151
*/
152152
@ServiceMethod(returns = ReturnType.SINGLE)
153-
public <T> Mono<Response<List<T>>> queryWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval,
154-
Class<T> type, LogsQueryOptions options) {
155-
return queryWithResponse(workspaceId, query, timeInterval, options)
153+
public <T> Mono<Response<List<T>>> queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval,
154+
Class<T> type, LogsQueryOptions options) {
155+
return queryWorkspaceWithResponse(workspaceId, query, timeInterval, options)
156156
.map(response -> new SimpleResponse<>(response.getRequest(),
157157
response.getStatusCode(), response.getHeaders(),
158158
LogsQueryHelper.toObject(response.getValue().getTable(), type)));
@@ -169,7 +169,7 @@ public <T> Mono<Response<List<T>>> queryWithResponse(String workspaceId, String
169169
Mono<LogsBatchQueryResultCollection> queryBatch(String workspaceId, List<String> queries,
170170
QueryTimeInterval timeInterval) {
171171
LogsBatchQuery logsBatchQuery = new LogsBatchQuery();
172-
queries.forEach(query -> logsBatchQuery.addQuery(workspaceId, query, timeInterval));
172+
queries.forEach(query -> logsBatchQuery.addWorkspaceQuery(workspaceId, query, timeInterval));
173173
return queryBatchWithResponse(logsBatchQuery).map(Response::getValue);
174174
}
175175

@@ -266,8 +266,8 @@ private ResponseError mapLogsQueryError(ErrorInfo errors) {
266266
return null;
267267
}
268268

269-
Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval,
270-
LogsQueryOptions options, Context context) {
269+
Mono<Response<LogsQueryResult>> queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval,
270+
LogsQueryOptions options, Context context) {
271271
String preferHeader = LogsQueryHelper.buildPreferHeaderString(options);
272272
context = updateContext(options.getServerTimeout(), context);
273273

0 commit comments

Comments
 (0)