diff --git a/Controllers/AppController.cs b/Controllers/AppController.cs index 93eb044..0c62d66 100644 --- a/Controllers/AppController.cs +++ b/Controllers/AppController.cs @@ -171,5 +171,72 @@ public ActionResult crash() return "success:oomd"; } + + [HttpGet] + [Route("health")] + public ActionResult GetHealthStatus() + { + var healthStatus = new + { + Status = "Healthy", + Timestamp = DateTime.UtcNow, + Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production", + MachineName = Environment.MachineName, + ProcessorCount = Environment.ProcessorCount, + WorkingSet = Environment.WorkingSet, + Scaling = new + { + CurrentInstances = 1, // App Service always reports as 1 for single instance + MinimumInstances = 1, // Free tier minimum + MaximumInstances = 1, // Free tier maximum + Tier = "Free", + CanScaleDown = false, + CanScaleUp = false, + ScalingPolicy = "Manual - Free tier does not support auto-scaling" + } + }; + + return Ok(healthStatus); + } + + [HttpGet] + [Route("scaling-status")] + public ActionResult GetScalingStatus() + { + var scalingInfo = new + { + AppName = "cpu-app", + ServicePlan = new + { + Name = "cpu-app20250714124552Plan", + Tier = "Free", + Sku = "F1" + }, + CurrentState = new + { + InstanceCount = 1, + IsAtMinimum = true, + IsAtMaximum = true + }, + ScalingLimits = new + { + MinimumInstances = 1, + MaximumInstances = 1, + ScaleDownPossible = false, + ScaleUpPossible = false, + Reason = "Free tier (F1) does not support scaling. Minimum and maximum instances are both 1." + }, + Recommendations = new[] + { + "App is already at minimum instance count for Free tier", + "To enable scaling, upgrade to Basic (B1) or higher tier", + "Scale-down operations will always fail on Free tier" + }, + Timestamp = DateTime.UtcNow, + StatusForSRE = "EXPECTED_STATE_NO_ACTION_NEEDED" + }; + + return Ok(scalingInfo); + } } } diff --git a/SCALING-INFO.md b/SCALING-INFO.md new file mode 100644 index 0000000..3ea007e --- /dev/null +++ b/SCALING-INFO.md @@ -0,0 +1,89 @@ +# Azure Web App Scaling Information + +## Overview +This document provides information about scaling behavior for the `cpu-app` Azure Web App to help SRE agents and operations teams understand expected scaling limitations. + +## Current Configuration +- **App Name**: cpu-app (deployed as test_webapp) +- **Service Plan**: cpu-app20250714124552Plan +- **Tier**: Free (F1) +- **Current Instances**: 1 +- **Minimum Instances**: 1 +- **Maximum Instances**: 1 + +## Scaling Limitations + +### Free Tier (F1) Constraints +- **Auto-scaling**: NOT SUPPORTED +- **Manual scaling**: NOT SUPPORTED +- **Scale-down below 1 instance**: NOT POSSIBLE +- **Scale-up above 1 instance**: NOT POSSIBLE + +### Expected Behavior for SRE Operations +- ✅ **Scale-down requests will ALWAYS fail** - This is expected behavior, not an error +- ✅ **Instance count will always be 1** - This is the minimum and maximum for Free tier +- ✅ **No App Service Plan ID in scaling responses** - Common for Free tier +- ❌ **Scale-down operations should NOT be attempted** on Free tier apps + +## API Endpoints for Operations + +### Health Check +``` +GET /api/app/health +``` +Returns overall application health and scaling status. + +### Detailed Scaling Status +``` +GET /api/app/scaling-status +``` +Returns detailed scaling information specifically for SRE operations: +- Current instance count +- Scaling limits and possibilities +- Recommendations for operations teams +- Status flag for automated systems + +## Recommendations + +### For SRE Agents +1. **Check tier before attempting scaling operations** +2. **Use the `/api/app/scaling-status` endpoint to determine if scaling is possible** +3. **Treat "already at minimum" as SUCCESS, not FAILURE for Free tier apps** + +### For Production Workloads +1. **Upgrade to Basic (B1) or higher tier** to enable scaling +2. **Configure auto-scaling rules** after tier upgrade +3. **Set appropriate minimum instance counts** (≥1 for all tiers) + +## Tier Comparison +| Tier | Manual Scaling | Auto-scaling | Min Instances | Max Instances | +|------|----------------|--------------|---------------|---------------| +| Free (F1) | ❌ | ❌ | 1 | 1 | +| Shared (D1) | ❌ | ❌ | 1 | 1 | +| Basic (B1+) | ✅ | ❌ | 1 | 3 | +| Standard (S1+) | ✅ | ✅ | 1 | 10 | +| Premium (P1+) | ✅ | ✅ | 1 | 100 | + +## Troubleshooting Scale-Down Issues + +### Issue: "Already at minimum instance count" +- **Status**: EXPECTED BEHAVIOR +- **Action**: NO ACTION NEEDED +- **Resolution**: This is normal for Free tier apps + +### Issue: "No App Service Plan ID returned" +- **Status**: EXPECTED BEHAVIOR for Free tier +- **Action**: NO ACTION NEEDED +- **Resolution**: Free tier has limited metadata exposure + +### Issue: Scale-down operation fails +- **Status**: EXPECTED BEHAVIOR for Free tier +- **Action**: Update SRE automation to skip scaling for Free tier +- **Resolution**: Check tier before attempting scaling operations + +## Contact Information +For questions about scaling configuration or to request tier upgrades, contact the platform team. + +--- +*Last Updated: 2025-01-19* +*Document Version: 1.0* \ No newline at end of file diff --git a/main.bicep b/main.bicep index 3625799..d42f328 100644 --- a/main.bicep +++ b/main.bicep @@ -1,18 +1,28 @@ // main.bicep // Deploys an Azure App Service Plan and a Web App +// Note: Free tier (F1) does not support auto-scaling and is limited to 1 instance param location string = resourceGroup().location param appServicePlanName string = 'cpu-app20250714124552Plan' param webAppName string = 'test_webapp' +// App Service Plan with explicit scaling configuration resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = { name: appServicePlanName location: location sku: { name: 'F1' tier: 'Free' + capacity: 1 // Free tier is always 1 instance } kind: 'app' + properties: { + // Free tier limitations: + // - Cannot scale below 1 instance + // - Cannot scale above 1 instance + // - No auto-scaling support + // - Manual scaling not supported + } } resource webApp 'Microsoft.Web/sites@2022-03-01' = { @@ -20,7 +30,40 @@ resource webApp 'Microsoft.Web/sites@2022-03-01' = { location: location properties: { serverFarmId: appServicePlan.id + httpsOnly: true + siteConfig: { + // Application settings for scaling awareness + appSettings: [ + { + name: 'SCALING_TIER' + value: 'Free' + } + { + name: 'MIN_INSTANCES' + value: '1' + } + { + name: 'MAX_INSTANCES' + value: '1' + } + { + name: 'SCALING_SUPPORTED' + value: 'false' + } + ] + } } } +// Output scaling information for operational awareness output webAppUrl string = 'https://${webApp.name}.azurewebsites.net' +output scalingInfo object = { + tier: 'Free' + sku: 'F1' + minInstances: 1 + maxInstances: 1 + scalingSupported: false + autoScalingSupported: false + currentInstances: 1 + message: 'Scale-down operations will fail as app is already at minimum instance count (1) for Free tier' +} diff --git a/main.json b/main.json new file mode 100644 index 0000000..c69611a --- /dev/null +++ b/main.json @@ -0,0 +1,92 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.37.4.10188", + "templateHash": "10724890501715392583" + } + }, + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appServicePlanName": { + "type": "string", + "defaultValue": "cpu-app20250714124552Plan" + }, + "webAppName": { + "type": "string", + "defaultValue": "test_webapp" + } + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2022-03-01", + "name": "[parameters('appServicePlanName')]", + "location": "[parameters('location')]", + "sku": { + "name": "F1", + "tier": "Free", + "capacity": 1 + }, + "kind": "app", + "properties": {} + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2022-03-01", + "name": "[parameters('webAppName')]", + "location": "[parameters('location')]", + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]", + "httpsOnly": true, + "siteConfig": { + "appSettings": [ + { + "name": "SCALING_TIER", + "value": "Free" + }, + { + "name": "MIN_INSTANCES", + "value": "1" + }, + { + "name": "MAX_INSTANCES", + "value": "1" + }, + { + "name": "SCALING_SUPPORTED", + "value": "false" + } + ] + } + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]" + ] + } + ], + "outputs": { + "webAppUrl": { + "type": "string", + "value": "[format('https://{0}.azurewebsites.net', parameters('webAppName'))]" + }, + "scalingInfo": { + "type": "object", + "value": { + "tier": "Free", + "sku": "F1", + "minInstances": 1, + "maxInstances": 1, + "scalingSupported": false, + "autoScalingSupported": false, + "currentInstances": 1, + "message": "Scale-down operations will fail as app is already at minimum instance count (1) for Free tier" + } + } + } +} \ No newline at end of file