Skip to content

Commit 4395582

Browse files
authored
Fix timeout of Invoke-AzOperationalInsightsQuery (#24882)
1 parent 7aa0d21 commit 4395582

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/OperationalInsights/OperationalInsights/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Fixed an issue that `Invoke-AzOperationalInsightsQuery` timed out after 100 seconds. The timeout is now bound to the `-Wait` parameter. (#16553)
2223
* Removed the outdated deps.json file.
2324

2425
## Version 3.2.0

src/OperationalInsights/OperationalInsights/Query/InvokeOperationalInsightsQuery.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using System.Management.Automation;
2121
using System.Net;
2222
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
23+
using System.Threading;
24+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2325

2426
namespace Microsoft.Azure.Commands.OperationalInsights.Query
2527
{
@@ -28,6 +30,7 @@ public class InvokeOperationalInsightsQuery : ResourceManager.Common.AzureRmLong
2830
{
2931
private const string ParamSetNameByWorkspaceId = "ByWorkspaceId";
3032
private const string ParamSetNameByWorkspaceObject = "ByWorkspaceObject";
33+
private readonly double _timeoutBufferInSeconds = 30;
3134

3235
[Parameter(Mandatory = true, ParameterSetName = ParamSetNameByWorkspaceId, HelpMessage = "The workspace ID.")]
3336
[ValidateNotNullOrEmpty]
@@ -73,11 +76,13 @@ internal OperationalInsightsDataClient OperationalInsightsDataClient
7376

7477
this._operationalInsightsDataClient =
7578
AzureSession.Instance.ClientFactory.CreateCustomArmClient<OperationalInsightsDataClient>(clientCredentials);
79+
ConfigureTimeoutForClient();
80+
7681
this._operationalInsightsDataClient.Preferences.IncludeRender = IncludeRender.IsPresent;
7782
this._operationalInsightsDataClient.Preferences.IncludeStatistics = IncludeStatistics.IsPresent;
7883
this._operationalInsightsDataClient.NameHeader = "LogAnalyticsPSClient";
7984

80-
Uri targetUri= null;
85+
Uri targetUri = null;
8186
DefaultContext.Environment.TryGetEndpointUrl(
8287
AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, out targetUri);
8388
if (targetUri == null)
@@ -101,6 +106,14 @@ internal OperationalInsightsDataClient OperationalInsightsDataClient
101106
}
102107
}
103108

109+
private void ConfigureTimeoutForClient()
110+
{
111+
if (this.IsParameterBound(c => c.Wait) && Wait != null)
112+
{
113+
_operationalInsightsDataClient.HttpClient.Timeout = TimeSpan.FromSeconds(Convert.ToDouble(Wait)).Add(TimeSpan.FromSeconds(_timeoutBufferInSeconds));
114+
}
115+
}
116+
104117
public override void ExecuteCmdlet()
105118
{
106119
if (ParameterSetName == ParamSetNameByWorkspaceId)

src/OperationalInsights/OperationalInsights/help/Invoke-AzOperationalInsightsQuery.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ You can retrieve the results of the search from the Value property of the return
3333
Please check detail of general query limits here:
3434
https://learn.microsoft.com/azure/azure-monitor/service-limits#log-queries-and-language.
3535

36+
Note: try setting `-Wait` to a larger value if you experience the error 'The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing'.
37+
3638
## EXAMPLES
3739

3840
### Example 1: Get search results using a query

0 commit comments

Comments
 (0)