Skip to content

Commit a9896c9

Browse files
committed
feat: Improve SubscriberClient logging
- Add a client index (1-N) for each individual API client within a SubscriberClient, to make it clearer what's going on - Reduce the log level for recoverable errors to Debug (as usually there's no action required)
1 parent 4b2b2ef commit a9896c9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

‎apis/Google.Cloud.PubSub.V1/Google.Cloud.PubSub.V1/SubscriberClientImpl.SingleChannel.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ internal RetryInfo(DateTime firstTimeOfFailureInUtc, TimeSpan? backoff = null)
155155
private readonly TimeSpan _maxExtensionDuration; // Maximum duration for which a message lease will be extended.
156156
private readonly int _maxAckExtendQueueSize; // Soft limit on push queue sizes. Used to throttle pulls.
157157
private readonly int _maxAckExtendSendCount; // Maximum number of ids to include in an ack/nack/extend push RPC.
158-
private readonly int _maxConcurrentPush; // Mamimum number (slightly soft) of concurrent ack/nack/extend push RPCs.
158+
private readonly int _maxConcurrentPush; // Maximum number (slightly soft) of concurrent ack/nack/extend push RPCs.
159159

160160
private readonly Flow _flow;
161161
private readonly bool _useLegacyFlowControl;
@@ -178,9 +178,10 @@ internal RetryInfo(DateTime firstTimeOfFailureInUtc, TimeSpan? backoff = null)
178178
private bool _messageOrderingEnabled = false; // True if subscription has ordering enabled, else false.
179179
private readonly RetryState _retryState;
180180
private readonly ILogger _logger;
181+
private readonly int _clientIndex; // The index of this client within the overall SubscriberClient, in the range 1-ClientCount. Only used for logging.
181182

182183
internal SingleChannel(SubscriberClientImpl subscriber,
183-
SubscriberServiceApiClient client, SubscriptionHandler handler,
184+
SubscriberServiceApiClient client, int clientIndex, SubscriptionHandler handler,
184185
Flow flow, bool useLegacyFlowControl,
185186
Action<Task> registerTaskFn,
186187
IClock clock)
@@ -190,6 +191,7 @@ internal SingleChannel(SubscriberClientImpl subscriber,
190191
_scheduler = subscriber._scheduler;
191192
_clock = subscriber._clock;
192193
_client = client;
194+
_clientIndex = clientIndex;
193195
_handler = handler;
194196
_hardStopCts = subscriber._globalHardStopCts;
195197
_pushStopCts = CancellationTokenSource.CreateLinkedTokenSource(_hardStopCts.Token);
@@ -303,7 +305,7 @@ private void StartStreamingPull()
303305
if (_retryState.Backoff is TimeSpan backoff)
304306
{
305307
// Delay, then start the streaming-pull.
306-
_logger?.LogDebug("Delaying for {seconds}s before streaming pull call.", (int) backoff.TotalSeconds);
308+
_logger?.LogDebug("Client {index} delaying for {seconds}s before streaming pull call.", _clientIndex, (int) backoff.TotalSeconds);
307309
Task delayTask = _scheduler.Delay(backoff, _softStopCts.Token);
308310
Add(delayTask, Next(true, HandleStartStreamingPullWithoutBackoff));
309311
}
@@ -353,7 +355,7 @@ private void RestartPullOrThrow(Exception e)
353355
/// </summary>
354356
private void RestartPullAfterRetriableFailure(Exception e)
355357
{
356-
_logger?.LogWarning(e, "Recoverable error in streaming pull; will retry.");
358+
_logger?.LogDebug(e, "Recoverable error in streaming pull for client {index}; will retry.", _clientIndex);
357359
// Update the retry state, increasing the backoff etc.
358360
_retryState.OnFailure(e);
359361
StopStreamingPull();

‎apis/Google.Cloud.PubSub.V1/Google.Cloud.PubSub.V1/SubscriberClientImpl.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public override Task StartAsync(SubscriptionHandler handler)
133133
Flow flow = new Flow(_flowControlSettings.MaxOutstandingByteCount ?? long.MaxValue,
134134
_flowControlSettings.MaxOutstandingElementCount ?? long.MaxValue, registerTask, _taskHelper);
135135
// Start all subscribers
136-
var subscriberTasks = _clients.Select(client =>
136+
var subscriberTasks = _clients.Select((client, index) =>
137137
{
138-
var singleChannel = new SingleChannel(this, client, handler, flow, _useLegacyFlowControl, registerTask, _clock);
138+
var singleChannel = new SingleChannel(this, client, index + 1, handler, flow, _useLegacyFlowControl, registerTask, _clock);
139139
return _taskHelper.Run(() => singleChannel.StartAsync());
140140
}).ToArray();
141141
// Set up finish task; code that executes when this subscriber is being shutdown (for whatever reason).

0 commit comments

Comments
 (0)