| | | 1 | | using ConsoleLogStreaming.Core; |
| | | 2 | | using ConsoleLogStreaming.Core.Models; |
| | | 3 | | using Elsa.Common.Entities; |
| | | 4 | | using Elsa.Common.Models; |
| | | 5 | | using Elsa.Dashboard.Api.Contracts; |
| | | 6 | | using Elsa.Dashboard.Api.Models; |
| | | 7 | | using Elsa.Diagnostics.StructuredLogs.Contracts; |
| | | 8 | | using Elsa.Diagnostics.StructuredLogs.Models; |
| | | 9 | | using Elsa.Workflows; |
| | | 10 | | using Elsa.Workflows.Management; |
| | | 11 | | using Elsa.Workflows.Management.Entities; |
| | | 12 | | using Elsa.Workflows.Management.Enums; |
| | | 13 | | using Elsa.Workflows.Management.Filters; |
| | | 14 | | using Elsa.Workflows.Management.Models; |
| | | 15 | | using Elsa.Workflows.Runtime; |
| | | 16 | | using Microsoft.Extensions.DependencyInjection; |
| | | 17 | | using Microsoft.Extensions.Hosting; |
| | | 18 | | |
| | | 19 | | namespace Elsa.Dashboard.Api.Services; |
| | | 20 | | |
| | 10 | 21 | | public class DefaultDashboardProvider( |
| | 10 | 22 | | IWorkflowInstanceStore workflowInstanceStore, |
| | 10 | 23 | | IWorkflowRuntimeAdminService runtimeAdminService, |
| | 10 | 24 | | DashboardRangeResolver rangeResolver, |
| | 10 | 25 | | IServiceProvider serviceProvider, |
| | 10 | 26 | | IHostEnvironment environment) : IDashboardProvider |
| | | 27 | | { |
| | | 28 | | public async Task<DashboardOverview> GetOverviewAsync(DashboardQuery query, CancellationToken cancellationToken = de |
| | | 29 | | { |
| | 4 | 30 | | var range = rangeResolver.Resolve(query.Range); |
| | 4 | 31 | | var runtime = GetRuntimeStatus(); |
| | 4 | 32 | | var workflowMetrics = await GetWorkflowMetricsAsync(range, query.IncludeSystem, cancellationToken); |
| | 4 | 33 | | var diagnostics = await GetDiagnosticsSummaryAsync(range, cancellationToken); |
| | | 34 | | |
| | 4 | 35 | | return new() |
| | 4 | 36 | | { |
| | 4 | 37 | | BackendName = environment.ApplicationName, |
| | 4 | 38 | | EnvironmentName = environment.EnvironmentName, |
| | 4 | 39 | | Runtime = runtime, |
| | 4 | 40 | | WorkflowInstances = workflowMetrics, |
| | 4 | 41 | | Diagnostics = diagnostics, |
| | 4 | 42 | | AppliedRange = range.Key, |
| | 4 | 43 | | From = range.From, |
| | 4 | 44 | | To = range.To |
| | 4 | 45 | | }; |
| | 4 | 46 | | } |
| | | 47 | | |
| | | 48 | | public async Task<DashboardTrendResponse> GetWorkflowTrendsAsync(DashboardTrendRequest request, CancellationToken ca |
| | | 49 | | { |
| | 1 | 50 | | var range = rangeResolver.Resolve(request.Range); |
| | 1 | 51 | | var granularity = rangeResolver.ResolveGranularity(request.Granularity, range.Key); |
| | 1 | 52 | | var bucketSize = rangeResolver.GetBucketSize(granularity); |
| | 1 | 53 | | var buckets = new List<DashboardTrendBucket>(); |
| | | 54 | | |
| | 50 | 55 | | for (var bucketFrom = range.From; bucketFrom < range.To; bucketFrom = bucketFrom.Add(bucketSize)) |
| | | 56 | | { |
| | 24 | 57 | | var bucketTo = Min(bucketFrom.Add(bucketSize), range.To); |
| | 24 | 58 | | buckets.Add(new() |
| | 24 | 59 | | { |
| | 24 | 60 | | From = bucketFrom, |
| | 24 | 61 | | To = bucketTo, |
| | 24 | 62 | | CreatedOrStarted = await CountAsync(request.IncludeSystem, nameof(WorkflowInstance.CreatedAt), bucketFro |
| | 24 | 63 | | Finished = await CountAsync(request.IncludeSystem, nameof(WorkflowInstance.FinishedAt), bucketFrom, buck |
| | 24 | 64 | | Faulted = await CountAsync(request.IncludeSystem, nameof(WorkflowInstance.UpdatedAt), bucketFrom, bucket |
| | 24 | 65 | | Suspended = await CountAsync(request.IncludeSystem, nameof(WorkflowInstance.UpdatedAt), bucketFrom, buck |
| | 24 | 66 | | IncidentBearing = await CountAsync(request.IncludeSystem, nameof(WorkflowInstance.UpdatedAt), bucketFrom |
| | 24 | 67 | | }); |
| | | 68 | | } |
| | | 69 | | |
| | 1 | 70 | | return new() |
| | 1 | 71 | | { |
| | 1 | 72 | | Buckets = buckets, |
| | 1 | 73 | | AppliedRange = range.Key, |
| | 1 | 74 | | Granularity = granularity, |
| | 1 | 75 | | From = range.From, |
| | 1 | 76 | | To = range.To |
| | 1 | 77 | | }; |
| | 1 | 78 | | } |
| | | 79 | | |
| | | 80 | | public async Task<DashboardNeedsAttentionResponse> GetNeedsAttentionAsync(DashboardQuery query, int take, Cancellati |
| | | 81 | | { |
| | 1 | 82 | | var range = rangeResolver.Resolve(query.Range); |
| | 1 | 83 | | var overview = await GetOverviewAsync(query, cancellationToken); |
| | 1 | 84 | | var findings = new List<DashboardFinding>(); |
| | | 85 | | |
| | 1 | 86 | | if (overview.Runtime.Status == DashboardRuntimeStatusKeys.Paused) |
| | 1 | 87 | | findings.Add(Finding("runtime-paused", DashboardFindingSeverity.Warning, "Runtime is paused", "Runtime", "ru |
| | 0 | 88 | | else if (overview.Runtime.Status == DashboardRuntimeStatusKeys.Draining) |
| | 0 | 89 | | findings.Add(Finding("runtime-draining", DashboardFindingSeverity.Warning, "Runtime is draining", "Runtime", |
| | | 90 | | |
| | 1 | 91 | | if (overview.Runtime.FailedIngressSourceCount > 0) |
| | 1 | 92 | | findings.Add(Finding("ingress-source-failures", DashboardFindingSeverity.Warning, $"{overview.Runtime.Failed |
| | | 93 | | |
| | 1 | 94 | | if (overview.WorkflowInstances.Faulted > 0) |
| | 1 | 95 | | findings.Add(Finding("workflow-faults", DashboardFindingSeverity.Error, $"{overview.WorkflowInstances.Faulte |
| | | 96 | | |
| | 1 | 97 | | if (overview.WorkflowInstances.Interrupted > 0) |
| | 0 | 98 | | findings.Add(Finding("workflow-interrupted", DashboardFindingSeverity.Warning, $"{overview.WorkflowInstances |
| | | 99 | | |
| | 1 | 100 | | if (overview.WorkflowInstances.IncidentBearing > 0) |
| | 1 | 101 | | findings.Add(Finding("workflow-incidents", DashboardFindingSeverity.Error, $"{overview.WorkflowInstances.Inc |
| | | 102 | | |
| | 1 | 103 | | var structuredLogs = overview.Diagnostics.StructuredLogs; |
| | 1 | 104 | | if (structuredLogs.StaleSourceCount > 0) |
| | 0 | 105 | | findings.Add(Finding("structured-log-stale-sources", DashboardFindingSeverity.Warning, $"{structuredLogs.Sta |
| | 1 | 106 | | if (structuredLogs.DroppedWriteCount > 0) |
| | 0 | 107 | | findings.Add(Finding("structured-log-dropped-writes", DashboardFindingSeverity.Error, "Structured log storag |
| | 1 | 108 | | if (structuredLogs.RecentErrorOrCriticalCount > 0) |
| | 1 | 109 | | findings.Add(Finding("structured-log-errors", DashboardFindingSeverity.Error, $"{structuredLogs.RecentErrorO |
| | | 110 | | |
| | 1 | 111 | | var consoleLogs = overview.Diagnostics.ConsoleLogs; |
| | 1 | 112 | | if (consoleLogs.StaleSourceCount > 0) |
| | 0 | 113 | | findings.Add(Finding("console-log-stale-sources", DashboardFindingSeverity.Warning, $"{consoleLogs.StaleSour |
| | 1 | 114 | | if (consoleLogs.DroppedLineCount > 0) |
| | 0 | 115 | | findings.Add(Finding("console-log-dropped-lines", DashboardFindingSeverity.Warning, "Console log capture dro |
| | | 116 | | |
| | 1 | 117 | | return new() |
| | 1 | 118 | | { |
| | 5 | 119 | | Findings = findings.OrderBy(x => x.Priority).Take(Math.Clamp(take, 1, 50)).ToList(), |
| | 1 | 120 | | AppliedRange = range.Key |
| | 1 | 121 | | }; |
| | 1 | 122 | | } |
| | | 123 | | |
| | | 124 | | public async Task<DashboardRecentActivityResponse> GetRecentActivityAsync(DashboardQuery query, int take, Cancellati |
| | | 125 | | { |
| | 1 | 126 | | var range = rangeResolver.Resolve(query.Range); |
| | 1 | 127 | | var filter = CreateRangeFilter(query.IncludeSystem, nameof(WorkflowInstance.UpdatedAt), range.From, range.To); |
| | 1 | 128 | | var order = new WorkflowInstanceOrder<DateTimeOffset?> |
| | 1 | 129 | | { |
| | 1 | 130 | | KeySelector = x => x.UpdatedAt, |
| | 1 | 131 | | Direction = OrderDirection.Descending |
| | 1 | 132 | | }; |
| | 1 | 133 | | var page = await workflowInstanceStore.SummarizeManyAsync(filter, PageArgs.FromPage(0, Math.Clamp(take, 1, 100)) |
| | | 134 | | |
| | 1 | 135 | | return new() |
| | 1 | 136 | | { |
| | 1 | 137 | | Items = page.Items.Select(MapRecentActivity).ToList(), |
| | 1 | 138 | | AppliedRange = range.Key, |
| | 1 | 139 | | From = range.From, |
| | 1 | 140 | | To = range.To |
| | 1 | 141 | | }; |
| | 1 | 142 | | } |
| | | 143 | | |
| | | 144 | | public async Task<DashboardWorkflowHotspotsResponse> GetWorkflowHotspotsAsync(DashboardWorkflowHotspotsRequest reque |
| | | 145 | | { |
| | 1 | 146 | | var range = rangeResolver.Resolve(request.Range); |
| | 1 | 147 | | var summaries = await workflowInstanceStore.SummarizeManyAsync(CreateRangeFilter(request.IncludeSystem, nameof(W |
| | 1 | 148 | | var metric = NormalizeHotspotMetric(request.Metric); |
| | 1 | 149 | | var hotspots = summaries |
| | 3 | 150 | | .GroupBy(x => x.DefinitionId) |
| | 2 | 151 | | .Select(x => CreateHotspot(x, metric)) |
| | 2 | 152 | | .OrderByDescending(x => x.Value) |
| | 2 | 153 | | .ThenBy(x => x.WorkflowName) |
| | 1 | 154 | | .Take(Math.Clamp(request.Take, 1, 50)) |
| | 1 | 155 | | .ToList(); |
| | | 156 | | |
| | 1 | 157 | | return new() |
| | 1 | 158 | | { |
| | 1 | 159 | | Items = hotspots, |
| | 1 | 160 | | AppliedRange = range.Key, |
| | 1 | 161 | | Metric = metric, |
| | 1 | 162 | | From = range.From, |
| | 1 | 163 | | To = range.To |
| | 1 | 164 | | }; |
| | 1 | 165 | | } |
| | | 166 | | |
| | | 167 | | private async Task<DashboardWorkflowInstanceMetrics> GetWorkflowMetricsAsync(DashboardRange range, bool includeSyste |
| | | 168 | | { |
| | 4 | 169 | | var completedSummaries = (await workflowInstanceStore.SummarizeManyAsync( |
| | 4 | 170 | | CreateRangeFilter(includeSystem, nameof(WorkflowInstance.FinishedAt), range.From, range.To, subStatus: Workf |
| | 4 | 171 | | cancellationToken)).ToList(); |
| | 4 | 172 | | var durations = completedSummaries |
| | 1 | 173 | | .Where(x => x.FinishedAt != null) |
| | 1 | 174 | | .Select(x => x.FinishedAt!.Value - x.CreatedAt) |
| | 1 | 175 | | .Where(x => x >= TimeSpan.Zero) |
| | 4 | 176 | | .ToList(); |
| | | 177 | | |
| | 4 | 178 | | return new() |
| | 4 | 179 | | { |
| | 4 | 180 | | Running = await CountAsync(includeSystem, status: WorkflowStatus.Running, cancellationToken: cancellationTok |
| | 4 | 181 | | Completed = completedSummaries.Count, |
| | 4 | 182 | | Faulted = await CountAsync(includeSystem, nameof(WorkflowInstance.UpdatedAt), range.From, range.To, cancella |
| | 4 | 183 | | Suspended = await CountAsync(includeSystem, subStatus: WorkflowSubStatus.Suspended, cancellationToken: cance |
| | 4 | 184 | | Interrupted = await CountAsync(includeSystem, nameof(WorkflowInstance.UpdatedAt), range.From, range.To, canc |
| | 4 | 185 | | IncidentBearing = await CountAsync(includeSystem, hasIncidents: true, cancellationToken: cancellationToken), |
| | 1 | 186 | | AverageDuration = durations.Count == 0 ? null : TimeSpan.FromTicks(Convert.ToInt64(durations.Average(x => x. |
| | 4 | 187 | | }; |
| | 4 | 188 | | } |
| | | 189 | | |
| | | 190 | | private DashboardRuntimeStatus GetRuntimeStatus() |
| | | 191 | | { |
| | 4 | 192 | | var status = runtimeAdminService.GetStatus(); |
| | 4 | 193 | | var state = status.State; |
| | 4 | 194 | | var runtimeStatus = state.IsAcceptingNewWork |
| | 4 | 195 | | ? DashboardRuntimeStatusKeys.AcceptingWork |
| | 4 | 196 | | : state.DrainStartedAt != null |
| | 4 | 197 | | ? DashboardRuntimeStatusKeys.Draining |
| | 4 | 198 | | : DashboardRuntimeStatusKeys.Paused; |
| | 5 | 199 | | var failedSourceCount = status.Sources.Count(x => x.LastError != null); |
| | | 200 | | |
| | 4 | 201 | | return new() |
| | 4 | 202 | | { |
| | 4 | 203 | | Status = runtimeStatus, |
| | 4 | 204 | | IsAcceptingWork = state.IsAcceptingNewWork, |
| | 4 | 205 | | ActiveExecutionCycleCount = status.ActiveExecutionCycleCount, |
| | 4 | 206 | | IngressSourceCount = status.Sources.Count, |
| | 4 | 207 | | FailedIngressSourceCount = failedSourceCount, |
| | 4 | 208 | | PausedAt = state.PausedAt, |
| | 4 | 209 | | DrainStartedAt = state.DrainStartedAt, |
| | 4 | 210 | | Reason = state.Reason.ToString() |
| | 4 | 211 | | }; |
| | | 212 | | } |
| | | 213 | | |
| | | 214 | | private async Task<DashboardDiagnosticsSummary> GetDiagnosticsSummaryAsync(DashboardRange range, CancellationToken c |
| | | 215 | | { |
| | 4 | 216 | | var structuredLogs = await GetStructuredLogSummaryAsync(range, cancellationToken); |
| | 4 | 217 | | var consoleLogs = await GetConsoleLogSummaryAsync(range, cancellationToken); |
| | 4 | 218 | | return new() |
| | 4 | 219 | | { |
| | 4 | 220 | | StructuredLogs = structuredLogs, |
| | 4 | 221 | | ConsoleLogs = consoleLogs |
| | 4 | 222 | | }; |
| | 4 | 223 | | } |
| | | 224 | | |
| | | 225 | | private async Task<DashboardStructuredLogSummary> GetStructuredLogSummaryAsync(DashboardRange range, CancellationTok |
| | | 226 | | { |
| | 4 | 227 | | var provider = serviceProvider.GetService<IStructuredLogProvider>(); |
| | 4 | 228 | | if (provider == null) |
| | 1 | 229 | | return new(); |
| | | 230 | | |
| | | 231 | | try |
| | | 232 | | { |
| | 3 | 233 | | var sources = await provider.ListSourcesAsync(cancellationToken); |
| | 2 | 234 | | var storageDiagnostics = serviceProvider.GetServices<IStructuredLogStorageDiagnostics>().ToList(); |
| | 2 | 235 | | var recentErrors = await provider.GetRecentAsync(new() |
| | 2 | 236 | | { |
| | 2 | 237 | | Levels = [StructuredLogLevel.Error, StructuredLogLevel.Critical], |
| | 2 | 238 | | From = range.From, |
| | 2 | 239 | | To = range.To, |
| | 2 | 240 | | Take = 1000 |
| | 2 | 241 | | }, cancellationToken); |
| | | 242 | | |
| | 2 | 243 | | return new() |
| | 2 | 244 | | { |
| | 2 | 245 | | Capability = DashboardCapabilityStatus.Available, |
| | 2 | 246 | | SourceCount = sources.Count, |
| | 1 | 247 | | StaleSourceCount = sources.Count(x => x.Status == StructuredLogSourceStatus.Stale || x.Status == Structu |
| | 2 | 248 | | RecentErrorOrCriticalCount = recentErrors.Items.Count, |
| | 1 | 249 | | DroppedWriteCount = storageDiagnostics.Aggregate(0L, (total, x) => checked(total + x.DroppedWriteCount)) |
| | 2 | 250 | | DroppedEventCount = recentErrors.DroppedEvents |
| | 2 | 251 | | }; |
| | | 252 | | } |
| | 1 | 253 | | catch (UnauthorizedAccessException) |
| | | 254 | | { |
| | 1 | 255 | | return new() { Capability = new(DashboardCapabilityStatus.Unauthorized.Status, "No access to structured logs |
| | | 256 | | } |
| | 0 | 257 | | catch (Exception e) when (e is not OperationCanceledException) |
| | | 258 | | { |
| | 0 | 259 | | return new() { Capability = new(DashboardCapabilityStatus.Unavailable.Status, "Structured log summary is una |
| | | 260 | | } |
| | 4 | 261 | | } |
| | | 262 | | |
| | | 263 | | private async Task<DashboardConsoleLogSummary> GetConsoleLogSummaryAsync(DashboardRange range, CancellationToken can |
| | | 264 | | { |
| | 4 | 265 | | var provider = serviceProvider.GetService<IConsoleLogProvider>(); |
| | 4 | 266 | | if (provider == null) |
| | 1 | 267 | | return new(); |
| | | 268 | | |
| | | 269 | | try |
| | | 270 | | { |
| | 3 | 271 | | var sources = await provider.ListSourcesAsync(cancellationToken); |
| | 2 | 272 | | var recentStderr = await provider.GetRecentAsync(new() |
| | 2 | 273 | | { |
| | 2 | 274 | | Stream = ConsoleStream.Stderr, |
| | 2 | 275 | | From = range.From, |
| | 2 | 276 | | To = range.To, |
| | 2 | 277 | | Limit = 1000 |
| | 2 | 278 | | }, cancellationToken); |
| | | 279 | | |
| | 2 | 280 | | return new() |
| | 2 | 281 | | { |
| | 2 | 282 | | Capability = DashboardCapabilityStatus.Available, |
| | 2 | 283 | | SourceCount = sources.Count, |
| | 1 | 284 | | StaleSourceCount = sources.Count(x => x.Health is ConsoleLogSourceHealth.Stale or ConsoleLogSourceHealth |
| | 2 | 285 | | RecentStderrCount = recentStderr.Items.Count, |
| | 0 | 286 | | DroppedLineCount = recentStderr.Dropped.Aggregate(0L, (total, x) => checked(total + x.Count)) |
| | 2 | 287 | | }; |
| | | 288 | | } |
| | 0 | 289 | | catch (UnauthorizedAccessException) |
| | | 290 | | { |
| | 0 | 291 | | return new() { Capability = new(DashboardCapabilityStatus.Unauthorized.Status, "No access to console logs") |
| | | 292 | | } |
| | 1 | 293 | | catch (Exception e) when (e is not OperationCanceledException) |
| | | 294 | | { |
| | 1 | 295 | | return new() { Capability = new(DashboardCapabilityStatus.Unavailable.Status, "Console log summary is unavai |
| | | 296 | | } |
| | 4 | 297 | | } |
| | | 298 | | |
| | | 299 | | private async Task<long> CountAsync( |
| | | 300 | | bool includeSystem, |
| | | 301 | | string? timestampColumn = null, |
| | | 302 | | DateTimeOffset? from = null, |
| | | 303 | | DateTimeOffset? to = null, |
| | | 304 | | CancellationToken cancellationToken = default, |
| | | 305 | | WorkflowStatus? status = null, |
| | | 306 | | WorkflowSubStatus? subStatus = null, |
| | | 307 | | bool? hasIncidents = null) |
| | | 308 | | { |
| | 140 | 309 | | return await workflowInstanceStore.CountAsync(CreateRangeFilter(includeSystem, timestampColumn, from, to, status |
| | 140 | 310 | | } |
| | | 311 | | |
| | | 312 | | private static WorkflowInstanceFilter CreateRangeFilter( |
| | | 313 | | bool includeSystem, |
| | | 314 | | string? timestampColumn, |
| | | 315 | | DateTimeOffset? from, |
| | | 316 | | DateTimeOffset? to, |
| | | 317 | | WorkflowStatus? status = null, |
| | | 318 | | WorkflowSubStatus? subStatus = null, |
| | | 319 | | bool? hasIncidents = null) |
| | | 320 | | { |
| | 146 | 321 | | var timestampFilters = new List<TimestampFilter>(); |
| | 146 | 322 | | if (timestampColumn != null && from != null) |
| | 134 | 323 | | timestampFilters.Add(new() { Column = timestampColumn, Operator = TimestampFilterOperator.GreaterThanOrEqual |
| | 146 | 324 | | if (timestampColumn != null && to != null) |
| | 134 | 325 | | timestampFilters.Add(new() { Column = timestampColumn, Operator = TimestampFilterOperator.LessThan, Timestam |
| | | 326 | | |
| | 146 | 327 | | return new() |
| | 146 | 328 | | { |
| | 146 | 329 | | IsSystem = includeSystem ? null : false, |
| | 146 | 330 | | WorkflowStatus = status, |
| | 146 | 331 | | WorkflowSubStatus = subStatus, |
| | 146 | 332 | | HasIncidents = hasIncidents, |
| | 146 | 333 | | TimestampFilters = timestampFilters.Count == 0 ? null : timestampFilters |
| | 146 | 334 | | }; |
| | | 335 | | } |
| | | 336 | | |
| | 2 | 337 | | private static DashboardRecentActivityItem MapRecentActivity(WorkflowInstanceSummary summary) => new() |
| | 2 | 338 | | { |
| | 2 | 339 | | InstanceId = summary.Id, |
| | 2 | 340 | | DefinitionId = summary.DefinitionId, |
| | 2 | 341 | | WorkflowName = summary.Name, |
| | 2 | 342 | | Status = summary.Status.ToString(), |
| | 2 | 343 | | SubStatus = summary.SubStatus.ToString(), |
| | 2 | 344 | | IncidentCount = summary.IncidentCount, |
| | 2 | 345 | | Duration = summary.FinishedAt == null ? null : summary.FinishedAt.Value - summary.CreatedAt, |
| | 2 | 346 | | CreatedAt = summary.CreatedAt, |
| | 2 | 347 | | UpdatedAt = summary.UpdatedAt, |
| | 2 | 348 | | FinishedAt = summary.FinishedAt |
| | 2 | 349 | | }; |
| | | 350 | | |
| | | 351 | | private static DashboardHotspot CreateHotspot(IGrouping<string, WorkflowInstanceSummary> group, string metric) |
| | | 352 | | { |
| | 2 | 353 | | var items = group.ToList(); |
| | 2 | 354 | | var durations = items |
| | 3 | 355 | | .Where(x => x.FinishedAt != null) |
| | 1 | 356 | | .Select(x => x.FinishedAt!.Value - x.CreatedAt) |
| | 1 | 357 | | .Where(x => x >= TimeSpan.Zero) |
| | 2 | 358 | | .ToList(); |
| | 2 | 359 | | var value = metric switch |
| | 2 | 360 | | { |
| | 0 | 361 | | DashboardHotspotMetric.Executions => items.Count, |
| | 5 | 362 | | DashboardHotspotMetric.Incidents => items.Sum(x => x.IncidentCount), |
| | 0 | 363 | | DashboardHotspotMetric.Duration => durations.Count == 0 ? 0 : Convert.ToInt64(durations.Average(x => x.Total |
| | 0 | 364 | | _ => items.LongCount(x => x.SubStatus == WorkflowSubStatus.Faulted) |
| | 2 | 365 | | }; |
| | | 366 | | |
| | 2 | 367 | | return new() |
| | 2 | 368 | | { |
| | 2 | 369 | | DefinitionId = group.Key, |
| | 4 | 370 | | WorkflowName = items.Select(x => x.Name).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)), |
| | 2 | 371 | | Value = value, |
| | 1 | 372 | | AverageDuration = durations.Count == 0 ? null : TimeSpan.FromTicks(Convert.ToInt64(durations.Average(x => x. |
| | 2 | 373 | | }; |
| | | 374 | | } |
| | | 375 | | |
| | | 376 | | private static string NormalizeHotspotMetric(string? metric) => |
| | 1 | 377 | | metric?.Trim().ToLowerInvariant() switch |
| | 1 | 378 | | { |
| | 0 | 379 | | "executions" => DashboardHotspotMetric.Executions, |
| | 1 | 380 | | "incidents" => DashboardHotspotMetric.Incidents, |
| | 0 | 381 | | "duration" => DashboardHotspotMetric.Duration, |
| | 0 | 382 | | _ => DashboardHotspotMetric.Faults |
| | 1 | 383 | | }; |
| | | 384 | | |
| | 5 | 385 | | private static DashboardFinding Finding(string id, string severity, string message, string? targetKind, string? targ |
| | 5 | 386 | | { |
| | 5 | 387 | | Id = id, |
| | 5 | 388 | | Severity = severity, |
| | 5 | 389 | | Message = message, |
| | 5 | 390 | | TargetKind = targetKind, |
| | 5 | 391 | | Target = target, |
| | 5 | 392 | | Priority = priority |
| | 5 | 393 | | }; |
| | | 394 | | |
| | 24 | 395 | | private static DateTimeOffset Min(DateTimeOffset left, DateTimeOffset right) => left <= right ? left : right; |
| | | 396 | | } |