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

[EventHubs] Track Two: Second Preview (Diagnostics Tests) #6913

Merged
merged 23 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
714ba9e
Some test files included (a lot of changes expected). Single incomple…
kinelski Jul 12, 2019
d05b4c1
Using only LiveTests for now. Single test failing, but complete.
kinelski Jul 12, 2019
1d56125
All send live tests added. Diagnostics not working as expected
kinelski Jul 15, 2019
d8f76f4
PartitionSender tests not necessary. Injection issue needs to be fixed.
kinelski Jul 16, 2019
d6cdb86
Receive test included as well. Injection still not working.
kinelski Jul 16, 2019
3676acf
Receive test working. The order matters.
kinelski Jul 16, 2019
4378502
Injection issue somehow solved.
kinelski Jul 16, 2019
786d491
PartitionKey property in diagnostics may receive partition id
kinelski Jul 16, 2019
7ddce05
Merge remote-tracking branch 'upstream/master' into diag
kinelski Jul 16, 2019
d704760
Non-live diagnostics tests added
kinelski Jul 16, 2019
e422bc3
Extension class moved to new namespace
kinelski Jul 16, 2019
4c5c446
final comments
kinelski Jul 17, 2019
6fea5fa
Diagnostics contain Track Two Event Data.
kinelski Jul 17, 2019
dd6eb76
Reorder; more comments and small fix in diagnostics asserts.
kinelski Jul 17, 2019
40e7963
Small fix: isFaulted
kinelski Jul 17, 2019
b1da098
Final changes to increase coverage.
kinelski Jul 17, 2019
d0c5c61
Addressed some comments
kinelski Jul 17, 2019
357936e
Deleted diagnostics event data extension method related stuff
kinelski Jul 17, 2019
c968061
Moved fake listener to infrastructure
kinelski Jul 17, 2019
6c087b9
Added comments and made small changes.
kinelski Jul 18, 2019
8fef3d5
Wording
kinelski Jul 18, 2019
da27270
Merge conflict
kinelski Jul 18, 2019
fd74163
Final fixes.
kinelski Jul 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task RunAsync(string connectionString,
// time that we've allowed.
//
// We will ask for just our event, but allow a fairly long wait period to ensure that we're able to receive it.
// If you observe the time that the call takes, it is extremely likely that the request to recieve will complete
// If you observe the time that the call takes, it is extremely likely that the request to receive will complete
kinelski marked this conversation as resolved.
Show resolved Hide resolved
// long before the maximum wait time.

Stopwatch watch = Stopwatch.StartNew();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Azure.Messaging.EventHubs.Compatibility
internal static class TrackOneExceptionExtensions
{
/// <summary>
/// Maps a <see cref="TrackOne.EventHubsException" /> or a child of it to the equivilent
/// Maps a <see cref="TrackOne.EventHubsException" /> or a child of it to the equivalent
/// exception for the new API surface.
/// </summary>
///
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics;

namespace Azure.Messaging.EventHubs.Diagnostics
{
/// <summary>
/// Diagnostic extension methods for <see cref="EventData"/>.
/// </summary>
///
internal static class EventDataDiagnosticsExtensions
kinelski marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Creates <see cref="Activity"/> based on the tracing context stored in the <see cref="EventData"/>.
/// </summary>
///
/// <param name="eventData">The event received from EventHub.</param>
/// <param name="activityName">Optional Activity name.</param>
///
/// <returns>New <see cref="Activity"/> with tracing context.</returns>
///
public static Activity ExtractActivity(this EventData eventData, string activityName = null)
{
static TrackOne.EventData TransformEvent(EventData eventData) =>
new TrackOne.EventData(eventData.Body.ToArray())
{
Properties = eventData.Properties
};

return TrackOne.EventDataDiagnosticExtensions.ExtractActivity(TransformEvent(eventData), activityName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal override Retry Clone() =>
/// <returns>The set of properties for the retry policy.</returns>
///
/// <remarks>
/// This method is intended to allow for compatibility shims to create the equivilent retry
/// This method is intended to allow for compatibility shims to create the equivalent retry
/// policy within the track one code; it will be removed after the first preview and should
/// not be depended upon outside of that context.
/// </remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal struct ConnectionStringProperties
/// Initializes a new instance of the <see cref="ConnectionStringProperties"/> struct.
/// </summary>
///
/// <param name="endpoint">The endpoint of the EVent Hubs namespace.</param>
/// <param name="endpoint">The endpoint of the Event Hubs namespace.</param>
kinelski marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="eventHubPath">The path to the specific Event Hub under the namespace.</param>
/// <param name="sharedAccessKeyName">The name of the shared access key, to use authorization.</param>
/// <param name="sharedAccessKey">The shared access key to use for authorization.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal static class EventDataDiagnosticExtensions
///
/// </example>

public static Activity ExtractActivity(this EventData eventData, string activityName = null)
internal static Activity ExtractActivity(this EventData eventData, string activityName = null)
jsquire marked this conversation as resolved.
Show resolved Hide resolved
{
Guard.ArgumentNotNull(nameof(eventData), eventData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ protected EventDataSender(EventHubClient eventHubClient, string partitionId)
public async Task SendAsync(IEnumerable<EventData> eventDatas, string partitionKey)
{
int count = ValidateEvents(eventDatas);
var diagnosticPartitionKey = String.IsNullOrEmpty(partitionKey) ?
kinelski marked this conversation as resolved.
Show resolved Hide resolved
this.PartitionId :
partitionKey;

EventHubsEventSource.Log.EventSendStart(this.ClientId, count, partitionKey);
Activity activity = EventHubsDiagnosticSource.StartSendActivity(this.ClientId, this.EventHubClient.ConnectionStringBuilder, partitionKey, eventDatas, count);
Activity activity = EventHubsDiagnosticSource.StartSendActivity(this.ClientId, this.EventHubClient.ConnectionStringBuilder, diagnosticPartitionKey, eventDatas, count);

Task sendTask = null;
try
Expand All @@ -41,13 +44,13 @@ public async Task SendAsync(IEnumerable<EventData> eventDatas, string partitionK
catch (Exception exception)
{
EventHubsEventSource.Log.EventSendException(this.ClientId, exception.ToString());
EventHubsDiagnosticSource.FailSendActivity(activity, this.EventHubClient.ConnectionStringBuilder, partitionKey, eventDatas, exception);
EventHubsDiagnosticSource.FailSendActivity(activity, this.EventHubClient.ConnectionStringBuilder, diagnosticPartitionKey, eventDatas, exception);
throw;
}
finally
{
EventHubsEventSource.Log.EventSendStop(this.ClientId);
EventHubsDiagnosticSource.StopSendActivity(activity, this.EventHubClient.ConnectionStringBuilder, partitionKey, eventDatas, sendTask);
EventHubsDiagnosticSource.StopSendActivity(activity, this.EventHubClient.ConnectionStringBuilder, diagnosticPartitionKey, eventDatas, sendTask);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace TrackOne
/// </summary>
internal static class EventHubsDiagnosticSource
{
public const string DiagnosticSourceName = "TrackOne";
public const string DiagnosticSourceName = "Azure.Messaging.EventHubs";

public const string ActivityIdPropertyName = "Diagnostic-Id";
public const string CorrelationContextPropertyName = "Correlation-Context";
Expand Down Expand Up @@ -64,7 +64,7 @@ internal static Activity StartSendActivity(string clientId, EventHubsConnectionS
csb.Endpoint,
Entity = csb.EntityPath,
PartitionKey = partitionKey,
EventDatas = eventDatas
EventDatas = eventDatas.Select(TransformEvent)
});
}
else
Expand All @@ -90,7 +90,7 @@ internal static void FailSendActivity(Activity activity, EventHubsConnectionStri
csb.Endpoint,
Entity = csb.EntityPath,
PartitionKey = partitionKey,
EventDatas = eventDatas,
EventDatas = eventDatas.Select(TransformEvent),
Exception = ex
});
}
Expand All @@ -108,7 +108,7 @@ internal static void StopSendActivity(Activity activity, EventHubsConnectionStri
csb.Endpoint,
Entity = csb.EntityPath,
PartitionKey = partitionKey,
EventDatas = eventDatas,
EventDatas = eventDatas.Select(TransformEvent),
sendTask?.Status
});
}
Expand Down Expand Up @@ -201,7 +201,7 @@ internal static void StopReceiveActivity(Activity activity, EventHubsConnectionS
Entity = csb.EntityPath,
PartitionKey = partitionKey,
ConsumerGroup = consumerGroup,
EventDatas = events,
EventDatas = events.Select(TransformEvent),
receiveTask?.Status
});
}
Expand Down Expand Up @@ -262,5 +262,11 @@ private static void SetRelatedOperations(Activity activity, IEnumerable<EventDat
}

#endregion Diagnostic Context Injection

private static Azure.Messaging.EventHubs.EventData TransformEvent(EventData eventData) =>
new Azure.Messaging.EventHubs.EventData(eventData.Body.ToArray())
{
Properties = eventData.Properties
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void IsEventPositionEquivalentDetectsDifferentOffsets()
var trackOnePosition = TrackOne.EventPosition.FromOffset("12", false);
var trackTwoPosition = EventPosition.FromOffset(12);

Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.False, "The offset for track two is inclusive; even the same base offset with non-inclusive is not equivilent.");
Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.False, "The offset for track two is inclusive; even the same base offset with non-inclusive is not equivalent.");
}

/// <summary>
Expand All @@ -156,7 +156,7 @@ public void IsEventPositionEquivalentRecognizesSameOffsets()
var trackOnePosition = TrackOne.EventPosition.FromOffset("12", true);
var trackTwoPosition = EventPosition.FromOffset(12);

Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True, "The offset for track two is inclusive; the equivilent offset set as inclusive should match.");
Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True, "The offset for track two is inclusive; the equivalent offset set as inclusive should match.");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public async Task SendAsyncTransformsSimpleEvents()
var sentEvents = mock.SendCalledWithParameters.Events.ToArray();
Assert.That(sentEvents.Length, Is.EqualTo(sourceEvents.Length), "The number of events sent should match the number of source events.");

// The events should not only be structurally equivilent, the ordering of them should be preserved. Compare the
// sequence in order and validate that the events in each position are equivilent.
// The events should not only be structurally equivalent, the ordering of them should be preserved. Compare the
// sequence in order and validate that the events in each position are equivalent.

for (var index = 0; index < sentEvents.Length; ++index)
{
Expand Down Expand Up @@ -138,8 +138,8 @@ public async Task SendAsyncTransformsComplexEvents()
var sentEvents = mock.SendCalledWithParameters.Events.ToArray();
Assert.That(sentEvents.Length, Is.EqualTo(sourceEvents.Length), "The number of events sent should match the number of source events.");

// The events should not only be structurally equivilent, the ordering of them should be preserved. Compare the
// sequence in order and validate that the events in each position are equivilent.
// The events should not only be structurally equivalent, the ordering of them should be preserved. Compare the
// sequence in order and validate that the events in each position are equivalent.

for (var index = 0; index < sentEvents.Length; ++index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void ConstructorValidatesArguments()
///
[Test]
[TestCaseSource(nameof(SameConfigurationCases))]
public void HaveSameConfigurationRecognizesEquivilentConfiguration(ExponentialRetry first,
public void HaveSameConfigurationRecognizesEquivalentConfiguration(ExponentialRetry first,
ExponentialRetry second,
string description)
{
Expand Down
Loading