Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between Mezmo error vs no logs for specified time period #180

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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