Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.82k forks source link

Az.Monitor : Update-AzAutoscaleSetting adds unintended parameter to autoscale settings #20848

Closed nconvery closed 1 year ago

nconvery commented 1 year ago

Description

Performing an Update-AzAutoscaleSetting command always appends a piece to the requestBody that is not derived from the existing Autoscale Setting.

The following always appears to be appended:

, "fixedDate": { "timeZone": null, "start": "0001-01-01T00:00:00Z", "end": "0001-01-01T00:00:00Z" } } ]

This breaks any update for settings that are utilizing recurrence rules as both a fixedDate and recurrence rule cannot be used together, and will also obviously make unintended changes to any Autoscale Settings even when the command succeeds

Issue script & Debug output

PS /home/nicholas> Update-AzAutoscaleSetting -ResourceGroupName "VMSS-RG" -Name "TEST-NCAS" -Enabled $false -Debug
DEBUG: 6:07:14 PM - GetAzureRMContextCommand end processing.
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing: 
DEBUG: CmdletProcessRecordStart: 
DEBUG: CmdletGetPipeline: 
DEBUG: CmdletBeforeAPICall: 
DEBUG: URLCreated: /subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourcegroups/VMSS-RG/providers/Microsoft.Insights/autoscalesettings/TEST-NCAS?api-version=2022-10-01
DEBUG: RequestCreated: /subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourcegroups/VMSS-RG/providers/Microsoft.Insights/autoscalesettings/TEST-NCAS?api-version=2022-10-01
DEBUG: HeaderParametersAdded: 
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourcegroups/VMSS-RG/providers/Microsoft.Insights/autoscalesettings/TEST-NCAS?api-version=2022-10-01

Headers:
x-ms-unique-id                : 6
x-ms-client-request-id        : 3cbe8af7-e16f-47d3-96cd-2029a5361d33
CommandName                   : Get-AzAutoscaleSetting
FullCommandName               : Get-AzAutoscaleSetting_Get
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v9.3.0,PSVersion/v7.3.1,Az.Autoscale/4.4.0

Body:

DEBUG: BeforeCall: 
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : 9d2a2536-1fd7-413d-abec-561902ab420f
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11998
x-ms-correlation-request-id   : 15c3d703-5589-4275-9d5f-8119b3456eac
x-ms-routing-request-id       : EASTUS:20230203T180714Z:15c3d703-5589-4275-9d5f-8119b3456eac
X-Content-Type-Options        : nosniff
Date                          : Fri, 03 Feb 2023 18:07:13 GMT

Body:
{
  "id": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/microsoft.insights/autoscalesettings/TEST-NCAS",
  "name": "TEST-NCAS",
  "type": "Microsoft.Insights/autoscaleSettings",
  "location": "eastus",
  "tags": {},
  "properties": {
    "profiles": [
      {
        "name": "Auto created default scale condition",
        "capacity": {
          "minimum": "4",
          "maximum": "4",
          "default": "4"
        },
        "rules": [
          {
            "metricTrigger": {
              "metricName": "Percentage CPU",
              "metricNamespace": "microsoft.compute/virtualmachinescalesets",
              "metricResourceUri": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/Microsoft.Compute/virtualMachineScaleSets/testnc-vmss-6",
              "timeGrain": "PT1M",
              "statistic": "Average",
              "timeWindow": "PT10M",
              "timeAggregation": "Average",
              "operator": "GreaterThan",
              "threshold": 70.0,
              "dimensions": [],
              "dividePerInstance": false
            },
            "scaleAction": {
              "direction": "Increase",
              "type": "ChangeCount",
              "value": "1",
              "cooldown": "PT5M"
            }
          }
        ]
      }
    ],
    "enabled": true,
    "name": "TEST-NCAS",
    "targetResourceUri": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/Microsoft.Compute/virtualMachineScaleSets/testnc-vmss-6",
    "notifications": [
      {
        "operation": "Scale",
        "email": {
          "sendToSubscriptionAdministrator": false,
          "sendToSubscriptionCoAdministrators": false,
          "customEmails": []
        },
        "webhooks": []
      }
    ],
    "predictiveAutoscalePolicy": {
      "scaleMode": "ForecastOnly",
      "scaleLookAheadTime": null
    }
  }
}

DEBUG: ResponseCreated: 
DEBUG: BeforeResponseDispatch: 
DEBUG: Finally: 
DEBUG: CmdletAfterAPICall: 
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd: 
DEBUG: CmdletProcessRecordEnd: 

Confirm
Are you sure you want to perform this action?
Performing the operation "Create or update" on target "AutoscaleSetting TEST-NCAS".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing: 
DEBUG: CmdletProcessRecordStart: 

Confirm
Are you sure you want to perform this action?
Performing the operation "New-AzAutoscaleSetting_CreateViaIdentity" on target "Call remote 'AutoscaleSettingsCreateOrUpdate' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
DEBUG: CmdletGetPipeline: 
DEBUG: CmdletBeforeAPICall: 
DEBUG: URLCreated: /subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourcegroups/VMSS-RG/providers/Microsoft.Insights/autoscalesettings/TEST-NCAS?api-version=2022-10-01
DEBUG: RequestCreated: /subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourcegroups/VMSS-RG/providers/Microsoft.Insights/autoscalesettings/TEST-NCAS?api-version=2022-10-01
DEBUG: HeaderParametersAdded: 
DEBUG: BodyContentSet: 
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourcegroups/VMSS-RG/providers/Microsoft.Insights/autoscalesettings/TEST-NCAS?api-version=2022-10-01

Headers:
x-ms-unique-id                : 7
x-ms-client-request-id        : 9d838a04-929e-46ee-b742-1a7ecdea61ef
CommandName                   : Az.Autoscale.private\New-AzAutoscaleSetting_CreateViaIdentity
FullCommandName               : New-AzAutoscaleSetting_CreateViaIdentity
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v9.3.0,PSVersion/v7.3.1,Az.Autoscale/4.4.0

Body:
{
  "location": "eastus",
  "properties": {
    "predictiveAutoscalePolicy": {
      "scaleMode": "ForecastOnly"
    },
    "profiles": [
      {
        "capacity": {
          "minimum": "4",
          "maximum": "4",
          "default": "4"
        },
        "fixedDate": {
          "start": "0001-01-01T00:00:00",
          "end": "0001-01-01T00:00:00"
        },
        "name": "Auto created default scale condition",
        "rules": [
          {
            "metricTrigger": {
              "metricName": "Percentage CPU",
              "metricNamespace": "microsoft.compute/virtualmachinescalesets",
              "metricResourceUri": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/Microsoft.Compute/virtualMachineScaleSets/testnc-vmss-6",
              "timeGrain": "PT1M",
              "statistic": "Average",
              "timeWindow": "PT10M",
              "timeAggregation": "Average",
              "operator": "GreaterThan",
              "threshold": 70,
              "dimensions": [],
              "dividePerInstance": false
            },
            "scaleAction": {
              "direction": "Increase",
              "type": "ChangeCount",
              "value": "1",
              "cooldown": "PT5M"
            }
          }
        ]
      }
    ],
    "notifications": [
      {
        "email": {
          "sendToSubscriptionAdministrator": false,
          "sendToSubscriptionCoAdministrators": false,
          "customEmails": []
        },
        "operation": "Scale",
        "webhooks": []
      }
    ],
    "enabled": false,
    "name": "TEST-NCAS",
    "targetResourceUri": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/Microsoft.Compute/virtualMachineScaleSets/testnc-vmss-6"
  }
}

DEBUG: BeforeCall: 
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : bec87237-d23f-4bb3-a970-7330f27d2cbb
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id   : 4586ec1e-80e1-4a73-926c-2b29b7b811e1
x-ms-routing-request-id       : EASTUS:20230203T180719Z:4586ec1e-80e1-4a73-926c-2b29b7b811e1
X-Content-Type-Options        : nosniff
Date                          : Fri, 03 Feb 2023 18:07:19 GMT

Body:
{
  "id": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/microsoft.insights/autoscalesettings/TEST-NCAS",
  "name": "TEST-NCAS",
  "type": "Microsoft.Insights/autoscaleSettings",
  "location": "eastus",
  "tags": {},
  "properties": {
    "profiles": [
      {
        "name": "Auto created default scale condition",
        "capacity": {
          "minimum": "4",
          "maximum": "4",
          "default": "4"
        },
        "rules": [
          {
            "metricTrigger": {
              "metricName": "Percentage CPU",
              "metricNamespace": "microsoft.compute/virtualmachinescalesets",
              "metricResourceUri": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/Microsoft.Compute/virtualMachineScaleSets/testnc-vmss-6",
              "timeGrain": "PT1M",
              "statistic": "Average",
              "timeWindow": "PT10M",
              "timeAggregation": "Average",
              "operator": "GreaterThan",
              "threshold": 70.0,
              "dimensions": [],
              "dividePerInstance": false
            },
            "scaleAction": {
              "direction": "Increase",
              "type": "ChangeCount",
              "value": "1",
              "cooldown": "PT5M"
            }
          }
        ],
        "fixedDate": {
          "timeZone": null,
          "start": "0001-01-01T00:00:00Z",
          "end": "0001-01-01T00:00:00Z"
        }
      }
    ],
    "enabled": false,
    "name": "TEST-NCAS",
    "targetResourceUri": "/subscriptions/5035ef37-7f5d-4b37-9c29-347781fad2f7/resourceGroups/VMSS-RG/providers/Microsoft.Compute/virtualMachineScaleSets/testnc-vmss-6",
    "notifications": [
      {
        "operation": "Scale",
        "email": {
          "sendToSubscriptionAdministrator": false,
          "sendToSubscriptionCoAdministrators": false,
          "customEmails": []
        },
        "webhooks": []
      }
    ],
    "predictiveAutoscalePolicy": {
      "scaleMode": "ForecastOnly",
      "scaleLookAheadTime": null
    }
  }
}

DEBUG: ResponseCreated: 
DEBUG: BeforeResponseDispatch: 

DEBUG: Finally: 
DEBUG: CmdletAfterAPICall: 
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd: 
DEBUG: CmdletProcessRecordEnd: 
DEBUG: AzureQoSEvent:  Module: Az.Monitor:4.4.0; CommandName: Update-AzAutoscaleSetting; PSVersion: 7.3.1; IsSuccess: True; Duration: 00:00:05.7627296
Location Name      SystemDataCreatedAt SystemDataCreatedBy SystemDataCreatedByType SystemDataLastModifiedAt SystemDataLastModifiedBy SystemDataLastModifiedByType
-------- ----      ------------------- ------------------- ----------------------- ------------------------ ------------------------ ----------------------------
eastus   TEST-NCAS                                                                                                                   

PS /home/nicholas>

Environment data

PS /home/nicholas> $PSVersionTable                                                                                                                                                                                                                                                                                                                                                                                                 
Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Linux 5.4.0-1101-azure #107~18.04.1-Ubuntu SMP Tue Jan 10 21:14:56 UTC 2023
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

PS /home/nicholas> Get-Module Az.Monitor

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     4.4.0                 Az.Monitor                          {Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2, Add-AzWebtestAlertRule…}

Error output

There is not error output unless fixedDate parameter causes a conflict, in which case the error output is the Autoscale API not accepting the parameters. 

Otherwise the command will succeed, but will perform a change to the scale setting that isn't intended.
VeryEarly commented 1 year ago

Hi @nconvery , this issue is similar to #20660 and the fix will be out on 2023-02-07 PST, please try latest version of Az.Monitor 4.4.1 then, thanks