From 2687c98f63255c289e5765a729da35ac9dee7dff Mon Sep 17 00:00:00 2001 From: lemaitre-aneo Date: Wed, 17 Apr 2024 16:07:03 +0200 Subject: [PATCH] Add oldest started time gauge --- Common/src/Pollster/Pollster.cs | 22 ++++++++++++++++++++++ Common/src/Pollster/TaskHandler.cs | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/Common/src/Pollster/Pollster.cs b/Common/src/Pollster/Pollster.cs index cc1610dbb..98f75315c 100644 --- a/Common/src/Pollster/Pollster.cs +++ b/Common/src/Pollster/Pollster.cs @@ -132,6 +132,28 @@ public Pollster(IPullQueueStorage pullQueueStorage, "Tasks", "Number of tasks in the pipeline", meterHolder_.Tags); + + meterHolder.Meter.CreateObservableGauge("TaskRunningTime", + () => taskProcessingDict_.Values.MinBy(taskHandler => taskHandler.StartedAt) switch + { + null => 0.0, + // ReSharper disable once PatternAlwaysMatches + TaskHandler taskHandler => (DateTime.UtcNow - taskHandler.StartedAt).TotalMilliseconds, + }, + "Milliseconds", + "Running time of the oldest task still processing by the Pollster", + meterHolder_.Tags); + + meterHolder.Meter.CreateObservableGauge("TaskStartTime", + () => (taskProcessingDict_.Values.MinBy(taskHandler => taskHandler.StartedAt) switch + { + null => TimeSpan.MaxValue, + // ReSharper disable once PatternAlwaysMatches + TaskHandler taskHandler => taskHandler.StartedAt - DateTime.UnixEpoch, + }).TotalSeconds, + "Seconds", + "Start time of the oldest task still processing by the Pollster", + meterHolder_.Tags); } public ICollection TaskProcessing diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index e8504befb..294752965 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -142,6 +142,11 @@ public TaskHandler(ISessionTable sessionTable, registration2_ = workerConnectionCts_.Token.Register(() => logger_.LogWarning("Cancellation triggered, start to properly cancel task")); } + /// + /// Start date for the task handled by the current Task Handler + /// + public DateTime StartedAt { get; } = DateTime.UtcNow; + /// public async ValueTask DisposeAsync()