public async Task AddAsync(string name, string uri) { if (await Get(name) == null) { await _db.Configurations.AddAsync(new HealthCheckConfiguration { Name = name, Uri = uri, DiscoveryService = "kubernetes" }); await _db.SaveChangesAsync(); _logger.LogInformation("[Push] New service added: {name} with uri: {uri}", name, uri); } }
private async Task SaveNotification(HealthCheckFailureNotification notification) { if (notification != null) { await _db.Failures .AddAsync(notification); 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) { 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(); }
Task <int> RegisterDiscoveredLiveness(HealthChecksDb livenessDb, string host, string name) { livenessDb.Configurations.Add(new HealthCheckConfiguration() { Name = name, Uri = host, DiscoveryService = "kubernetes" }); return(livenessDb.SaveChangesAsync()); }
async Task RegisterDiscoveredLiveness(string service, string name, Uri uri, CancellationToken cancellationToken) { _db.Configurations.Add(new HealthCheckConfiguration { Name = name, Uri = uri.ToString(), DiscoveryService = service }); await _db.SaveChangesAsync(cancellationToken); }
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(); }