Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 1 addition & 37 deletions ScheduledTasks/DailySupportCheck/Invoke-DailySupportCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -453,43 +453,7 @@ function Test-SubscriptionService {
$provider = $Context.SubscriptionServiceProvider
}

$subscriptions = @(& $provider $uri $timeoutSeconds)
$subscriptionIdValue = if ($subscriptions.Count -eq 1 -and $subscriptions[0].PSObject.Properties['subscriptionId']) { $subscriptions[0].subscriptionId }
$isSubscriptionCollection = $subscriptionIdValue -is [System.Collections.IEnumerable] -and $subscriptionIdValue -isnot [string]
$flattenedSubscriptionIds = if ($subscriptionIdValue -is [string]) {
@([regex]::Split($subscriptionIdValue.Trim(), '(?=\$idx-)') | Where-Object { -not [string]::IsNullOrWhiteSpace([string] $_) })
}
$flattenedSubscriptionIds = @($flattenedSubscriptionIds)
if ($subscriptions.Count -eq 1 -and $flattenedSubscriptionIds.Count -gt 1) {
$flattenedResponse = $subscriptions[0]
$flattenedTags = if ($flattenedResponse.PSObject.Properties['tag']) { @(([string] $flattenedResponse.tag).Trim() -split '\s+') } else { @() }
$flattenedHealth = if ($flattenedResponse.PSObject.Properties['health']) { @(([string] $flattenedResponse.health).Trim() -split '\s+') } else { @() }
$subscriptions = for ($index = 0; $index -lt $flattenedSubscriptionIds.Count; $index++) {
$subscriptionId = ([string] $flattenedSubscriptionIds[$index]).Trim()
[pscustomobject]@{
subscriptionId = $subscriptionId
tag = if ($flattenedTags.Count -eq $flattenedSubscriptionIds.Count) { $flattenedTags[$index] } else { ($subscriptionId -split '_')[-1] }
isRunning = $flattenedResponse.isRunning
health = if ($flattenedHealth.Count -eq $flattenedSubscriptionIds.Count) { $flattenedHealth[$index] } else { $flattenedResponse.health }
parkedEventCount = $flattenedResponse.parkedEventCount
operationalReason = if ($flattenedResponse.PSObject.Properties['operationalReason']) { $flattenedResponse.operationalReason } else { $null }
runtimeFailureReason = if ($flattenedResponse.PSObject.Properties['runtimeFailureReason']) { $flattenedResponse.runtimeFailureReason } else { $null }
}
}
}
elseif ($subscriptions.Count -eq 1 -and $subscriptions[0].PSObject.Properties['subscriptionId'] -and $isSubscriptionCollection) {
$wrappedSubscriptions = $subscriptions[0]
$subscriptionCount = @($wrappedSubscriptions.subscriptionId).Count
$subscriptions = for ($index = 0; $index -lt $subscriptionCount; $index++) {
$subscription = [ordered]@{}
foreach ($property in $wrappedSubscriptions.PSObject.Properties) {
$value = $property.Value
$isCollection = $value -is [System.Collections.IEnumerable] -and $value -isnot [string]
$subscription[$property.Name] = if ($isCollection -and @($value).Count -eq $subscriptionCount) { @($value)[$index] } else { $value }
}
[pscustomobject] $subscription
}
}
$subscriptions = @((& $provider $uri $timeoutSeconds))
if ($subscriptions.Count -eq 0) {
return Get-CheckResult -Name 'Subscription Service' -Status Warning -Summary 'Subscription service returned no subscriptions.' -Details @()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ Describe 'Daily support check' {
$result.Summary | Should -Match '1 subscription'
}

It 'expands a wrapped subscription response into individual subscriptions' {
It 'creates one health result for every subscription returned by the API' {
$context = [pscustomobject]@{
Configuration = [pscustomobject]@{
SubscriptionService = [pscustomobject]@{
Expand All @@ -538,15 +538,11 @@ Describe 'Daily support check' {
}
}
SubscriptionServiceProvider = {
[pscustomobject]@{
subscriptionId = @('subscription-1', 'subscription-2')
tag = @('Main', 'Ordered')
isRunning = @($true, $true)
health = @('Healthy', 'Healthy')
parkedEventCount = @(0, 2)
operationalReason = @($null, $null)
runtimeFailureReason = @($null, $null)
}
$apiResponse = @(
[pscustomobject]@{ subscriptionId = 'subscription-1'; tag = 'Main'; isRunning = $true; health = 'Healthy'; parkedEventCount = 0; operationalReason = $null; runtimeFailureReason = $null }
[pscustomobject]@{ subscriptionId = 'subscription-2'; tag = 'Ordered'; isRunning = $true; health = 'Healthy'; parkedEventCount = 2; operationalReason = 'Parked messages detected'; runtimeFailureReason = $null }
)
,$apiResponse
}
}

Expand All @@ -555,71 +551,10 @@ Describe 'Daily support check' {
$result.Status | Should -Be 'Warning'
$result.Summary | Should -Match '1 subscription\(s\) have parked messages'
$result.Details.Count | Should -Be 2
}

It 'expands wrapped enumerable subscription collections returned by the API' {
$context = [pscustomobject]@{
Configuration = [pscustomobject]@{
SubscriptionService = [pscustomobject]@{
Enabled = $true
BaseUrl = 'http://subscription-service'
StatusPath = '/subscriptions/status'
TimeoutSeconds = 10
}
}
SubscriptionServiceProvider = {
$subscriptionIds = [System.Collections.ArrayList]::new(@('subscription-1', 'subscription-2'))
$tags = [System.Collections.ArrayList]::new(@('Main', 'Ordered'))
$runningStates = [System.Collections.ArrayList]::new(@($true, $true))
$healthStates = [System.Collections.ArrayList]::new(@('Healthy', 'Healthy'))
$parkedCounts = [System.Collections.ArrayList]::new(@(0, 2))
[pscustomobject]@{
subscriptionId = $subscriptionIds
tag = $tags
isRunning = $runningStates
health = $healthStates
parkedEventCount = $parkedCounts
}
}
}

$result = Test-SubscriptionService -Context $context

$result.Status | Should -Be 'Warning'
$result.Details.Count | Should -Be 2
$result.Details[0].SubscriptionId | Should -Be 'subscription-1'
$result.Details[0].Status | Should -Be 'Passed'
$result.Details[1].SubscriptionId | Should -Be 'subscription-2'
}

It 'expands the flattened subscription response emitted by the status endpoint' {
$context = [pscustomobject]@{
Configuration = [pscustomobject]@{
SubscriptionService = [pscustomobject]@{
Enabled = $true
BaseUrl = 'http://subscription-service'
StatusPath = '/subscriptions/status'
TimeoutSeconds = 10
}
}
SubscriptionServiceProvider = {
[pscustomobject]@{
subscriptionId = '$idx-ce-TransactionAggregate_Transaction Processor_Main $idx-ce-SettlementAggregate_Transaction Processor_Ordered'
tag = 'Main Ordered'
isRunning = $true
health = 'Healthy Healthy'
parkedEventCount = 0
}
}
}

$result = Test-SubscriptionService -Context $context

$result.Status | Should -Be 'Passed'
$result.Details.Count | Should -Be 2
$result.Details[0].SubscriptionId | Should -Be '$idx-ce-TransactionAggregate_Transaction Processor_Main'
$result.Details[0].Tag | Should -Be 'Main'
$result.Details[1].SubscriptionId | Should -Be '$idx-ce-SettlementAggregate_Transaction Processor_Ordered'
$result.Details[1].Tag | Should -Be 'Ordered'
$result.Details[1].Status | Should -Be 'Warning'
}

It 'fails when a subscription is stopped and warns when parked messages exist' {
Expand Down
Loading