Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Minimize noisy Storage exceptions via DPG methods #27645

Closed
wants to merge 2 commits into from

Conversation

tg-msft
Copy link
Member

@tg-msft tg-msft commented Mar 18, 2022

This shows how we can reduce logging noise for expected failures by using DPG methods from HLCs. #25626 is tracking the meta issue, but this is a proof of concept for both internal only (like BlobClient.Exists for #18592) and externally visible (like BlobLeaseClient.Acquire for #21511) cases.

This is currently blocked on #27614 before we can ship it.

There are also a few tests in DataLake like FileClientTest.ExistsAsync_CPK complaining about not matching the recordings, but it's difficult to debug at the moment because of a known issue in the test proxy. I'm ignoring those for the moment.

@ghost ghost added Azure.Core Storage Storage Service (Queues, Blobs, Files) labels Mar 18, 2022
// Get the blob properties, but don't throw any exceptions
RequestContext context = new()
{
ErrorOptions = ErrorOptions.NoThrow,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will suppress an exception from being thrown from within GetProperties, but error logging and tracing will still occur in the pipeline. In order to suppress those as well, you'll need to add classifiers using context.AddClassifier(...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh... That's what I get for rushing and only checking the Storage tests. I updated and verified that distributed tracing is clean too.

Current:
Current

Fixed:
Fixed

#define Fixed

using Azure;
using Azure.Core;
using Azure.Monitor.OpenTelemetry.Exporter;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using OpenTelemetry.Trace;
using System.Diagnostics;

// Settings
const string StorageConnStr = "...";
const string AppInsightsConnStr = "...";
const string Name =
#if !Fixed
    "Current";
#else
    "Fixed";
#endif

// Collect telemetry in Azure Monitor
AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);
using TracerProvider telemetry =
    OpenTelemetry.Sdk
    .CreateTracerProviderBuilder()
    .AddSource(Name, "Azure.*")
    .AddAzureMonitorTraceExporter(options => options.ConnectionString = AppInsightsConnStr)
    .Build();
using ActivitySource source = new(Name);
using Activity? group = source.StartActivity(Name)!;


// Check if a fake blob exists
BlobClient fake = new BlobClient(StorageConnStr, "fakecontainer", "fakeblob");
Console.WriteLine($"Exists: {fake.Exists().Value}");


// Try acquiring a lease from a fake blob
#if !Fixed

try
{
    BlobLease lease = fake.GetBlobLeaseClient().Acquire(TimeSpan.FromSeconds(15));
    Console.WriteLine($"Lease: {lease.LeaseId}");
}
catch (RequestFailedException ex)
{
    Console.WriteLine($"Failed to obtain lease!\n{ex}");
}

#else

RequestContext context =
    new RequestContext() { ErrorOptions = ErrorOptions.NoThrow }
    .AddClassifier(404, BlobErrorCode.BlobNotFound.ToString(), false)
    .AddClassifier(404, BlobErrorCode.ContainerNotFound.ToString(), false)
    .AddClassifier(409, BlobErrorCode.LeaseAlreadyPresent.ToString(), false);
Response<BlobLease> response =
    fake.GetBlobLeaseClient().Acquire(
        TimeSpan.FromSeconds(15),
        conditions: null,
        context);
Response raw = response.GetRawResponse();
if (raw.Status == 201)
{
    Console.WriteLine($"Lease: {response.Value.LeaseId}");
}
else
{
    Console.WriteLine($"Failed to obtain lease!\n{raw.Content.ToString()}");
}

#endif

@@ -1578,7 +1578,9 @@ public partial class BlobLeaseClient
protected virtual Azure.Storage.Blobs.BlobContainerClient BlobContainerClient { get { throw null; } }
public virtual string LeaseId { get { throw null; } }
public System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Blobs.Models.BlobLease> Acquire(System.TimeSpan duration, Azure.RequestConditions conditions, Azure.RequestContext context) { throw null; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we determine that we want to add RequestContext to HLC methods vs using it internally.
I.e. why this instead of AcquireIfNotYetAcuired API that uses RequestContext internally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's not really doing AcquireIfNotYetAcquired. It's doing AcquireIfBlobNotFoundOrContainerNotFoundOrLeaseAlreadyAcquired and we don't want to add an overload for that specific, non-general scenario.

.AddClassifier(404, BlobErrorCode.ContainerNotFound.ToString(), false);
Response<BlobLease> response =
await blob.GetBlobLeaseClient()
.AcquireAsync(LeasePeriod, conditions: null, context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If BlockBlobClient is using ClientDiagnostics internally to create a RequestFailedException, adding these classifiers should be enough to suppress any unwanted errors while preserving correct exception creation.

@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label May 27, 2022
@ghost
Copy link

ghost commented May 27, 2022

Hi @tg-msft. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

@tg-msft
Copy link
Member Author

tg-msft commented May 27, 2022

Be gone from here, bot.

@ghost ghost removed the no-recent-activity There has been no recent activity on this issue. label May 27, 2022
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Jul 29, 2022
@ghost
Copy link

ghost commented Jul 29, 2022

Hi @tg-msft. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

@ghost ghost closed this Aug 5, 2022
@ghost
Copy link

ghost commented Aug 5, 2022

Hi @tg-msft. Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing "/reopen" if you'd like to continue working on these changes. Please be sure to use the command to reopen or remove the "no-recent-activity" label; otherwise, this is likely to be closed again with the next cleanup pass.

@tg-msft tg-msft reopened this Aug 5, 2022
@azure-sdk
Copy link
Collaborator

azure-sdk commented Aug 5, 2022

API change check

APIView has identified API level changes in this PR and created following API reviews.

Azure.Storage.Blobs

@ghost ghost removed the no-recent-activity There has been no recent activity on this issue. label Aug 5, 2022
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Oct 7, 2022
@ghost
Copy link

ghost commented Oct 7, 2022

Hi @tg-msft. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

@ghost ghost closed this Oct 14, 2022
@ghost
Copy link

ghost commented Oct 14, 2022

Hi @tg-msft. Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing "/reopen" if you'd like to continue working on these changes. Please be sure to use the command to reopen or remove the "no-recent-activity" label; otherwise, this is likely to be closed again with the next cleanup pass.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core no-recent-activity There has been no recent activity on this issue. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants