Skip to content

Commit e15c9f4

Browse files
authored
even more xml docs, nullability change in OT, parameter rename in Persistence (#1699)
1 parent 9017e6e commit e15c9f4

11 files changed

+241
-40
lines changed

src/Proto.OpenTelemetry/OpenTelemetryDecorators.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public OpenTelemetryRootContextDecorator(IRootContext context, ActivitySetup sen
1616
=> _sendActivitySetup = (activity, message)
1717
=> {
1818
activity?.SetTag(ProtoTags.ActorType, "<None>");
19-
sendActivitySetup(activity, message);
19+
if(activity != null)
20+
sendActivitySetup(activity, message);
2021
};
2122

2223
private static string Source => "Root";
@@ -55,13 +56,15 @@ ActivitySetup receiveActivitySetup
5556
activity?.SetTag(ProtoTags.ActorType, actorType);
5657
activity?.SetTag(ProtoTags.ActorPID, self);
5758
activity?.SetTag(ProtoTags.SenderPID, self);
58-
sendActivitySetup(activity, message);
59+
if(activity != null)
60+
sendActivitySetup(activity, message);
5961
};
6062
_receiveActivitySetup = (activity, message) => {
6163
activity?.SetTag(ProtoTags.ActorType, actorType);
6264
activity?.SetTag(ProtoTags.ActorPID, self);
6365
activity?.SetTag(ProtoTags.TargetPID, self);
64-
receiveActivitySetup(activity, message);
66+
if(activity != null)
67+
receiveActivitySetup(activity, message);
6568
};
6669
}
6770

@@ -208,7 +211,8 @@ internal static async Task Receive(string source, MessageEnvelope envelope, Acti
208211
{
209212
if (envelope.Sender != null) activity?.SetTag(ProtoTags.SenderPID, envelope.Sender.ToString());
210213

211-
receiveActivitySetup?.Invoke(activity, message);
214+
if(activity != null)
215+
receiveActivitySetup?.Invoke(activity, message);
212216

213217
await receive().ConfigureAwait(false);
214218
}

src/Proto.OpenTelemetry/OpenTelemetryMetricsExtensions.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ namespace Proto.OpenTelemetry;
1010

1111
public static class OpenTelemetryMetricsExtensions
1212
{
13+
/// <summary>
14+
/// Histogram buckets definition for request-like operations
15+
/// </summary>
1316
public static readonly double[] RequestLikeHistogramBoundaries =
1417
{.002, .005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10, 20, 30};
1518

19+
/// <summary>
20+
/// Histogram buckets definition for queue length
21+
/// </summary>
1622
public static readonly double[] QueueLengthHistogramBoundaries =
1723
{0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000};
1824

1925
/// <summary>
20-
/// Adds Proto.Actor meter to the MeterProviderBuilder
26+
/// Adds Proto.Actor metrics to the <see cref="MeterProviderBuilder"/>
2127
/// </summary>
2228
/// <param name="builder"></param>
2329
/// <param name="useRecommendedHistogramBoundaries">If true, views will be added for histogram metrics to specify recommended histogram boundaries.</param>
@@ -59,10 +65,14 @@ public static MeterProviderBuilder AddProtoActorInstrumentation(this MeterProvid
5965
builder.AddView("protocluster_identity_get_with_global_lock_duration",
6066
new ExplicitBucketHistogramConfiguration {Boundaries = RequestLikeHistogramBoundaries}
6167
);
62-
68+
6369
builder.AddView("protocluster_identity_try_acquire_lock_duration",
6470
new ExplicitBucketHistogramConfiguration {Boundaries = RequestLikeHistogramBoundaries}
6571
);
72+
73+
builder.AddView("protoremote_write_duration",
74+
new ExplicitBucketHistogramConfiguration {Boundaries = RequestLikeHistogramBoundaries}
75+
);
6676
}
6777

6878
return builder;

src/Proto.OpenTelemetry/OpenTelemetryTracingExtensions.cs

+17-10
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33

44
namespace Proto.OpenTelemetry;
55

6-
public delegate void ActivitySetup(Activity? activity, object message);
6+
/// <summary>
7+
/// Customizes the activity based on a message being processed
8+
/// <param name="activity">Activity to be customized</param>
9+
/// <param name="message">Message being processed</param>
10+
/// </summary>
11+
public delegate void ActivitySetup(Activity activity, object message);
712

813
public static class OpenTelemetryTracingExtensions
914
{
1015
public static TracerProviderBuilder AddProtoActorInstrumentation(this TracerProviderBuilder builder)
1116
=> builder.AddSource(ProtoTags.ActivitySourceName);
1217

1318
/// <summary>
14-
/// Setup OpenTelemetry send middleware & decorator.
19+
/// Adds OpenTelemetry tracing to actors spawned with given <see cref="Props"/>. Incoming and outgoing messages will create new activities.
20+
/// Ensures <see cref="Activity"/> context propagation via message headers.
1521
/// </summary>
16-
/// <param name="props">props.</param>
17-
/// <param name="sendActivitySetup">provide a way inject send activity customization according to the message.</param>
18-
/// <param name="receiveActivitySetup">provide a way inject receive activity customization according to the message.</param>
22+
/// <param name="props"><see cref="Props"/> to instrument</param>
23+
/// <param name="sendActivitySetup">Optional delegate to customize the <see cref="Activity"/> on message receive</param>
24+
/// <param name="receiveActivitySetup">Optional delegate to customize the <see cref="Activity"/> on message send</param>
1925
/// <returns>props</returns>
2026
public static Props WithTracing(
2127
this Props props,
@@ -31,7 +37,7 @@ public static Props WithTracing(
3137
}
3238

3339
/// <summary>
34-
/// Adds trace headers to the message envelope, to propagate trace context.
40+
/// Adds trace headers to the message envelope, to propagate trace context.
3541
/// </summary>
3642
public static Sender OpenTelemetrySenderMiddleware(Sender next)
3743
=> async (context, target, envelope) => {
@@ -46,11 +52,12 @@ public static Sender OpenTelemetrySenderMiddleware(Sender next)
4652
};
4753

4854
/// <summary>
49-
/// Setup OpenTelemetry send decorator around RootContext.
55+
/// Adds OpenTelemetry tracing to messages sent through <see cref="IRootContext"/>. Sent messages will create new activities.
56+
/// Ensures <see cref="Activity"/> context propagation via message headers.
5057
/// </summary>
51-
/// <param name="context">Root context</param>
52-
/// <param name="sendActivitySetup">provide a way inject send activity customization according to the message.</param>
53-
/// <returns>IRootContext</returns>
58+
/// <param name="context"><see cref="IRootContext"/> to instrument</param>
59+
/// <param name="sendActivitySetup">Optional delegate to customize the <see cref="Activity"/> on message send</param>
60+
/// <returns></returns>
5461
public static IRootContext WithTracing(this IRootContext context, ActivitySetup? sendActivitySetup = null)
5562
{
5663
sendActivitySetup ??= OpenTelemetryHelpers.DefaultSetupActivity!;

src/Proto.OpenTelemetry/ProtoTags.cs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
namespace Proto.OpenTelemetry;
1+
using System.Diagnostics;
22

3+
namespace Proto.OpenTelemetry;
4+
5+
/// <summary>
6+
/// Proto.actor specific tags on the <see cref="Activity"/>
7+
/// </summary>
38
public static class ProtoTags
49
{
10+
/// <summary>
11+
/// Activity source name for Proto.Actor created activities
12+
/// </summary>
513
public const string ActivitySourceName = "Proto.Actor";
614

715
/// <summary>
8-
/// GetType().Name on the message
16+
/// GetType().Name on the message
917
/// </summary>
1018
public const string MessageType = "proto.messagetype";
1119

1220
/// <summary>
13-
/// Message destination
21+
/// Message destination PID string representation
1422
/// </summary>
1523
public const string TargetPID = "proto.targetpid";
1624

1725
/// <summary>
18-
/// Message origin
26+
/// Message sender PID string representation
1927
/// </summary>
2028
public const string SenderPID = "proto.senderpid";
2129

2230
/// <summary>
23-
/// Current actor PID, when applicable (equals TargetPID when this is a receive activity, or SenderId when this is a
24-
/// sending activity)
31+
/// Current actor PID string representation, when applicable (equals TargetPID when this is a receive activity, or SenderId when this is a
32+
/// sending activity)
2533
/// </summary>
2634
public const string ActorPID = "proto.actorpid";
2735

2836
/// <summary>
29-
/// Type of the current actor, when applicable
37+
/// Type of the current actor, when applicable
3038
/// </summary>
3139
public const string ActorType = "proto.actortype";
3240
}

src/Proto.Persistence/IProvider.cs

+54-6
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,72 @@
88

99
namespace Proto.Persistence;
1010

11+
/// <summary>
12+
/// Abstraction for the snapshot storage
13+
/// </summary>
1114
public interface ISnapshotStore
1215
{
13-
Task<(object? Snapshot, long Index)> GetSnapshotAsync(string actorName);
16+
/// <summary>
17+
/// Gets the last available snapshot for the specified actor
18+
/// </summary>
19+
/// <param name="actorId">Unique actor identifier</param>
20+
/// <returns>A tuple of (<see cref="Snapshot"/>, last event index included in the snapshot + 1)</returns>
21+
Task<(object? Snapshot, long Index)> GetSnapshotAsync(string actorId);
1422

15-
Task PersistSnapshotAsync(string actorName, long index, object snapshot);
23+
/// <summary>
24+
/// Stores a new snapshot for the specified actor
25+
/// </summary>
26+
/// <param name="actorId">Unique actor identifier</param>
27+
/// <param name="index">Last event included in the snapshot + 1</param>
28+
/// <param name="snapshot">Snapshot to store</param>
29+
/// <returns></returns>
30+
Task PersistSnapshotAsync(string actorId, long index, object snapshot);
1631

17-
Task DeleteSnapshotsAsync(string actorName, long inclusiveToIndex);
32+
/// <summary>
33+
/// Deletes snapshots for the specified actor
34+
/// </summary>
35+
/// <param name="actorId">Unique actor identifier</param>
36+
/// <param name="inclusiveToIndex">Index stored along the snapshot has to be &lt;= to the value in this parameter for the snapshot to be deleted</param>
37+
/// <returns></returns>
38+
Task DeleteSnapshotsAsync(string actorId, long inclusiveToIndex);
1839
}
1940

41+
/// <summary>
42+
/// Abstraction for event storage. Responsible for writing and retrieving event streams.
43+
/// </summary>
2044
public interface IEventStore
2145
{
22-
Task<long> GetEventsAsync(string actorName, long indexStart, long indexEnd, Action<object> callback);
46+
/// <summary>
47+
/// Gets a stream of events for particular actor
48+
/// </summary>
49+
/// <param name="actorId">Unique actor identifier</param>
50+
/// <param name="indexStart">Index of the first event to get (inclusive)</param>
51+
/// <param name="indexEnd">Index of the last event to get (inclusive)</param>
52+
/// <param name="callback">A callback which should be called for each read event, in the order the events are stored</param>
53+
/// <returns>Index of the last read event or -1 if none</returns>
54+
Task<long> GetEventsAsync(string actorId, long indexStart, long indexEnd, Action<object> callback);
2355

24-
Task<long> PersistEventAsync(string actorName, long index, object @event);
56+
/// <summary>
57+
/// Writes an event to event stream of particular actor
58+
/// </summary>
59+
/// <param name="actorId">Unique actor identifier</param>
60+
/// <param name="index">Expected index this event should be written at. This can be used for optimistic concurrency, although most providers don't do that</param>
61+
/// <param name="event">Event to be written</param>
62+
/// <returns>Index for the next event</returns>
63+
Task<long> PersistEventAsync(string actorId, long index, object @event);
2564

26-
Task DeleteEventsAsync(string actorName, long inclusiveToIndex);
65+
/// <summary>
66+
/// Deletes events from actor's event stream starting with the oldest available, ending at provided index
67+
/// </summary>
68+
/// <param name="actorId">Unique actor identifier</param>
69+
/// <param name="inclusiveToIndex">Inclusive index of the last event to delete</param>
70+
/// <returns></returns>
71+
Task DeleteEventsAsync(string actorId, long inclusiveToIndex);
2772
}
2873

74+
/// <summary>
75+
/// Abstraction for persistence provider
76+
/// </summary>
2977
public interface IProvider : IEventStore, ISnapshotStore
3078
{
3179
}

src/Proto.Persistence/ISnapshotStrategy.cs

+8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
// -----------------------------------------------------------------------
66
namespace Proto.Persistence;
77

8+
/// <summary>
9+
/// A strategy that decides at what points in time to take snapshots
10+
/// </summary>
811
public interface ISnapshotStrategy
912
{
13+
/// <summary>
14+
/// Returns true if for given <see cref="PersistedEvent"/> a snapshot should be stored
15+
/// </summary>
16+
/// <param name="persistedEvent">Event being persisted along with its index</param>
17+
/// <returns>True if snapshot should be stored</returns>
1018
bool ShouldTakeSnapshot(PersistedEvent persistedEvent);
1119
}

src/Proto.Persistence/Messages.cs

+37-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// -----------------------------------------------------------------------
66
namespace Proto.Persistence;
77

8+
/// <summary>
9+
/// Actor's persistent event
10+
/// </summary>
811
public class Event
912
{
1013
public Event(object data, long index)
@@ -13,24 +16,40 @@ public Event(object data, long index)
1316
Index = index;
1417
}
1518

19+
/// <summary>
20+
/// Event data
21+
/// </summary>
1622
public object Data { get; }
23+
24+
/// <summary>
25+
/// Event index
26+
/// </summary>
1727
public long Index { get; }
1828
}
1929

30+
/// <summary>
31+
/// Represents snapshot to be persisted
32+
/// </summary>
2033
public class PersistedSnapshot : Snapshot
2134
{
2235
public PersistedSnapshot(object state, long index) : base(state, index)
2336
{
2437
}
2538
}
2639

40+
/// <summary>
41+
/// Represents snapshot that is being recovered
42+
/// </summary>
2743
public class RecoverSnapshot : Snapshot
2844
{
2945
public RecoverSnapshot(object state, long index) : base(state, index)
3046
{
3147
}
3248
}
33-
49+
50+
/// <summary>
51+
/// Wrapper for persistent snapshot
52+
/// </summary>
3453
public class Snapshot
3554
{
3655
public Snapshot(object state, long index)
@@ -39,25 +58,40 @@ public Snapshot(object state, long index)
3958
Index = index;
4059
}
4160

61+
/// <summary>
62+
/// Snapshot data
63+
/// </summary>
4264
public object State { get; }
65+
66+
/// <summary>
67+
/// Index of the last event included in the snapshot + 1
68+
/// </summary>
4369
public long Index { get; }
4470
}
45-
46-
71+
72+
/// <summary>
73+
/// Represents an event being recovered
74+
/// </summary>
4775
public class RecoverEvent : Event
4876
{
4977
public RecoverEvent(object data, long index) : base(data, index)
5078
{
5179
}
5280
}
5381

82+
/// <summary>
83+
/// Represents an event being replayed
84+
/// </summary>
5485
public class ReplayEvent : Event
5586
{
5687
public ReplayEvent(object data, long index) : base(data, index)
5788
{
5889
}
5990
}
6091

92+
/// <summary>
93+
/// Represents an event being stored
94+
/// </summary>
6195
public class PersistedEvent : Event
6296
{
6397
public PersistedEvent(object data, long index) : base(data, index)

0 commit comments

Comments
 (0)