< Summary - Kestrun — Combined Coverage

Information
Class: Public.Health.Add-KrHealthHttpProbe
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Health/Add-KrHealthHttpProbe.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 23
Coverable lines: 23
Total lines: 99
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 0% (0/23) Total lines: 99 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Health/Add-KrHealthHttpProbe.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Registers an HTTP-based health probe that polls a remote endpoint.
 4    .DESCRIPTION
 5        Creates a Kestrun HttpProbe that issues a GET request to the specified URL and interprets the
 6        response according to the standard health contract. Provide a shared HttpClient instance for
 7        production use to avoid socket exhaustion, or rely on the default constructed client for simple
 8        scenarios.
 9    .PARAMETER Server
 10        The Kestrun host instance to configure. If omitted, the current server context is resolved automatically.
 11    .PARAMETER Name
 12        Unique name for the probe.
 13    .PARAMETER Url
 14        The absolute URL that the probe polls.
 15    .PARAMETER Tags
 16        Optional set of tags used to include or exclude the probe when requests filter by tag.
 17    .PARAMETER HttpClient
 18        Optional HttpClient reused for the probe requests. When omitted a new HttpClient instance is created.
 19    .PARAMETER Timeout
 20        Optional timeout applied to the HTTP request. Defaults to 5 seconds.
 21    .PARAMETER PassThru
 22        Emits the configured server instance so the call can be chained.
 23    .EXAMPLE
 24        Add-KrHealthHttpProbe -Name Api -Url 'https://api.contoso.local/health' -Tags 'remote','api'
 25        Registers a health probe that checks a downstream API health endpoint.
 26    .EXAMPLE
 27        $client = [System.Net.Http.HttpClient]::new()
 28        Get-KrServer | Add-KrHealthHttpProbe -Name Ping -Url 'https://example.com/health' -HttpClient $client -PassThru
 29        Registers a probe using a shared HttpClient instance and returns the host for additional configuration.
 30#>
 31function Add-KrHealthHttpProbe {
 32    [KestrunRuntimeApi('Definition')]
 33    [CmdletBinding()]
 34    [OutputType([Kestrun.Hosting.KestrunHost])]
 35    param(
 36        [Parameter(ValueFromPipeline = $true)]
 37        [Kestrun.Hosting.KestrunHost]$Server,
 38
 39        [Parameter(Mandatory = $true)]
 40        [string]$Name,
 41
 42        [Parameter(Mandatory = $true)]
 43        [ValidateNotNullOrEmpty()]
 44        [string]$Url,
 45
 46        [string[]]$Tags,
 47
 48        [System.Net.Http.HttpClient]$HttpClient,
 49
 50        [timespan]$Timeout,
 51
 52        [switch]$PassThru
 53    )
 54    begin {
 055        $Server = Resolve-KestrunServer -Server $Server
 056        if ($null -eq $Server) {
 057            throw 'Server is not initialized. Call New-KrServer first or pipe an existing host instance.'
 58        }
 59    }
 60    process {
 061        if (-not [Uri]::IsWellFormedUriString($Url, [UriKind]::Absolute)) {
 062            throw "The URL '$Url' must be an absolute URI."
 63        }
 64
 065        $normalizedTags = @()
 066        if ($PSBoundParameters.ContainsKey('Tags')) {
 067            $normalizedTags = @($Tags | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_.Tri
 68        }
 69
 070        if ($normalizedTags.Count -eq 0) {
 071            $normalizedTags = @()
 72        }
 73
 074        $client = $HttpClient
 075        if (-not $PSBoundParameters.ContainsKey('HttpClient') -or $null -eq $HttpClient) {
 076            $client = [System.Net.Http.HttpClient]::new()
 77        }
 78
 079        $probe = if ($PSBoundParameters.ContainsKey('Timeout')) {
 080            if ($Timeout -le [timespan]::Zero) {
 081                throw 'Timeout must be greater than zero.'
 82            }
 083            [Kestrun.Health.HttpProbe]::new($Name, $normalizedTags, $client, $Url, $Timeout)
 84        } else {
 085            [Kestrun.Health.HttpProbe]::new($Name, $normalizedTags, $client, $Url)
 86        }
 87
 88        try {
 089            $hostResult = $Server.AddProbe($probe)
 090            Write-KrLog -Level Information -Message "HTTP health probe '{0}' registered." -Values $Name
 091            if ($PassThru.IsPresent) {
 092                return $hostResult
 93            }
 94        } catch {
 095            Write-KrLog -Level Error -Message "Failed to register HTTP health probe '{0}'." -Values $Name -ErrorRecord $
 96            throw
 97        }
 98    }
 99}

Methods/Properties

Add-KrHealthHttpProbe()