This commit is contained in:
Rajkumar Rangaraj 2021-04-13 18:44:54 -07:00
Родитель d248059ac7
Коммит 017d3ba787
18 изменённых файлов: 60 добавлений и 66 удалений

Просмотреть файл

@ -1,8 +1,4 @@
Microsoft.ApplicationInsights.Channel.IAsyncFlushable
Microsoft.ApplicationInsights.Channel.IAsyncFlushable.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Microsoft.ApplicationInsights.Channel.Transmission.FlushAsyncId.get -> long
Microsoft.ApplicationInsights.Channel.Transmission.HasFlushTask.get -> bool
Microsoft.ApplicationInsights.Channel.Transmission.HasFlushTask.set -> void
Microsoft.ApplicationInsights.Channel.Transmission.Serialize(System.Uri address, System.Collections.Generic.IEnumerable<Microsoft.ApplicationInsights.Channel.ITelemetry> telemetryItems, System.TimeSpan timeout = default(System.TimeSpan)) -> void
Microsoft.ApplicationInsights.TelemetryClient.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>

Просмотреть файл

@ -1,8 +1,4 @@
Microsoft.ApplicationInsights.Channel.IAsyncFlushable
Microsoft.ApplicationInsights.Channel.IAsyncFlushable.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Microsoft.ApplicationInsights.Channel.Transmission.FlushAsyncId.get -> long
Microsoft.ApplicationInsights.Channel.Transmission.HasFlushTask.get -> bool
Microsoft.ApplicationInsights.Channel.Transmission.HasFlushTask.set -> void
Microsoft.ApplicationInsights.Channel.Transmission.Serialize(System.Uri address, System.Collections.Generic.IEnumerable<Microsoft.ApplicationInsights.Channel.ITelemetry> telemetryItems, System.TimeSpan timeout = default(System.TimeSpan)) -> void
Microsoft.ApplicationInsights.TelemetryClient.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>

Просмотреть файл

@ -1,8 +1,4 @@
Microsoft.ApplicationInsights.Channel.IAsyncFlushable
Microsoft.ApplicationInsights.Channel.IAsyncFlushable.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Microsoft.ApplicationInsights.Channel.Transmission.FlushAsyncId.get -> long
Microsoft.ApplicationInsights.Channel.Transmission.HasFlushTask.get -> bool
Microsoft.ApplicationInsights.Channel.Transmission.HasFlushTask.set -> void
Microsoft.ApplicationInsights.Channel.Transmission.Serialize(System.Uri address, System.Collections.Generic.IEnumerable<Microsoft.ApplicationInsights.Channel.ITelemetry> telemetryItems, System.TimeSpan timeout = default(System.TimeSpan)) -> void
Microsoft.ApplicationInsights.TelemetryClient.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>

Просмотреть файл

@ -214,7 +214,7 @@ namespace Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implement
Assert.AreEqual(69, traces[0].EventId); // failed to send
Assert.AreEqual("Data loss", traces[0].Payload[1]);
// Sets flush task to failure on not whitelisted status code
Assert.IsFalse(failedTransmission.HasFlushTask);
Assert.IsFalse(failedTransmission.IsFlushAsyncInProgress);
}
}
@ -247,7 +247,7 @@ namespace Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implement
Assert.AreEqual(69, traces[0].EventId); // failed to send
Assert.AreEqual("Unknown Exception Message", traces[0].Payload[1]);
// Sets flush task to failure on not whitelisted status code
Assert.IsFalse(failedTransmission.HasFlushTask);
Assert.IsFalse(failedTransmission.IsFlushAsyncInProgress);
}
}
@ -284,7 +284,7 @@ namespace Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implement
Assert.AreEqual(71, traces[0].EventId); // failed to send
Assert.AreEqual("8989", traces[0].Payload[1]);
// Sets flush task to failure on not whitelisted status code
Assert.IsFalse(failedTransmission.HasFlushTask);
Assert.IsFalse(failedTransmission.IsFlushAsyncInProgress);
}
}

Просмотреть файл

@ -285,7 +285,7 @@
policy.Initialize(transmitter);
var items = new List<ITelemetry> { new EventTelemetry(), new EventTelemetry() };
Transmission transmission = new Transmission(new Uri("http://uri"), items, "type", "encoding") { HasFlushTask = true };
Transmission transmission = new Transmission(new Uri("http://uri"), items, "type", "encoding") { IsFlushAsyncInProgress = true };
string response = BackendResponseHelper.CreateBackendResponse(
itemsReceived: 2,
@ -301,7 +301,7 @@
transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(transmission, null, wrapper));
Assert.AreEqual(1, enqueuedTransmissions.Count);
Assert.IsTrue(transmission.HasFlushTask);
Assert.IsTrue(transmission.IsFlushAsyncInProgress);
}
}
}

Просмотреть файл

@ -552,6 +552,15 @@
Assert.IsTrue(anotherThread.Wait(50));
}
[TestMethod]
public void SerializerThrowsExceptionWhenEndPointIsNull()
{
var serializer = new TelemetrySerializer(new Transmitter());
var telemetryBuffer = new TelemetryBuffer(serializer, new StubApplicationLifecycle());
AssertEx.Throws<Exception>(() => telemetryBuffer.FlushAsync(default));
}
}
}
}

Просмотреть файл

@ -241,7 +241,7 @@
transmitter.OnEnqueue = t =>
{
transmission = t;
transmission.HasFlushTask = true;
transmission.IsFlushAsyncInProgress = true;
};
var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("http://expected.uri") };
@ -297,7 +297,7 @@
transmitter.OnEnqueue = t =>
{
transmission = t;
transmission.HasFlushTask = false;
transmission.IsFlushAsyncInProgress = false;
};
var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("http://expected.uri") };

Просмотреть файл

@ -137,7 +137,7 @@
transmitter.OnTransmissionSent(
new TransmissionProcessedEventArgs(
new StubTransmission() { HasFlushTask = hasFlushTask }, null, new HttpWebResponseWrapper()
new StubTransmission() { IsFlushAsyncInProgress = hasFlushTask }, null, new HttpWebResponseWrapper()
{
StatusCode = responseCode,
StatusDescription = statusDescription,

Просмотреть файл

@ -339,12 +339,12 @@
var wrapper = new HttpWebResponseWrapper();
Transmission transmission = new StubTransmission(telemetryItems) { OnSend = () => wrapper };
transmission.HasFlushTask = true;
transmission.IsFlushAsyncInProgress = true;
sender.Enqueue(() => transmission);
// Both accepted and rejected transmission has flush task
Assert.IsTrue(eventArgs[0].Transmission.HasFlushTask);
Assert.IsTrue(eventArgs[1].Transmission.HasFlushTask);
Assert.IsTrue(eventArgs[0].Transmission.IsFlushAsyncInProgress);
Assert.IsTrue(eventArgs[1].Transmission.IsFlushAsyncInProgress);
}
[TestMethod]
@ -377,8 +377,8 @@
sender.Enqueue(() => transmission);
// Both accepted and rejected transmission has flush task
Assert.IsFalse(eventArgs[0].Transmission.HasFlushTask);
Assert.IsFalse(eventArgs[1].Transmission.HasFlushTask);
Assert.IsFalse(eventArgs[0].Transmission.IsFlushAsyncInProgress);
Assert.IsFalse(eventArgs[1].Transmission.IsFlushAsyncInProgress);
}
[TestMethod]

Просмотреть файл

@ -797,7 +797,7 @@
if (transmission != null)
{
storedTransmission = transmission;
transmission.HasFlushTask = true;
transmission.IsFlushAsyncInProgress = true;
return true;
}

Просмотреть файл

@ -26,13 +26,6 @@
private int isSending;
/// <summary>
/// Initializes a new instance of the <see cref="Transmission"/> class. This overload seperates telemetryitems serialization from object construction.
/// </summary>
public Transmission()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Transmission"/> class.
/// </summary>
@ -73,6 +66,13 @@
client = passedClient;
}
/// <summary>
/// Initializes a new instance of the <see cref="Transmission"/> class. This overload is for Test purposes.
/// </summary>
protected internal Transmission()
{
}
/// <summary>
/// Gets or Sets an event notification to track ingestion endpoint response.
/// </summary>
@ -144,28 +144,12 @@
/// <summary>
/// Gets the flush async id for the transmission.
/// </summary>
/// [EditorBrowsable(EditorBrowsableState.Never)]
public long FlushAsyncId { get; } = Interlocked.Increment(ref flushAsyncCounter);
internal long FlushAsyncId { get; } = Interlocked.Increment(ref flushAsyncCounter);
/// <summary>
/// Gets or sets a value indicating whether this transmission is created from FlushAsync API call.
/// Gets or sets a value indicating whether FlushAsync is in progress.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool HasFlushTask { get; set; } = false;
/// <summary>
/// Serializes telemetry items.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void Serialize(Uri address, IEnumerable<ITelemetry> telemetryItems, TimeSpan timeout = default(TimeSpan))
{
this.EndpointAddress = address;
this.Content = JsonSerializer.Serialize(telemetryItems);
this.ContentType = JsonSerializer.ContentType;
this.ContentEncoding = JsonSerializer.CompressionType;
this.Timeout = timeout == default(TimeSpan) ? DefaultTimeout : timeout;
this.Id = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next()));
}
internal bool IsFlushAsyncInProgress { get; set; } = false;
/// <summary>
/// Executes the request that the current transmission represents.
@ -386,6 +370,19 @@
return Tuple.Create(transmissionA, transmissionB);
}
/// <summary>
/// Serializes telemetry items.
/// </summary>
internal void Serialize(Uri address, IEnumerable<ITelemetry> telemetryItems, TimeSpan timeout = default(TimeSpan))
{
this.EndpointAddress = address;
this.Content = JsonSerializer.Serialize(telemetryItems);
this.ContentType = JsonSerializer.ContentType;
this.ContentEncoding = JsonSerializer.CompressionType;
this.Timeout = timeout == default(TimeSpan) ? DefaultTimeout : timeout;
this.Id = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next()));
}
/// <summary>
/// Creates an http request for sending a transmission.
/// </summary>

Просмотреть файл

@ -105,7 +105,7 @@
TelemetryChannelEventSource.Log.TransmissionDataNotRetriedForNonWhitelistedResponse(e.Transmission.Id,
httpWebResponseWrapper.StatusCode.ToString(CultureInfo.InvariantCulture));
// For non white listed response, set the result of FlushAsync to false.
e.Transmission.HasFlushTask = false;
e.Transmission.IsFlushAsyncInProgress = false;
break;
}
}
@ -126,7 +126,7 @@
}
// For Unknown Exception set the result of FlushAsync to false.
e.Transmission.HasFlushTask = false;
e.Transmission.IsFlushAsyncInProgress = false;
}
}

Просмотреть файл

@ -106,7 +106,7 @@
if (!string.IsNullOrEmpty(newTransmissions))
{
if (args.Transmission.HasFlushTask)
if (args.Transmission.IsFlushAsyncInProgress)
{
// Move newTransmission to storage on IAsyncFlushable.FlushAsync
transmission = this.SerializeNewTransmission(args, newTransmissions);

Просмотреть файл

@ -170,7 +170,7 @@
/// </summary>
public virtual async Task FlushAsync()
{
List<ITelemetry> telemetryToFlush = this.MoveTelemeteryBufferForFlush();
List<ITelemetry> telemetryToFlush = this.GetBufferTelemetryAndResetBuffer();
if (telemetryToFlush != null)
{
@ -188,7 +188,7 @@
/// </summary>
public virtual Task<bool> FlushAsync(CancellationToken cancellationToken)
{
List<ITelemetry> telemetryToFlush = this.MoveTelemeteryBufferForFlush();
List<ITelemetry> telemetryToFlush = this.GetBufferTelemetryAndResetBuffer();
if (!cancellationToken.IsCancellationRequested)
{
@ -208,7 +208,7 @@
return this.GetEnumerator();
}
private List<ITelemetry> MoveTelemeteryBufferForFlush()
private List<ITelemetry> GetBufferTelemetryAndResetBuffer()
{
List<ITelemetry> telemetryToFlush = null;
if (this.itemBuffer.Count > 0)

Просмотреть файл

@ -44,7 +44,7 @@
this.MaxBufferCapacity = 0;
this.MaxStorageCapacity = 0;
}
else if (e.Transmission.HasFlushTask)
else if (e.Transmission.IsFlushAsyncInProgress)
{
// Move rejectedTransmission to storage on IAsyncFlushable.FlushAsync
this.MaxBufferCapacity = 0;

Просмотреть файл

@ -316,10 +316,10 @@
if (rejectedTransmission != null)
{
TelemetryChannelEventSource.Log.TransmissionThrottledWarning(this.ThrottleLimit, attemptedItemsCount, acceptedItemsCount);
if (transmission.HasFlushTask)
if (transmission.IsFlushAsyncInProgress)
{
acceptedTransmission.HasFlushTask = true;
rejectedTransmission.HasFlushTask = true;
acceptedTransmission.IsFlushAsyncInProgress = true;
rejectedTransmission.IsFlushAsyncInProgress = true;
}
this.SendTransmissionThrottleRejection(rejectedTransmission);

Просмотреть файл

@ -173,7 +173,7 @@
if (!this.Storage.Enqueue(transmissionGetter))
{
transmission.HasFlushTask = false;
transmission.IsFlushAsyncInProgress = false;
TelemetryChannelEventSource.Log.TransmitterStorageSkipped(transmission.Id);
}
}
@ -183,7 +183,7 @@
TaskStatus taskStatus = TaskStatus.Canceled;
if (!cancellationToken.IsCancellationRequested)
{
transmission.HasFlushTask = true;
transmission.IsFlushAsyncInProgress = true;
this.Enqueue(transmission);
try
@ -207,7 +207,7 @@
{
flushTaskStatus = TaskEx.FromCanceled<bool>(cancellationToken);
}
else if (taskStatus == TaskStatus.RanToCompletion && transmission.HasFlushTask)
else if (taskStatus == TaskStatus.RanToCompletion && transmission.IsFlushAsyncInProgress)
{
flushTaskStatus = this.successTask;
}

Просмотреть файл

@ -3,6 +3,7 @@
## VNext
- [Fix PropertyFetcher error when used with multiple types](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2194)
- [New Task Based Flush API - FlushAsync] (https://github.com/microsoft/ApplicationInsights-dotnet/issues/1743)
## Version 2.17.0
- [Fix: telemetry parent id when using W3C activity format in TelemetryDiagnosticSourceListener](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2142)
@ -68,7 +69,6 @@
- [Fix: Disabling HeartBeats in Asp.Net Core projects causes Error traces every heart beat interval (15 minutes defualt)](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1681)
- [Standard Metric extractor (Exception,Trace) populates all standard dimensions.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1738)
- [Add an explicit reference to System.Memory v4.5.4. This fixes a bug in System.Diagnostics.DiagnosticSource. We will remove this dependency when DiagnosticSource is re-released.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1707)
- [New Task Based Flush API - FlushAsync] (https://github.com/microsoft/ApplicationInsights-dotnet/issues/1743)
## Version 2.14.0-beta3
- [New: JavaScript Property to support Content Security Policy](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1443)