Skip to content

Commit 1340cb6

Browse files
authored
Fix max server timeout for batch queries (Azure#29347)
* Fix max server timeout for batch queries * update changelog
1 parent 4899849 commit 1340cb6

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Release History
22

3-
## 1.0.7 (2022-06-07)
3+
## 1.0.7 (2022-06-09)
44

55
### Bugs Fixed
66

77
- Fixed bug where partial queries fail when `LogsQueryOptions.setAllowPartialErrors(true)`.
8+
- [Fixed bug that causes `NullPointerException` when batch queries have server timeout configured.](https://github.com/Azure/azure-sdk-for-java/issues/29339)
89

910
### Other Changes
1011

sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/LogsBatchQuery.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public String addWorkspaceQuery(String workspaceId, String query, QueryTimeInter
7272

7373
String preferHeader = buildPreferHeaderString(logsQueryOptions);
7474
if (logsQueryOptions != null && logsQueryOptions.getServerTimeout() != null) {
75-
if (logsQueryOptions.getServerTimeout().compareTo(this.maxServerTimeout) > 0) {
75+
// Set the server timeout to max server timeout among all the queries in the batch
76+
if (maxServerTimeout == null || logsQueryOptions.getServerTimeout().compareTo(maxServerTimeout) > 0) {
7677
maxServerTimeout = logsQueryOptions.getServerTimeout();
7778
}
7879
}

sdk/monitor/azure-monitor-query/src/test/java/com/azure/monitor/query/LogsQueryClientTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,35 @@ public void testLogsQueryBatch() {
154154
assertEquals(3, responses.get(1).getAllTables().get(0).getRows().size());
155155
}
156156

157+
@Test
158+
public void testLogsQueryBatchWithServerTimeout() {
159+
LogsBatchQuery logsBatchQuery = new LogsBatchQuery();
160+
logsBatchQuery.addWorkspaceQuery(WORKSPACE_ID, QUERY_STRING + " | take 2", null);
161+
logsBatchQuery.addWorkspaceQuery(WORKSPACE_ID, QUERY_STRING + " | take 5", null,
162+
new LogsQueryOptions().setServerTimeout(Duration.ofSeconds(20)));
163+
logsBatchQuery.addWorkspaceQuery(WORKSPACE_ID, QUERY_STRING + "| take 3", null,
164+
new LogsQueryOptions().setServerTimeout(Duration.ofSeconds(10)));
165+
166+
LogsBatchQueryResultCollection batchResultCollection = client
167+
.queryBatchWithResponse(logsBatchQuery, Context.NONE).getValue();
168+
169+
List<LogsBatchQueryResult> responses = batchResultCollection.getBatchResults();
170+
171+
assertEquals(3, responses.size());
172+
173+
assertEquals(1, responses.get(0).getAllTables().size());
174+
assertEquals(24, responses.get(0).getAllTables().get(0).getAllTableCells().size());
175+
assertEquals(2, responses.get(0).getAllTables().get(0).getRows().size());
176+
177+
assertEquals(1, responses.get(1).getAllTables().size());
178+
assertEquals(60, responses.get(1).getAllTables().get(0).getAllTableCells().size());
179+
assertEquals(5, responses.get(1).getAllTables().get(0).getRows().size());
180+
181+
assertEquals(1, responses.get(2).getAllTables().size());
182+
assertEquals(36, responses.get(2).getAllTables().get(0).getAllTableCells().size());
183+
assertEquals(3, responses.get(2).getAllTables().get(0).getRows().size());
184+
}
185+
157186
@Test
158187
@DisabledIfEnvironmentVariable(named = "AZURE_TEST_MODE", matches = "LIVE", disabledReason = "multi-workspace "
159188
+ "queries require sending logs to Azure Monitor first. So, run this test in playback or record mode only.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"networkCallRecords" : [ {
3+
"Method" : "POST",
4+
"Uri" : "https://REDACTED.loganalytics.io/v1/$batch",
5+
"Headers" : {
6+
"User-Agent" : "azsdk-java-azure-monitor-query/1.0.7 (17.0.2; Windows 10; 10.0)",
7+
"Content-Type" : "application/json"
8+
},
9+
"Response" : {
10+
"Transfer-Encoding" : "chunked",
11+
"Access-Control-Allow-Origin" : "*",
12+
"X-Content-Type-Options" : "nosniff",
13+
"Connection" : "keep-alive",
14+
"retry-after" : "0",
15+
"StatusCode" : "200",
16+
"Date" : "Thu, 09 Jun 2022 19:19:48 GMT",
17+
"via" : "1.1 draft-oms-6d895847bd-fk545",
18+
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
19+
"Access-Control-Expose-Headers" : "Retry-After,Age,WWW-Authenticate,x-resource-identities,x-ms-status-location",
20+
"Vary" : "Accept-Encoding,Accept-Encoding",
21+
"Body" : "{\"responses\":[{\"id\":\"2\",\"status\":200,\"headers\":{\"Preference-Applied\":\"wait=20\",\"request-context\":\"appId=cid-v1:70941e4f-7e8f-40b7-b730-183893db0297\"},\"body\":{\"tables\":[{\"name\":\"PrimaryResult\",\"columns\":[{\"name\":\"x\",\"type\":\"long\"},{\"name\":\"y\",\"type\":\"long\"},{\"name\":\"DateTime\",\"type\":\"datetime\"},{\"name\":\"Bool\",\"type\":\"bool\"},{\"name\":\"Guid\",\"type\":\"guid\"},{\"name\":\"Int\",\"type\":\"int\"},{\"name\":\"Long\",\"type\":\"long\"},{\"name\":\"Double\",\"type\":\"real\"},{\"name\":\"String\",\"type\":\"string\"},{\"name\":\"Timespan\",\"type\":\"timespan\"},{\"name\":\"Decimal\",\"type\":\"decimal\"},{\"name\":\"Dynamic\",\"type\":\"dynamic\"}],\"rows\":[[100,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[99,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[98,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[97,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[96,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"]]}]}},{\"id\":\"3\",\"status\":200,\"headers\":{\"Preference-Applied\":\"wait=10\",\"request-context\":\"appId=cid-v1:70941e4f-7e8f-40b7-b730-183893db0297\"},\"body\":{\"tables\":[{\"name\":\"PrimaryResult\",\"columns\":[{\"name\":\"x\",\"type\":\"long\"},{\"name\":\"y\",\"type\":\"long\"},{\"name\":\"DateTime\",\"type\":\"datetime\"},{\"name\":\"Bool\",\"type\":\"bool\"},{\"name\":\"Guid\",\"type\":\"guid\"},{\"name\":\"Int\",\"type\":\"int\"},{\"name\":\"Long\",\"type\":\"long\"},{\"name\":\"Double\",\"type\":\"real\"},{\"name\":\"String\",\"type\":\"string\"},{\"name\":\"Timespan\",\"type\":\"timespan\"},{\"name\":\"Decimal\",\"type\":\"decimal\"},{\"name\":\"Dynamic\",\"type\":\"dynamic\"}],\"rows\":[[100,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[99,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[98,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"]]}]}},{\"id\":\"1\",\"status\":200,\"body\":{\"tables\":[{\"name\":\"PrimaryResult\",\"columns\":[{\"name\":\"x\",\"type\":\"long\"},{\"name\":\"y\",\"type\":\"long\"},{\"name\":\"DateTime\",\"type\":\"datetime\"},{\"name\":\"Bool\",\"type\":\"bool\"},{\"name\":\"Guid\",\"type\":\"guid\"},{\"name\":\"Int\",\"type\":\"int\"},{\"name\":\"Long\",\"type\":\"long\"},{\"name\":\"Double\",\"type\":\"real\"},{\"name\":\"String\",\"type\":\"string\"},{\"name\":\"Timespan\",\"type\":\"timespan\"},{\"name\":\"Decimal\",\"type\":\"decimal\"},{\"name\":\"Dynamic\",\"type\":\"dynamic\"}],\"rows\":[[100,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"],[99,1,\"2015-12-31T23:59:59.9Z\",false,\"74be27de-1e4e-49d9-b579-fe0b331d3642\",12345,1,12345.6789,\"string value\",\"00:00:10\",\"0.10101\",\"{\\\"a\\\":123,\\\"b\\\":\\\"hello\\\",\\\"c\\\":[1,2,3],\\\"d\\\":{}}\"]]}]}}]}",
22+
"Content-Type" : "application/json; charset=utf-8"
23+
},
24+
"Exception" : null
25+
} ],
26+
"variables" : [ ]
27+
}

0 commit comments

Comments
 (0)