Beispiel #1
0
        private void SaveExecutionHistoryEntries(UIHealthReport healthReport, HealthCheckExecution execution, DateTime lastExecutionTime)
        {
            _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values.");

            foreach (var item in execution.Entries)
            {
                // If the health service is down, no entry in dictionary
                if (healthReport.Entries.TryGetValue(item.Name, out var reportEntry))
                {
                    if (item.Status != reportEntry.Status)
                    {
                        execution.History.Add(new HealthCheckExecutionHistory()
                        {
                            On          = lastExecutionTime,
                            Status      = reportEntry.Status,
                            Name        = item.Name,
                            Description = reportEntry.Description
                        });
                    }
                }
            }

            execution.OnStateFrom  = lastExecutionTime;
            execution.LastExecuted = lastExecutionTime;
            execution.Status       = healthReport.Status;
        }
        private async Task SaveExecutionHistory(HealthCheckConfiguration configuration, UIHealthReport healthReport)
        {
            _logger.LogDebug("HealthReportCollector - health report execution history saved.");

            var execution = await GetHealthCheckExecution(configuration);

            var lastExecutionTime = DateTime.UtcNow;

            if (execution != null)
            {
                execution.Entries.Clear();
                execution.Entries = healthReport.ToExecutionEntries();

                if (execution.Status == healthReport.Status)
                {
                    _logger.LogDebug("HealthReport history already exists and is in the same state, updating the values.");

                    execution.LastExecuted = lastExecutionTime;
                }
                else
                {
                    _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values.");

                    execution.History.Add(new HealthCheckExecutionHistory()
                    {
                        On     = lastExecutionTime,
                        Status = execution.Status
                    });

                    execution.OnStateFrom  = lastExecutionTime;
                    execution.LastExecuted = lastExecutionTime;
                    execution.Status       = healthReport.Status;
                }
            }
            else
            {
                _logger.LogDebug("Creating a new HealthReport history.");

                execution = new HealthCheckExecution()
                {
                    LastExecuted     = lastExecutionTime,
                    OnStateFrom      = lastExecutionTime,
                    Entries          = healthReport.ToExecutionEntries(),
                    Status           = healthReport.Status,
                    Name             = configuration.Name,
                    Uri              = configuration.Uri,
                    DiscoveryService = configuration.DiscoveryService
                };

                await _db.Executions
                .AddAsync(execution);
            }

            await _db.SaveChangesAsync();
        }
        private async Task SaveExecutionHistory(HealthCheckConfiguration configuration, UIHealthReport healthReport)
        {
            _logger.LogDebug("HealthReportCollector - health report execution history saved.");

            var execution = await GetHealthCheckExecution(configuration);

            var lastExecutionTime = DateTime.UtcNow;

            if (execution != null)
            {
                //update existing entries from new health report

                foreach (var item in healthReport.ToExecutionEntries())
                {
                    var existing = execution.Entries
                                   .Where(e => e.Name == item.Name)
                                   .SingleOrDefault();

                    if (existing != null)
                    {
                        existing.Status      = item.Status;
                        existing.Description = item.Description;
                        existing.Duration    = item.Duration;
                    }
                    else
                    {
                        execution.Entries.Add(item);
                    }
                }

                //remove old entries in existing execution not present in new health report

                foreach (var item in execution.Entries)
                {
                    var existing = healthReport.Entries
                                   .ContainsKey(item.Name);

                    if (!existing)
                    {
                        var oldEntry = execution.Entries
                                       .Where(t => t.Name == item.Name)
                                       .SingleOrDefault();

                        _db.HealthCheckExecutionEntries
                        .Remove(oldEntry);
                    }
                }

                if (execution.Status == healthReport.Status)
                {
                    _logger.LogDebug("HealthReport history already exists and is in the same state, updating the values.");

                    execution.LastExecuted = lastExecutionTime;
                }
                else
                {
                    _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values.");

                    execution.History.Add(new HealthCheckExecutionHistory()
                    {
                        On     = lastExecutionTime,
                        Status = execution.Status
                    });

                    execution.OnStateFrom  = lastExecutionTime;
                    execution.LastExecuted = lastExecutionTime;
                    execution.Status       = healthReport.Status;
                }
            }
            else
            {
                _logger.LogDebug("Creating a new HealthReport history.");

                execution = new HealthCheckExecution()
                {
                    LastExecuted     = lastExecutionTime,
                    OnStateFrom      = lastExecutionTime,
                    Entries          = healthReport.ToExecutionEntries(),
                    Status           = healthReport.Status,
                    Name             = configuration.Name,
                    Uri              = configuration.Uri,
                    DiscoveryService = configuration.DiscoveryService
                };

                await _db.Executions
                .AddAsync(execution);
            }

            await _db.SaveChangesAsync();
        }
Beispiel #4
0
 private void UpdateUris(HealthCheckExecution execution, HealthCheckConfiguration configuration)
 {
     execution.Uri = configuration.Uri;
     endpointAddresses.Remove(configuration.Id);
 }