Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9976f02
Update dashboard data - 2025-06-10 12:09:41 UTC
hmcts-platform-operations Jun 10, 2025
081df80
Update dashboard data - 2025-06-10 12:09:52 UTC
hmcts-platform-operations Jun 10, 2025
c4fb1fb
Initial plan for issue
Copilot Jun 10, 2025
df105bd
Add support for additional resource types in cost calculation
Copilot Jun 10, 2025
313a521
Improve SKU detection and add comprehensive documentation
Copilot Jun 10, 2025
3098c81
Merge pull request #183 from hmcts/copilot/fix-182
JordanHoey96 Jun 10, 2025
cfcab63
Update dashboard data - 2025-06-10 12:35:45 UTC
hmcts-platform-operations Jun 10, 2025
33d03da
Update dashboard data - 2025-06-10 12:37:00 UTC
hmcts-platform-operations Jun 10, 2025
ebb53ae
Update dashboard data - 2025-06-10 12:37:15 UTC
hmcts-platform-operations Jun 10, 2025
9fd44b6
parseissue-184
hmcts-platform-operations Jun 10, 2025
29a6434
Update dashboard data - 2025-06-10 12:38:26 UTC
hmcts-platform-operations Jun 10, 2025
96bbd97
Update dashboard data - 2025-06-10 12:56:41 UTC
hmcts-platform-operations Jun 10, 2025
089c59d
Update dashboard data - 2025-06-10 12:56:56 UTC
hmcts-platform-operations Jun 10, 2025
80d9956
Initial plan for issue
Copilot Jun 10, 2025
feced38
Fix cost calculation issues: API URL syntax and Azure Graph query par…
Copilot Jun 10, 2025
1303c80
Fix bash syntax error in associative array check
Copilot Jun 10, 2025
e1b87de
Remove fallback pricing mechanism - use only API data
Copilot Jun 10, 2025
fd2b44f
Merge pull request #186 from hmcts/copilot/fix-185
JordanHoey96 Jun 10, 2025
827bf3c
Update dashboard data - 2025-06-10 13:32:32 UTC
hmcts-platform-operations Jun 10, 2025
5eea894
Update dashboard data - 2025-06-10 13:33:17 UTC
hmcts-platform-operations Jun 10, 2025
83077b5
parseissue-187
hmcts-platform-operations Jun 10, 2025
e31a166
Update dashboard data - 2025-06-10 13:34:20 UTC
hmcts-platform-operations Jun 10, 2025
2655af6
JSON Status files housekeeping
hmcts-platform-operations Jun 10, 2025
c241d87
Update dashboard data - 2025-06-11 06:06:33 UTC
hmcts-platform-operations Jun 11, 2025
243338a
housekeeping
hmcts-platform-operations Jun 11, 2025
cda4889
Update dashboard data - 2025-06-12 06:06:48 UTC
hmcts-platform-operations Jun 12, 2025
90e1bf0
Update dashboard data - 2025-06-13 06:06:34 UTC
hmcts-platform-operations Jun 13, 2025
81a40c2
adding torubleshooting file output
JordanHoey96 Jun 13, 2025
6a88563
Update dashboard data - 2025-06-13 09:46:01 UTC
hmcts-platform-operations Jun 13, 2025
86888e0
parseissue-188
hmcts-platform-operations Jun 13, 2025
eab19d5
Update dashboard data - 2025-06-13 09:47:12 UTC
hmcts-platform-operations Jun 13, 2025
36aff73
Update dashboard data - 2025-06-13 09:55:07 UTC
hmcts-platform-operations Jun 13, 2025
01784c0
Update dashboard data - 2025-06-13 09:55:19 UTC
hmcts-platform-operations Jun 13, 2025
948783a
Initial plan for issue
Copilot Jun 13, 2025
15c3934
Initial analysis of Azure Resource Graph query syntax errors
Copilot Jun 13, 2025
2e78608
Fix Azure Resource Graph KQL syntax errors in queries
Copilot Jun 13, 2025
b46e84b
Merge pull request #190 from hmcts/copilot/fix-189
JordanHoey96 Jun 13, 2025
c7dcbc4
Update dashboard data - 2025-06-13 11:06:43 UTC
hmcts-platform-operations Jun 13, 2025
79365a0
Update dashboard data - 2025-06-13 11:07:29 UTC
hmcts-platform-operations Jun 13, 2025
aee88c6
parseissue-191
hmcts-platform-operations Jun 13, 2025
ab7cbf7
Update dashboard data - 2025-06-13 11:08:19 UTC
hmcts-platform-operations Jun 13, 2025
97ef00f
updates
JordanHoey96 Jun 16, 2025
ba223d0
updating script path
JordanHoey96 Jun 17, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/parsegithubissue-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
- name: get aks resource details
if: env.PROCESS_SUCCESS == 'true'
continue-on-error: true
run: ./scripts/aks/resource-details.sh
run: ./scripts/resource-details.sh

#Run cost calculator python script
- name: process costs
Expand Down
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
.venv
.venv
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
172 changes: 172 additions & 0 deletions COST_CALCULATION_IMPROVEMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Cost Calculation Improvements

## Overview

This enhancement extends the existing cost calculation system to support additional Azure resource types beyond AKS clusters and VM Scale Sets. The system now supports:

- **Virtual Machines** - Individual VMs with accurate SKU detection
- **Application Gateways** - With tier and capacity-based pricing
- **PostgreSQL Flexible Servers** - With compute tier-based pricing
- **SQL Managed Instances** - With vCore-based pricing

## Key Features

### 1. Scalable Resource Type Support

The system uses a new data format that includes resource type information:
```
ResourceType,SKU,OS/Tier,Count
```

Examples:
```
VM,Standard_D2s_v3,Linux,2
ApplicationGateway,Standard_v2,Standard_v2,1
FlexibleServer,GP_Standard_D2ds_v4,PostgreSQL,1
SqlManagedInstance,GP_Gen5_4,GeneralPurpose,1
```

### 2. Backward Compatibility

The system maintains full backward compatibility with the existing format:
```
SKU,OS,Count
```

Legacy entries are automatically treated as VM resources.

### 3. Enhanced SKU Detection

- **Virtual Machines**: Extracts actual VM size and OS type from Azure properties
- **Application Gateways**: Detects tier, name, and capacity from Azure SKU properties
- **Flexible Servers**: Extracts compute tier and VM size from Azure SKU properties
- **SQL Managed Instances**: Detects service tier, generation, and vCore count

### 4. Robust Pricing API Integration

- Supports different Azure Pricing API product names for each resource type
- Includes fallback pricing when API is unavailable
- Maintains existing retry logic and error handling

### 5. Resource-Specific Cost Calculations

While most resources use the standard shutdown schedule calculation, the system is designed to support resource-specific cost models if needed in the future.

## Implementation Details

### New Functions in `resource-details.sh`

1. **`countResource()`** - Enhanced resource counting with type support
2. **`get_vm_costs()`** - Collects Virtual Machine cost information
3. **`get_appgateway_costs()`** - Collects Application Gateway cost information
4. **`get_flexible_server_costs()`** - Collects Flexible Server cost information
5. **`get_sqlmi_costs()`** - Collects SQL Managed Instance cost information

### Enhanced `cost-calculator.py`

1. **`get_fallback_pricing()`** - Provides fallback pricing when API is unavailable
2. **`azPriceAPI()`** - Enhanced to handle different resource types and product names
3. **Main processing loop** - Supports both new and legacy data formats

## Azure Graph Queries

The system uses enhanced Azure Resource Graph queries to extract pricing-relevant information:

### Virtual Machines
```kql
resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| where tags.autoShutdown == 'true'
| project name, resourceGroup, subscriptionId, ['tags'],
properties.hardwareProfile.vmSize, properties.storageProfile.osDisk.osType
```

### Application Gateways
```kql
resources
| where type =~ 'microsoft.network/applicationgateways'
| where tags.autoShutdown == 'true'
| project name, resourceGroup, subscriptionId, ['tags'],
properties.sku.tier, properties.sku.name, properties.sku.capacity
```

### PostgreSQL Flexible Servers
```kql
resources
| where type =~ 'microsoft.dbforpostgresql/flexibleservers'
| where tags.autoShutdown == 'true'
| project name, resourceGroup, subscriptionId, ['tags'],
properties.sku.tier, properties.sku.name
```

### SQL Managed Instances
```kql
resources
| where type =~ 'microsoft.sql/managedinstances'
| where tags.autoShutdown == 'true'
| project name, resourceGroup, subscriptionId, ['tags'],
properties.sku.tier, properties.sku.family, properties.vCores
```

## Adding New Resource Types

To add support for additional resource types in the future:

1. **Create collection function** in `resource-details.sh`:
```bash
function get_newresource_costs() {
# Azure graph query to get resources with SKU info
# Process each resource and call countResource
}
```

2. **Add to main collection** in `resource-details.sh`:
```bash
get_newresource_costs
```

3. **Add pricing logic** in `cost-calculator.py`:
```python
elif resource_type == "NewResourceType":
productName = "'New Resource Product Name'"
```

4. **Add fallback pricing** in `cost-calculator.py`:
```python
"NewResourceType": {
"SKU_Name": hourly_rate
}
```

## Testing

The implementation includes comprehensive tests covering:

- Legacy format compatibility
- New format support
- Mixed format handling
- All resource types
- Stay-on-late functionality
- Error handling and fallback pricing

Run tests with:
```bash
# Basic functionality test
./test_cost_calculation.sh

# Comprehensive test suite
./final_test_suite.sh
```

## Cost Estimation Accuracy

The system maintains the existing 25% buffer for unmeasurable costs and uses realistic fallback pricing when the Azure Pricing API is unavailable. This ensures cost estimates remain useful even in degraded conditions.

## Future Enhancements

Potential future improvements:
- Resource-specific cost calculation models
- Regional pricing support
- Reserved instance pricing consideration
- More granular Application Gateway data processing costs
- Disk and storage cost calculations
Loading