Skip to content

Commit

Permalink
feat: Metrics for task running time (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemaitre-aneo authored Apr 22, 2024
2 parents bc7d2ed + 2687c98 commit 991bd56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Common/src/Pollster/Pollster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> TaskProcessing
Expand Down
5 changes: 5 additions & 0 deletions Common/src/Pollster/TaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public TaskHandler(ISessionTable sessionTable,
registration2_ = workerConnectionCts_.Token.Register(() => logger_.LogWarning("Cancellation triggered, start to properly cancel task"));
}

/// <summary>
/// Start date for the task handled by the current Task Handler
/// </summary>
public DateTime StartedAt { get; } = DateTime.UtcNow;


/// <inheritdoc />
public async ValueTask DisposeAsync()
Expand Down

0 comments on commit 991bd56

Please sign in to comment.