Azure / azure-powershell

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

Add-AzureRmAutoscaleSetting returns 'BadRequest' despite valid params #8474

Closed l0010o0001l closed 5 years ago

l0010o0001l commented 5 years ago

Description

I have been attempting to create Autoscale settings via AzureRM and have been only getting 'BadRequest' responses despite valid parameter input. If it helps, I get the same behavior using ARM templates. It is not clear what the problem is, or which metric is unsupported. Thank you for looking into this.

Script/Steps for Reproduction

        $outWindow = New-TimeSpan -Minutes 10
        $outTimeGrain = New-TimeSpan -Minutes 1
        $outCooldown = New-TimeSpan -Minutes 10

        $mrid = Get-AzureRmResource -Name <name> -ResourceType 'Microsoft.Web/sites'

        $soRuleParams = @{
            MetricName = "incredible metric name"
            MetricResourceId = $mrid.resourceID
            TimeGrain = $outTimeGrain
            MetricStatistic = 'Average'
            TimeWindow = $outWindow
            Operator = 'GreaterThan'
            Threshold = 1000
            ScaleActionDirection = 'Increase'
            ScaleActionScaleType = 'ChangeCount'
            ScaleActionValue = '1'
            ScaleActionCooldown = $outCooldown
        }

        $outRule = New-AzureRmAutoscaleRule @soRuleParams

        $outProfileParams = @{
            Name = "awesome-scale-out-profile"
            DefaultCapacity = 1
            MinimumCapacity = 1
            MaximumCapacity = 4
            Rule = $outRule
        }
        $outProfile = New-AzureRmAutoscaleProfile @outProfileParams

        $outTargetResource = Get-AzureRMResource -Name <name> -ResourceType 'Microsoft.Web/serverFarms'

        $outAddParams = @{
            Location = 'westus2'
            Name = 'awesome-scale-out'
            ResourceGroupName = 'awesomeresourcegroup'
            TargetResourceID = $outTargetResource.resourceID
            AutoscaleProfile = $outProfile
        }
        Add-AzureRmAutoscaleSetting @outAddParams

Module Version

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     4.6.1      Azure.Storage                       {Get-AzureStorageTable, New-AzureStorageTableSASToken, New-Azur...
Script     4.5.0      Azure.Storage                       {Get-AzureStorageTable, New-AzureStorageTableSASToken, New-Azur...
Binary     2.0.1.16   AzureAD                             {Add-AzureADApplicationOwner, Get-AzureADApplication, Get-Azure...
Script     6.13.1     AzureRM
Script     6.8.1      AzureRM
Script     0.6.14     AzureRM.AnalysisServices            {Resume-AzureRmAnalysisServicesServer, Suspend-AzureRmAnalysisS...
Script     6.1.7      AzureRM.ApiManagement               {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementSsoTok...
Script     6.1.5      AzureRM.ApiManagement               {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementSsoTok...
Script     0.1.8      AzureRM.ApplicationInsights         {Get-AzureRmApplicationInsights, New-AzureRmApplicationInsights...
Script     6.1.1      AzureRM.Automation                  {Get-AzureRMAutomationHybridWorkerGroup, Remove-AzureRmAutomati...
Script     5.1.1      AzureRM.Automation                  {Get-AzureRMAutomationHybridWorkerGroup, Get-AzureRmAutomationJ...
Script     4.0.11     AzureRM.Backup                      {Backup-AzureRmBackupItem, Enable-AzureRmBackupContainerReregis...
Script     4.0.10     AzureRM.Backup                      {Backup-AzureRmBackupItem, Enable-AzureRmBackupContainerReregis...
Script     4.1.5      AzureRM.Batch                       {Remove-AzureRmBatchAccount, Get-AzureRmBatchAccount, Get-Azure...
Script     0.14.6     AzureRM.Billing                     {Get-AzureRmBillingInvoice, Get-AzureRmBillingPeriod, Get-Azure...
Script     5.0.6      AzureRM.Cdn                         {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-AzureR...
Script     5.0.5      AzureRM.Cdn                         {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-AzureR...
Script     0.9.12     AzureRM.CognitiveServices           {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitiveServi...
Script     0.9.10     AzureRM.CognitiveServices           {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitiveServi...
Script     5.9.1      AzureRM.Compute                     {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet, New...
Script     5.5.2      AzureRM.Compute                     {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet, New...
Script     0.3.7      AzureRM.Consumption                 {Get-AzureRmConsumptionBudget, Get-AzureRmConsumptionMarketplac...
Script     0.2.12     AzureRM.ContainerInstance           {New-AzureRmContainerGroup, Get-AzureRmContainerGroup, Remove-A...
Script     0.2.10     AzureRM.ContainerInstance           {New-AzureRmContainerGroup, Get-AzureRmContainerGroup, Remove-A...
Script     1.0.10     AzureRM.ContainerRegistry           {New-AzureRmContainerRegistry, Get-AzureRmContainerRegistry, Up...
Script     5.0.3      AzureRM.DataFactories               {Remove-AzureRmDataFactory, Get-AzureRmDataFactoryRun, Get-Azur...
Script     0.5.11     AzureRM.DataFactoryV2               {Set-AzureRmDataFactoryV2, Update-AzureRmDataFactoryV2, Get-Azu...
Script     0.5.10     AzureRM.DataFactoryV2               {Set-AzureRmDataFactoryV2, Update-AzureRmDataFactoryV2, Get-Azu...
Script     5.1.4      AzureRM.DataLakeAnalytics           {Get-AzureRmDataLakeAnalyticsDataSource, New-AzureRmDataLakeAna...
Script     6.2.1      AzureRM.DataLakeStore               {Get-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataL...
Script     6.1.2      AzureRM.DataLakeStore               {Get-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataL...
Script     4.0.9      AzureRM.DevTestLabs                 {Get-AzureRmDtlAllowedVMSizesPolicy, Get-AzureRmDtlAutoShutdown...
Script     5.1.0      AzureRM.Dns                         {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remove-Az...
Script     5.0.4      AzureRM.Dns                         {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remove-Az...
Script     0.3.7      AzureRM.EventGrid                   {New-AzureRmEventGridTopic, Get-AzureRmEventGridTopic, Set-Azur...
Script     0.7.0      AzureRM.EventHub                    {New-AzureRmEventHubNamespace, Get-AzureRmEventHubNamespace, Se...
Script     0.6.10     AzureRM.EventHub                    {New-AzureRmEventHubNamespace, Get-AzureRmEventHubNamespace, Se...
Script     4.1.8      AzureRM.HDInsight                   {Get-AzureRmHDInsightJob, New-AzureRmHDInsightSqoopJobDefinitio...
Script     5.1.5      AzureRM.Insights                    {Get-AzureRmMetricDefinition, Get-AzureRmMetric, Remove-AzureRm...
Script     5.1.3      AzureRM.Insights                    {Get-AzureRmMetricDefinition, Get-AzureRmMetric, Remove-AzureRm...
Script     3.1.8      AzureRM.IotHub                      {Add-AzureRmIotHubKey, Get-AzureRmIotHubEventHubConsumerGroup, ...
Script     5.2.1      AzureRM.KeyVault                    {Add-AzureKeyVaultCertificate, Update-AzureKeyVaultCertificate,...
Script     4.1.4      AzureRM.LogicApp                    {Get-AzureRmIntegrationAccountAgreement, Get-AzureRmIntegration...
Script     0.18.5     AzureRM.MachineLearning             {Move-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentAs...
Script     0.4.8      AzureRM.MachineLearningCompute      {Get-AzureRmMlOpCluster, Get-AzureRmMlOpClusterKey, Test-AzureR...
Script     0.2.7      AzureRM.MarketplaceOrdering         {Get-AzureRmMarketplaceTerms, Set-AzureRmMarketplaceTerms}
Script     0.2.5      AzureRM.MarketplaceOrdering         {Get-AzureRmMarketplaceTerms, Set-AzureRmMarketplaceTerms}
Script     0.10.4     AzureRM.Media                       {Sync-AzureRmMediaServiceStorageKeys, Set-AzureRmMediaServiceKe...
Script     6.11.1     AzureRM.Network                     {Add-AzureRmApplicationGatewayAuthenticationCertificate, Get-Az...
Script     6.6.1      AzureRM.Network                     {Add-AzureRmApplicationGatewayAuthenticationCertificate, Get-Az...
Script     5.0.3      AzureRM.NotificationHubs            {Get-AzureRmNotificationHub, Get-AzureRmNotificationHubAuthoriz...
Script     5.0.6      AzureRM.OperationalInsights         {New-AzureRmOperationalInsightsAzureActivityLogDataSource, New-...
Script     1.1.0      AzureRM.PolicyInsights              {Get-AzureRmPolicyEvent, Get-AzureRmPolicyState, Get-AzureRmPol...
Script     1.0.4      AzureRM.PolicyInsights              {Get-AzureRmPolicyEvent, Get-AzureRmPolicyState, Get-AzureRmPol...
Script     4.1.10     AzureRM.PowerBIEmbedded             {Remove-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWo...
Script     5.8.2      AzureRM.profile                     {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave,...
Script     5.5.1      AzureRM.profile                     {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave,...
Script     4.1.9      AzureRM.RecoveryServices            {Get-AzureRmRecoveryServicesBackupProperty, Get-AzureRmRecovery...
Script     4.1.8      AzureRM.RecoveryServices            {Get-AzureRmRecoveryServicesBackupProperty, Get-AzureRmRecovery...
Script     4.5.2      AzureRM.RecoveryServices.Backup     {Backup-AzureRmRecoveryServicesBackupItem, Get-AzureRmRecoveryS...
Script     4.4.1      AzureRM.RecoveryServices.Backup     {Backup-AzureRmRecoveryServicesBackupItem, Get-AzureRmRecoveryS...
Script     0.2.12     AzureRM.RecoveryServices.SiteRec... {Edit-AzureRmRecoveryServicesAsrRecoveryPlan, Get-AzureRmRecove...
Script     0.2.9      AzureRM.RecoveryServices.SiteRec... {Edit-AzureRmRecoveryServicesAsrRecoveryPlan, Get-AzureRmRecove...
Script     5.1.0      AzureRM.RedisCache                  {Remove-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCacheSc...
Script     5.0.5      AzureRM.RedisCache                  {Remove-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCacheSc...
Script     0.3.12     AzureRM.Relay                       {New-AzureRmRelayNamespace, Get-AzureRmRelayNamespace, Set-Azur...
Script     0.3.10     AzureRM.Relay                       {New-AzureRmRelayNamespace, Get-AzureRmRelayNamespace, Set-Azur...
Script     6.7.3      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment, Ge...
Script     6.4.2      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment, Ge...
Script     0.16.10    AzureRM.Scheduler                   {Disable-AzureRmSchedulerJobCollection, Enable-AzureRmScheduler...
Script     0.6.13     AzureRM.ServiceBus                  {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace...
Script     0.6.11     AzureRM.ServiceBus                  {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace...
Script     0.3.15     AzureRM.ServiceFabric               {Add-AzureRmServiceFabricApplicationCertificate, Add-AzureRmSer...
Script     0.3.12     AzureRM.ServiceFabric               {Add-AzureRmServiceFabricApplicationCertificate, Add-AzureRmSer...
Script     1.0.0      AzureRM.SignalR                     {New-AzureRmSignalR, Get-AzureRmSignalR, Get-AzureRmSignalRKey,...
Script     4.12.1     AzureRM.Sql                         {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSq...
Script     4.11.3     AzureRM.Sql                         {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSq...
Script     5.2.0      AzureRM.Storage                     {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, New-A...
Script     5.0.4      AzureRM.Storage                     {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, New-A...
Script     4.0.10     AzureRM.StreamAnalytics             {Get-AzureRmStreamAnalyticsFunction, Get-AzureRmStreamAnalytics...
Script     4.0.5      AzureRM.Tags                        {Remove-AzureRmTag, Get-AzureRmTag, New-AzureRmTag}
Script     4.1.3      AzureRM.TrafficManager              {Add-AzureRmTrafficManagerCustomHeaderToEndpoint, Remove-AzureR...
Script     4.1.1      AzureRM.TrafficManager              {Add-AzureRmTrafficManagerCustomHeaderToEndpoint, Remove-AzureR...
Script     4.0.5      AzureRM.UsageAggregates             Get-UsageAggregates
Script     5.2.0      AzureRM.Websites                    {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New-Azur...
Script     5.0.9      AzureRM.Websites                    {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New-Azur...
Script     1.2.297    csc-azure                           {Add-CscArmTemplate, Add-CscArtifactoryFile, Add-CscDatabricksF...
Script     1.2.211    csc-azure                           {Add-CscArmTemplate, Add-CscArtifactoryFile, Add-CscMemberToAAD...
Script     1.0.0.5    DockerMsftProvider
Binary     0.2.3      LogicAppTemplate                    Get-LogicAppTemplate
Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSou...
Script     4.4.1      Pester                              {Describe, Context, It, Should...}
Script     0.7.3      posh-git                            {Invoke-NullCoalescing, Add-PoshGitToProfile, Get-PromptPath, W...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}
Script     0.3.5      powershell-yaml                     {ConvertTo-Yaml, ConvertFrom-Yaml, cfy, cty}
Script     4.1.3      ProtectedData                       {Protect-Data, Unprotect-Data, Get-ProtectedDataSupportedTypes,...
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, Remove-PSR...
Script     1.17.1     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
Binary     0.8.1      SHiPS
Script     0.0.2      Trackyon.Utils                      {Backup-Location, Get-OperatingSystem, New-Directory, Set-As...}
Manifest   4.0.12     VSTeam                              {Add-VSTeamAzureRMServiceEndpoint, Add-VSTeamSonarQubeEndpoint,...

Environment Data

Name                           Value
----                           -----
PSVersion                      5.1.17134.228
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.228
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Debug Output

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

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : 00000000-0000-0000-0000-000000000000
x-ms-ratelimit-remaining-subscription-writes: 1198
x-ms-correlation-request-id   : 7d2b2e43-fbf5-4794-88e5-9e2dd3cf43ee
x-ms-routing-request-id       : CANADAEAST:20190204T222635Z:7d2b2e43-fbf5-4794-88e5-9e2dd3cf43ee
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Mon, 04 Feb 2019 22:26:34 GMT
Server                        : Microsoft-IIS/10.0

Body:
{
  "code": "UnsupportedMetric",
  "message": "Exception of type 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was
thrown."
}

Add-AzureRmAutoscaleSetting : Exception type: ErrorResponseException, Message: Exception of type
'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was thrown., Code: UnsupportedMetric,
Status code:BadRequest, Reason phrase: Bad Request
At line:1 char:9
+         Add-AzureRmAutoscaleSetting @outAddParams
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Add-AzureRmAutoscaleSetting], PSInvalidOperationException
markcowl commented 5 years ago

@l0010o0001l Can you pleae include the request as well from the debug trace - this will help diagnose precisely what is wrong.

l0010o0001l commented 5 years ago

Thanks for the head's up @markcowl. Here it is.

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/02f27965-8f6f-4280-a8ab-02eb0bcc1f15/resourcegroups/integrationtest-api-7
4393/providers/microsoft.insights/autoscalesettings/api-74393-sandbox-de-scale-out?api-version=2015-04-01

Headers:
x-ms-client-request-id        : b592d1a5-c0e9-4cac-aa01-d7549a7585cb
accept-language               : en-US

Body:
{
  "properties": {
    "profiles": [
      {
        "name": "-scale-out-profile",
        "capacity": {
          "minimum": "1",
          "maximum": "2",
          "default": "1"
        },
        "rules": [
          {
            "metricTrigger": {
              "metricName": "HTTPQueueLength",
              "metricResourceUri":
"/subscriptions/02f27965-8f6f-4280-a8ab-02eb0bcc1f15/resourceGroups/integrationtest-api-74393/providers/Microsoft.We
b/sites/api-74393-sandbox-de",
              "timeGrain": "PT1M",
              "statistic": "Average",
              "timeWindow": "PT10M",
              "timeAggregation": "Average",
              "operator": "GreaterThan",
              "threshold": 100.0
            },
            "scaleAction": {
              "direction": "Increase",
              "type": "ChangeCount",
              "value": "1",
              "cooldown": "PT10M"
            }
          }
        ]
      }
    ],
    "enabled": true,
    "targetResourceUri":
"/subscriptions/02f27965-8f6f-4280-a8ab-02eb0bcc1f15/resourceGroups/integrationtest-api-74393/providers/Microsoft.We
b/serverFarms/api-74393-sandbox-de-plan"
  },
  "location": "westus2",
  "tags": {}
}
joshidp commented 5 years ago

Any update on this issue?