From 860358aa5d74b1cc1f15f72246dcc7e010579b99 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Tue, 29 Oct 2024 22:13:27 -0700 Subject: [PATCH] Distinguish between Mezmo error vs no logs for specified time period (#180) * Distinguish between Mezmo error vs no logs for specified time period --------- Signed-off-by: Dave Thaler --- OrcanodeMonitor/Core/MezmoFetcher.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/OrcanodeMonitor/Core/MezmoFetcher.cs b/OrcanodeMonitor/Core/MezmoFetcher.cs index 1743036..e361381 100644 --- a/OrcanodeMonitor/Core/MezmoFetcher.cs +++ b/OrcanodeMonitor/Core/MezmoFetcher.cs @@ -33,7 +33,7 @@ private static int MezmoLogSeconds /// /// URL to get content from /// String content. An empty string may mean empty content or an HTTP error. - public async static Task GetMezmoDataAsync(string url) + public async static Task GetMezmoDataAsync(string url) { try { @@ -41,7 +41,7 @@ public async static Task GetMezmoDataAsync(string url) if (string.IsNullOrEmpty(service_key)) { Console.Error.WriteLine($"MEZMO_SERVICE_KEY not configured"); - return string.Empty; // No content. + return null; } using (var request = new HttpRequestMessage @@ -60,7 +60,7 @@ public async static Task GetMezmoDataAsync(string url) { string msg = ex.ToString(); Console.Error.WriteLine($"Exception in GetMezmoDataAsync: {msg}"); - return string.Empty; // No content. + return null; } } @@ -82,10 +82,10 @@ public async static Task GetMezmoDataAsync(string url) } int from = to - MezmoLogSeconds; string url = $"{_mezmoLogUrl}?from={from}&to={to}&hosts={node.S3NodeName}"; - string jsonString = await GetMezmoDataAsync(url); - if (jsonString.IsNullOrEmpty()) + string? jsonString = await GetMezmoDataAsync(url); + if (jsonString == null) { - // Error. + logger.LogDebug($"Failed to fetch Mezmo logs for {node.S3NodeName} between {from} and {to}"); return null; } @@ -126,8 +126,8 @@ public async static Task UpdateMezmoHostsAsync(OrcanodeMonitorContext context, I { try { - string jsonArray = await GetMezmoDataAsync(_mezmoHostsUrl); - if (jsonArray.IsNullOrEmpty()) + string? jsonArray = await GetMezmoDataAsync(_mezmoHostsUrl); + if (jsonArray == null) { // Error so do nothing. return; @@ -236,8 +236,8 @@ public async static Task UpdateMezmoViewsAsync(OrcanodeMonitorContext context, I { try { - string jsonArray = await GetMezmoDataAsync(_mezmoViewsUrl); - if (jsonArray.IsNullOrEmpty()) + string? jsonArray = await GetMezmoDataAsync(_mezmoViewsUrl); + if (jsonArray == null) { // Error so do nothing. return; @@ -258,7 +258,7 @@ public async static Task UpdateMezmoViewsAsync(OrcanodeMonitorContext context, I { if (!view.TryGetProperty("hosts", out var hostsArray)) { - logger.LogError($"Missing hosts in UpdateMezmoViewsAsync result"); + // Not an error, since there are other types of views. continue; } if (hostsArray.ValueKind != JsonValueKind.Array)