Skip to content

[HealthChecks] Add health check middleware #11173

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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open

Conversation

jviau
Copy link
Contributor

@jviau jviau commented Jul 9, 2025

Issue describing the changes in this PR

Part of #11010, #11171

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Adds supporting files for the eventual addition of a health check endpoint. The added files do two primary things:

  1. HealthCheckWaitMiddleware.cs -- this file enables HTTP long polling of health probes by adding a ?wait={timeInSeconds} query string to the health check calls.
  2. HealthCheckResponseWriter -- this files writes the HTTP responses for health checks. It has 2 modes, a minimal or an expanded response.
    • The expanded response is provided by AspNetCore.Diagnostics.HealthChecks. This ensures it is compatible with other components from that ecosystem of health check packages.
    • Minimal/expanded response is controlled by ?expand={true/false}. Default is false if not included.
    • Note this intentionally does not set status code. That will be done by the AspNetCore health check middleware (which will be added later)

This PR also removes ApiErrorModel (it is unused) and introduces ErrorResponse, which is modeled after the ARM recommended error structure.

@jviau jviau requested a review from a team as a code owner July 9, 2025 18:47
@jviau jviau changed the title Add health check middleware [HealthChecks] Add health check middleware Jul 9, 2025
@jviau jviau force-pushed the jviau/health-checks-2 branch from 5ab9426 to c6fff79 Compare July 17, 2025 15:53
@jviau jviau requested a review from kshyju July 17, 2025 16:02
Copy link
Member

@liliankasem liliankasem left a comment

Choose a reason for hiding this comment

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

lgtm, minor comments. deps json looks good, I don't see any major version bumps

@fabiocav fabiocav requested a review from Copilot July 18, 2025 22:02
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds health check middleware infrastructure to support health check endpoints with two main features: long polling capabilities and configurable response formats. It removes the unused ApiErrorModel class and introduces a new ARM-compliant ErrorResponse model.

  • Adds HealthCheckWaitMiddleware to enable HTTP long polling via ?wait={seconds} query parameter
  • Adds HealthCheckResponseWriter to handle both minimal and expanded health check responses via ?expand={true/false}
  • Replaces deprecated ApiErrorModel with ARM-compliant ErrorResponse model

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
HealthCheckWaitMiddleware.cs Implements long polling for health checks with wait parameter support
HealthCheckResponseWriter.cs Handles response formatting with minimal/expanded modes
ErrorResponse.cs New ARM-compliant error model replacing deprecated ApiErrorModel
ScriptHostManagerExtensions.cs Renames method to DelayUntilHostReadyAsync for consistency
Test files Comprehensive unit tests for new middleware and response writer

@jviau jviau requested a review from kshyju July 22, 2025 20:21
public static class JsonSerializerOptionsProvider
{
/// <summary>
/// Gets the default JSON serializer options used across the functions host.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Not sure we should mention "used across the functions host". I prefer something along the line of "Shared Json serializer with the following settings: 1) Trailing commas allowed, 2) camel casing ...."

using System.Text.Json.Nodes;
using System.Threading.Tasks;
using FluentAssertions;
using HealthChecks.UI.Client;
Copy link
Member

Choose a reason for hiding this comment

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

Remove unnecessary usings.

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.

3 participants