Skip to content

Commit

Permalink
Distinguish between Mezmo error vs no logs for specified time period (#…
Browse files Browse the repository at this point in the history
…180)

* Distinguish between Mezmo error vs no logs for specified time period

---------

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Oct 30, 2024
1 parent 7becca2 commit 860358a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions OrcanodeMonitor/Core/MezmoFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ private static int MezmoLogSeconds
/// </summary>
/// <param name="url">URL to get content from</param>
/// <returns>String content. An empty string may mean empty content or an HTTP error.</returns>
public async static Task<string> GetMezmoDataAsync(string url)
public async static Task<string?> GetMezmoDataAsync(string url)
{
try
{
string? service_key = Environment.GetEnvironmentVariable("MEZMO_SERVICE_KEY");
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
Expand All @@ -60,7 +60,7 @@ public async static Task<string> GetMezmoDataAsync(string url)
{
string msg = ex.ToString();
Console.Error.WriteLine($"Exception in GetMezmoDataAsync: {msg}");
return string.Empty; // No content.
return null;
}
}

Expand All @@ -82,10 +82,10 @@ public async static Task<string> 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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 860358a

Please sign in to comment.