Skip to content

Commit 8682b3d

Browse files
authored
Diagnostic clean slate and initial features (#57)
- Removes existing DiagnosticSources (for now) - Add OpenTelemetry Activity support for product calls - Support optional disabling of Auditing for performance scenarios - Misc type cleanup
1 parent e2701a2 commit 8682b3d

29 files changed

+362
-315
lines changed

src/Elastic.Transport.VirtualizedCluster/Audit/Auditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private Auditor(Components.VirtualizedCluster cluster, Components.VirtualizedClu
4141

4242
private bool StartedUp { get; }
4343

44-
public void ChangeTime(Func<DateTime, DateTime> selector)
44+
public void ChangeTime(Func<DateTimeOffset, DateTimeOffset> selector)
4545
{
4646
_cluster ??= Cluster();
4747
_clusterAsync ??= Cluster();

src/Elastic.Transport.VirtualizedCluster/Components/VirtualizedCluster.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public TransportResponse ClientCall(Func<RequestConfigurationDescriptor, IReques
6868
public async Task<TransportResponse> ClientCallAsync(Func<RequestConfigurationDescriptor, IRequestConfiguration> requestOverrides = null) =>
6969
await _asyncCall(Transport, requestOverrides).ConfigureAwait(false);
7070

71-
public void ChangeTime(Func<DateTime, DateTime> change) => _dateTimeProvider.ChangeTime(change);
71+
public void ChangeTime(Func<DateTimeOffset, DateTimeOffset> change) => _dateTimeProvider.ChangeTime(change);
7272

7373
public void ClientThrows(bool throws) => _settings.ThrowExceptions(throws);
7474
}

src/Elastic.Transport.VirtualizedCluster/Providers/TestableDateTimeProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ namespace Elastic.Transport.VirtualizedCluster.Providers;
99
/// <inheritdoc cref="DateTimeProvider"/>
1010
public sealed class TestableDateTimeProvider : DateTimeProvider
1111
{
12-
private DateTime MutableNow { get; set; } = DateTime.UtcNow;
12+
private DateTimeOffset MutableNow { get; set; } = DateTimeOffset.UtcNow;
1313

1414
/// <inheritdoc cref="DateTimeProvider.Now"/>
15-
public override DateTime Now() => MutableNow;
15+
public override DateTimeOffset Now() => MutableNow;
1616

1717
/// <summary>
1818
/// Advance the time <see cref="Now"/> returns
1919
/// </summary>
2020
/// <param name="change">A fun that gets passed the current <see cref="Now"/> and needs to return the new value</param>
21-
public void ChangeTime(Func<DateTime, DateTime> change) => MutableNow = change(MutableNow);
21+
public void ChangeTime(Func<DateTimeOffset, DateTimeOffset> change) => MutableNow = change(MutableNow);
2222

23-
public override DateTime DeadTime(int attempts, TimeSpan? minDeadTimeout, TimeSpan? maxDeadTimeout) => throw new NotImplementedException();
23+
public override DateTimeOffset DeadTime(int attempts, TimeSpan? minDeadTimeout, TimeSpan? maxDeadTimeout) => throw new NotImplementedException();
2424
}

src/Elastic.Transport/Components/NodePool/Node.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public IReadOnlyCollection<string> Features
7171
public bool IsAlive { get; private set; }
7272

7373
/// <summary> When marked dead this reflects the date that the node has to be taken out of rotation till</summary>
74-
public DateTime DeadUntil { get; private set; }
74+
public DateTimeOffset DeadUntil { get; private set; }
7575

7676
/// <summary> The number of failed attempts trying to use this node, resets when a node is marked alive</summary>
7777
public int FailedAttempts { get; private set; }
@@ -85,17 +85,16 @@ public IReadOnlyCollection<string> Features
8585
/// </summary>
8686
public bool HasFeature(string feature) => _features.Count == 0 || _featureSet.Contains(feature);
8787

88-
8988
/// <summary>
90-
/// Marks this node as dead and set the date (see <paramref name="untill"/>) after which we want it to come back alive
89+
/// Marks this node as dead and set the date (see <paramref name="until"/>) after which we want it to come back alive
9190
/// </summary>
92-
/// <param name="untill">The <see cref="DateTime"/> after which this node should be considered alive again</param>
93-
public void MarkDead(DateTime untill)
91+
/// <param name="until">The <see cref="DateTime"/> after which this node should be considered alive again</param>
92+
public void MarkDead(DateTimeOffset until)
9493
{
9594
FailedAttempts++;
9695
IsAlive = false;
9796
IsResurrected = false;
98-
DeadUntil = untill;
97+
DeadUntil = until;
9998
}
10099

101100
/// <summary> Mark the node alive explicitly </summary>
@@ -104,20 +103,20 @@ public void MarkAlive()
104103
FailedAttempts = 0;
105104
IsAlive = true;
106105
IsResurrected = false;
107-
DeadUntil = default(DateTime);
106+
DeadUntil = default;
108107
}
109108

110109
/// <summary>
111110
/// Use the nodes uri as root to create a <see cref="Uri"/> with <paramref name="path"/>
112111
/// </summary>
113-
public Uri CreatePath(string path) => new Uri(Uri, path);
112+
public Uri CreatePath(string path) => new(Uri, path);
114113

115114
/// <summary>
116115
/// Create a clone of the current node. This is used by <see cref="NodePool"/> implementations that supports reseeding the
117116
/// list of nodes through <see cref="NodePool.Reseed"/>
118117
/// </summary>
119118
public Node Clone() =>
120-
new Node(Uri, Features)
119+
new(Uri, Features)
121120
{
122121
IsResurrected = IsResurrected,
123122
Id = Id,
@@ -146,7 +145,7 @@ public bool Equals(Node other)
146145
public static bool operator !=(Node left, Node right) => !(left == right);
147146

148147
/// <inheritdoc cref="Equals(Node)"/>
149-
public static implicit operator Node(Uri uri) => new Node(uri);
148+
public static implicit operator Node(Uri uri) => new(uri);
150149

151150
/// <inheritdoc cref="Equals(Node)"/>
152151
public override bool Equals(object obj)

src/Elastic.Transport/Components/NodePool/NodePool.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public abstract class NodePool : IDisposable
2020
{
2121
private bool _disposed;
2222

23+
internal NodePool() { }
24+
2325
/// <summary>
2426
/// The last time that this instance was updated.
2527
/// </summary>
26-
public abstract DateTime LastUpdate { get; protected set; }
28+
public abstract DateTimeOffset LastUpdate { get; protected set; }
2729

2830
/// <summary>
2931
/// Returns the default maximum retries for the connection pool implementation.

src/Elastic.Transport/Components/NodePool/SingleNodePool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public SingleNodePool(Uri uri, DateTimeProvider dateTimeProvider = null)
2121
}
2222

2323
/// <inheritdoc />
24-
public override DateTime LastUpdate { get; protected set; }
24+
public override DateTimeOffset LastUpdate { get; protected set; }
2525

2626
/// <inheritdoc />
2727
public override int MaxRetries => 0;

src/Elastic.Transport/Components/NodePool/StaticNodePool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void Initialize(IEnumerable<Node> nodes, DateTimeProvider dateTimeProvid
7979
}
8080

8181
/// <inheritdoc />
82-
public override DateTime LastUpdate { get; protected set; }
82+
public override DateTimeOffset LastUpdate { get; protected set; }
8383

8484
/// <inheritdoc />
8585
public override int MaxRetries => InternalNodes.Count - 1;

0 commit comments

Comments
 (0)