Skip to content

Commit 20e1234

Browse files
authored
[monitor-query] Update samples to use 10-minute server timeout (Azure#23055)
1 parent 298ceb1 commit 20e1234

File tree

12 files changed

+40
-36
lines changed

12 files changed

+40
-36
lines changed

sdk/monitor/monitor-query/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ For information on request throttling at the Log Analytics service level, see [R
376376

377377
#### Set logs query timeout
378378

379-
Some logs queries take longer than 3 minutes to execute. The default server timeout is 3 minutes. You can increase the server timeout to a maximum of 10 minutes. In the following example, the `LogsQueryOptions` object's `serverTimeoutInSeconds` property is used to decrease the server timeout to 1 minute:
379+
Some logs queries take longer than 3 minutes to execute. The default server timeout is 3 minutes. You can increase the server timeout to a maximum of 10 minutes. In the following example, the `LogsQueryOptions` object's `serverTimeoutInSeconds` property is used to increase the server timeout to 10 minutes:
380380

381381
```ts
382382
// setting optional parameters
383383
const queryLogsOptions: LogsQueryOptions = {
384384
// explicitly control the amount of time the server can spend processing the query.
385-
serverTimeoutInSeconds: 60
385+
serverTimeoutInSeconds: 600 // 600 seconds = 10 minutes
386386
};
387387

388388
const result = await logsQueryClient.queryWorkspace(

sdk/monitor/monitor-query/samples-dev/logsQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function main() {
3232
console.log(`Running '${kustoQuery}' over the last One Hour`);
3333
const queryLogsOptions: LogsQueryOptions = {
3434
// explicitly control the amount of time the server can spend processing the query.
35-
serverTimeoutInSeconds: 60,
35+
serverTimeoutInSeconds: 600, // sets the timeout to 10 minutes
3636
// optionally enable returning additional statistics about the query's execution.
3737
// (by default this is off)
3838
includeQueryStatistics: true,

sdk/monitor/monitor-query/samples-dev/logsQueryMultipleWorkspaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function main() {
3434
console.log(`Running '${kustoQuery}' over the last 5 minutes`);
3535
const queryLogsOptions: LogsQueryOptions = {
3636
// explicitly control the amount of time the server can spend processing the query.
37-
serverTimeoutInSeconds: 60,
37+
serverTimeoutInSeconds: 600, // sets the timeout to 10 minutes
3838
// optionally enable returning additional statistics about the query's execution.
3939
// (by default this is off)
4040
includeQueryStatistics: true,

sdk/monitor/monitor-query/samples/v1/javascript/logsQuery.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
const { DefaultAzureCredential } = require("@azure/identity");
99
const { Durations, LogsQueryClient, LogsQueryResultStatus } = require("@azure/monitor-query");
10-
const dotenv = require("dotenv");
11-
dotenv.config();
10+
require("dotenv").config();
1211

1312
const monitorWorkspaceId = process.env.MONITOR_WORKSPACE_ID;
1413

@@ -26,10 +25,10 @@ async function main() {
2625
console.log(`Running '${kustoQuery}' over the last One Hour`);
2726
const queryLogsOptions = {
2827
// explicitly control the amount of time the server can spend processing the query.
29-
serverTimeoutInSeconds: 60,
28+
serverTimeoutInSeconds: 600,
3029
// optionally enable returning additional statistics about the query's execution.
3130
// (by default this is off)
32-
includeQueryStatistics: true
31+
includeQueryStatistics: true,
3332
};
3433

3534
const result = await logsQueryClient.queryWorkspace(
@@ -86,3 +85,5 @@ main().catch((err) => {
8685
console.error("The sample encountered an error:", err);
8786
process.exit(1);
8887
});
88+
89+
module.exports = { main };

sdk/monitor/monitor-query/samples/v1/javascript/logsQueryBatch.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
const { DefaultAzureCredential } = require("@azure/identity");
99
const { LogsQueryClient, LogsQueryResultStatus } = require("@azure/monitor-query");
10-
const dotenv = require("dotenv");
11-
dotenv.config();
10+
require("dotenv").config();
1211

1312
const monitorWorkspaceId = process.env.MONITOR_WORKSPACE_ID;
1413

@@ -25,25 +24,25 @@ async function main() {
2524
{
2625
workspaceId: monitorWorkspaceId,
2726
query: kqlQuery,
28-
timespan: { duration: "P1D" }
27+
timespan: { duration: "P1D" },
2928
},
3029
{
3130
workspaceId: monitorWorkspaceId,
3231
query: "AzureActivity | summarize count()",
33-
timespan: { duration: "PT1H" }
32+
timespan: { duration: "PT1H" },
3433
},
3534
{
3635
workspaceId: monitorWorkspaceId,
3736
query:
3837
"AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId",
39-
timespan: { duration: "PT1H" }
38+
timespan: { duration: "PT1H" },
4039
},
4140
{
4241
workspaceId: monitorWorkspaceId,
4342
query: "AppRequests | take 2",
4443
timespan: { duration: "PT1H" },
45-
includeQueryStatistics: true
46-
}
44+
includeQueryStatistics: true,
45+
},
4746
];
4847

4948
const result = await logsQueryClient.queryBatch(queriesBatch);
@@ -94,3 +93,5 @@ main().catch((err) => {
9493
console.error("The sample encountered an error:", err);
9594
process.exit(1);
9695
});
96+
97+
module.exports = { main };

sdk/monitor/monitor-query/samples/v1/javascript/logsQueryMultipleWorkspaces.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
const { DefaultAzureCredential } = require("@azure/identity");
99
const { Durations, LogsQueryClient, LogsQueryResultStatus } = require("@azure/monitor-query");
10-
const dotenv = require("dotenv");
11-
dotenv.config();
10+
require("dotenv").config();
1211

1312
const monitorWorkspaceId = process.env.MONITOR_WORKSPACE_ID;
1413
const additionalWorkspaces1 = process.env.ADDITIONAL_WORKSPACES_1 || "workspace1";
@@ -28,11 +27,11 @@ async function main() {
2827
console.log(`Running '${kustoQuery}' over the last 5 minutes`);
2928
const queryLogsOptions = {
3029
// explicitly control the amount of time the server can spend processing the query.
31-
serverTimeoutInSeconds: 60,
30+
serverTimeoutInSeconds: 600,
3231
// optionally enable returning additional statistics about the query's execution.
3332
// (by default this is off)
3433
includeQueryStatistics: true,
35-
additionalWorkspaces: [additionalWorkspaces1, additionalWorkspaces2]
34+
additionalWorkspaces: [additionalWorkspaces1, additionalWorkspaces2],
3635
};
3736

3837
const result = await logsQueryClient.queryWorkspace(
@@ -87,3 +86,5 @@ main().catch((err) => {
8786
console.error("The sample encountered an error:", err);
8887
process.exit(1);
8988
});
89+
90+
module.exports = { main };

sdk/monitor/monitor-query/samples/v1/javascript/metricsQuery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
const { DefaultAzureCredential } = require("@azure/identity");
99
const { Durations, MetricsQueryClient } = require("@azure/monitor-query");
10-
const dotenv = require("dotenv");
11-
12-
dotenv.config();
10+
require("dotenv").config();
1311

1412
const metricsResourceId = process.env.METRICS_RESOURCE_ID;
1513

@@ -34,7 +32,7 @@ async function main() {
3432
console.log(`Picking an example list of metrics to query: ${metricNames}`);
3533
const metricsResponse = await metricsQueryClient.queryResource(metricsResourceId, metricNames, {
3634
granularity: "PT1M",
37-
timespan: { duration: Durations.fiveMinutes }
35+
timespan: { duration: Durations.fiveMinutes },
3836
});
3937

4038
console.log(
@@ -54,3 +52,5 @@ main().catch((err) => {
5452
console.error("The sample encountered an error:", err);
5553
process.exit(1);
5654
});
55+
56+
module.exports = { main };

sdk/monitor/monitor-query/samples/v1/typescript/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@azure/identity": "^2.0.1"
3333
},
3434
"devDependencies": {
35-
"typescript": "~4.4.0",
35+
"@types/node": "^12.0.0",
36+
"typescript": "~4.6.0",
3637
"rimraf": "latest"
3738
}
3839
}

sdk/monitor/monitor-query/samples/v1/typescript/src/logsQuery.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
LogsQueryClient,
1212
LogsTable,
1313
LogsQueryOptions,
14-
LogsQueryResultStatus
14+
LogsQueryResultStatus,
1515
} from "@azure/monitor-query";
1616
import * as dotenv from "dotenv";
1717
dotenv.config();
@@ -32,10 +32,10 @@ export async function main() {
3232
console.log(`Running '${kustoQuery}' over the last One Hour`);
3333
const queryLogsOptions: LogsQueryOptions = {
3434
// explicitly control the amount of time the server can spend processing the query.
35-
serverTimeoutInSeconds: 60,
35+
serverTimeoutInSeconds: 600, // sets the timeout to 10 minutes
3636
// optionally enable returning additional statistics about the query's execution.
3737
// (by default this is off)
38-
includeQueryStatistics: true
38+
includeQueryStatistics: true,
3939
};
4040

4141
const result = await logsQueryClient.queryWorkspace(

sdk/monitor/monitor-query/samples/v1/typescript/src/logsQueryBatch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ export async function main() {
2525
{
2626
workspaceId: monitorWorkspaceId,
2727
query: kqlQuery,
28-
timespan: { duration: "P1D" }
28+
timespan: { duration: "P1D" },
2929
},
3030
{
3131
workspaceId: monitorWorkspaceId,
3232
query: "AzureActivity | summarize count()",
33-
timespan: { duration: "PT1H" }
33+
timespan: { duration: "PT1H" },
3434
},
3535
{
3636
workspaceId: monitorWorkspaceId,
3737
query:
3838
"AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId",
39-
timespan: { duration: "PT1H" }
39+
timespan: { duration: "PT1H" },
4040
},
4141
{
4242
workspaceId: monitorWorkspaceId,
4343
query: "AppRequests | take 2",
4444
timespan: { duration: "PT1H" },
45-
includeQueryStatistics: true
46-
}
45+
includeQueryStatistics: true,
46+
},
4747
];
4848

4949
const result = await logsQueryClient.queryBatch(queriesBatch);

0 commit comments

Comments
 (0)