Skip to content

feat: proper health-check for github#10

Open
Fildrance wants to merge 3 commits into
space-wizards:masterfrom
Fildrance:feature/health-check-github
Open

feat: proper health-check for github#10
Fildrance wants to merge 3 commits into
space-wizards:masterfrom
Fildrance:feature/health-check-github

Conversation

@Fildrance

Copy link
Copy Markdown
Contributor

No description provided.

@Fildrance

Copy link
Copy Markdown
Contributor Author

This thing will return only Healthy/Unhealthy/Degraded string, no details. It cannot return detailed statuses because that will require either custom serialization code or turning NAOT off.

Need to add health-check for discourse. And for database too. Then this status being Unhealthy would be quite problematic to decypher ;(

Comment thread SS14.Labeller/Program.cs

app.MapGet("/", () => Results.Ok("Nik is a cat!"));

app.MapHealthChecks("/health");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you gate this behind some form of auth? Maybe a basic-auth check that is configured via appsettings? We wouldn't want people spamming this endpoint and getting us ratelimited that way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smort! true.
actually i was not expecting to have this in open field
hmm. i need to do cache for gh status, so we won't re-request it too often anyways!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache added, i propose leave it as is - having basic auth just for that endpoint seems off.

Comment on lines +16 to +40
var client = httpClientFactory.CreateClient(nameof(IGitHubApiClient));

// Make a simple, low-impact request to verify the key
var response = await client.GetAsync("https://api.github.com/user", cancellationToken);

if (response.IsSuccessStatusCode)
{
return HealthCheckResult.Healthy("GitHub API key is valid.");
}

if (response.StatusCode is System.Net.HttpStatusCode.Unauthorized or System.Net.HttpStatusCode.Forbidden)
{
return HealthCheckResult.Unhealthy("GitHub API key is invalid or lacks necessary permissions.");
}

return HealthCheckResult.Degraded($"GitHub API returned an unexpected status code: {response.StatusCode}");
}
catch (HttpRequestException ex)
{
return HealthCheckResult.Unhealthy($"Failed to connect to GitHub API: {ex.Message}");
}
catch (Exception ex)
{
return HealthCheckResult.Unhealthy($"An error occurred during GitHub API key health check: {ex.Message}");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing ex.Message just pass ex itself so it also includes the full stacktrace. (Considering this endpoint is supposed to be internal)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do that, but serializer that we are using (which is the only available by default w/ NAOT) is not going to show anything anyways, not even that text - just healthy/unhealthy. So probably fine by now. Later tho i would better like that thing blocking requests from the outside on the level of reverse proxy.

@Fildrance Fildrance requested a review from Simyon264 September 29, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants