Skip to content

Commit 8ffff38

Browse files
authored
Adjust the request header and body sent to the server. (#14250)
- Move the correlation id to the header. - Remove the session id from the context. It's not used.
1 parent 6be762f commit 8ffff38

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tools/Az.Tools.Predictor/Az.Tools.Predictor/AzPredictorService.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ private sealed class PredictionRequestBody
3939
{
4040
public sealed class RequestContext
4141
{
42-
public string CorrelationId { get; set; } = Guid.Empty.ToString();
43-
public string SessionId { get; set; } = Guid.Empty.ToString();
4442
public string SubscriptionId { get; set; } = Guid.Empty.ToString();
4543
public Version VersionNumber{ get; set; } = new Version(0, 0);
4644
}
@@ -57,6 +55,11 @@ private sealed class CommandRequestContext
5755
public Version VersionNumber{ get; set; } = new Version(0, 0);
5856
}
5957

58+
/// <summary>
59+
/// The name of the header value that contains the platform correlation id.
60+
/// </summary>
61+
private const string CorrelationIdHeader = "Sml-CorrelationId";
62+
6063
private const string ThrottleByIdHeader = "X-UserId";
6164
private readonly HttpClient _client;
6265
private readonly string _commandsEndpoint;
@@ -285,12 +288,10 @@ public virtual void RequestPredictions(IEnumerable<string> commands)
285288
Task.Run(async () => {
286289
try
287290
{
288-
AzPredictorService.ReplaceThrottleUserIdToHeader(_client?.DefaultRequestHeaders, _azContext.UserId);
291+
AzPredictorService.SetHttpRequestHeader(_client?.DefaultRequestHeaders, _azContext.UserId, _telemetryClient.CorrelationId);
289292

290293
var requestContext = new PredictionRequestBody.RequestContext()
291294
{
292-
SessionId = _telemetryClient.SessionId,
293-
CorrelationId = _telemetryClient.CorrelationId,
294295
VersionNumber = this._azContext.AzVersion
295296
};
296297

@@ -358,7 +359,7 @@ protected virtual void RequestAllPredictiveCommands()
358359

359360
try
360361
{
361-
_client.DefaultRequestHeaders?.Add(AzPredictorService.ThrottleByIdHeader, _azContext.UserId);
362+
AzPredictorService.SetHttpRequestHeader(_client.DefaultRequestHeaders, _azContext.UserId, _telemetryClient.CorrelationId);
362363

363364
var httpResponseMessage = await _client.GetAsync(_commandsEndpoint);
364365

@@ -427,21 +428,27 @@ private static string GetCommandName(string commandLine)
427428
return commandLine.Split(AzPredictorConstants.CommandParameterSeperator).First();
428429
}
429430

430-
private static void ReplaceThrottleUserIdToHeader(HttpRequestHeaders header, string value)
431+
private static void SetHttpRequestHeader(HttpRequestHeaders header, string idToThrottle, string correlationId)
431432
{
432433
if (header != null)
433434
{
434435
lock (header)
435436
{
436437
header.Remove(AzPredictorService.ThrottleByIdHeader);
437438

438-
if (!string.IsNullOrWhiteSpace(value))
439+
if (!string.IsNullOrWhiteSpace(idToThrottle))
440+
{
441+
header.Add(AzPredictorService.ThrottleByIdHeader, idToThrottle);
442+
}
443+
444+
header.Remove(AzPredictorService.CorrelationIdHeader);
445+
446+
if (!string.IsNullOrWhiteSpace(correlationId))
439447
{
440-
header.Add(AzPredictorService.ThrottleByIdHeader, value);
448+
header.Add(AzPredictorService.CorrelationIdHeader, correlationId);
441449
}
442450
}
443451
}
444-
445452
}
446453
}
447454
}

0 commit comments

Comments
 (0)