Skip to content

Unncessary response deserializations in PartialSuccessTransmissionPolicy for ingestion sampling cases #2445

@vangarp

Description

@vangarp
  • List of NuGet packages and version that you are using: Microsoft.ApplicationInsights.AspNetCore v2.16.0
  • Runtime version (e.g. net461, net48, netcoreapp2.1, netcoreapp3.1, etc. You can find this information from the *.csproj file): netcoreapp3.1
  • Hosting environment (e.g. Azure Web App, App Service on Linux, Windows, Ubuntu, etc.): Windows

Describe the bug

Due to the way the code at

if (backendResponse.ItemsAccepted != backendResponse.ItemsReceived)
{
string[] items = JsonSerializer
.Deserialize(initialTransmission.Content)
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var error in backendResponse.Errors)
{
if (error != null)
{
is, we are deserializing the initialTransmission.Content any time the items backendResponse.ItemsAccepted != backendResponse.ItemsReceived regardless of the error codes (which is checked later). In cases when there is ingestion time sampling enabled, backendResponse.ItemsAccepted != backendResponse.ItemsReceived due to the sampling and we end up deserializing the items even though the error is not a retryable error code in such cases (statusCode 206). This results in unncessary memory allocations and wasted CPU cycles.

To Reproduce

In your AI resource just turn on ingestion side sampling to a relatively high degree and collect a memory dump using Perfview etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions