Azure部署:首次部署时的UnsupportedMetric

huangapple go评论69阅读模式
英文:

Azure Deployment: UnsupportedMetric on first deploy

问题

我们面临一个烦人的问题,在首次部署新环境时出现错误:

resource: /subscriptions/XX/resourceGroups/rg-YY/providers/Microsoft.Web/serverfarms/plan-ZZ, 
metricnamespace: microsoft.web/serverfarms, metricname: CpuPercentage (Code: UnsupportedMetric)

如果重新部署,一切正常。根据文档,应该支持度量标准 'CpuPercentage':https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftwebserverfarms

我们的 Bicep 代码:

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appName
  location: location
  kind: 'windows'
  properties: {
    reserved: false
    maximumElasticWorkerCount: 10
  }
  sku: {
    tier: tier
    name: skuName
  }
  tags: tags
}

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-${appName}'
  location: location
  tags: tags
  properties: {
    targetResourceLocation: location
    targetResourceUri: appServicePlan.id
    enabled: true
    name: 'autoscale-${appName}'
    profiles: [
      {
        capacity: {
          default: '1'
          maximum: '3'
          minimum: '1'
        }
        name: 'DefaultAutoscaleProfile'
        rules: [
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'GreaterThan'
              threshold: 70
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Increase'
              type: 'ChangeCount'
              value: '1'
            }
          }
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'LessThan'
              threshold: 45
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Decrease'
              type: 'ChangeCount'
              value: '1'
            }
          }
        ]
      }
    ]    
  }
}

关于可能引起此问题的原因或是否有任何解决方法有何想法吗?已尝试拆分为单独的模块以引入一些延迟,但似乎也不起作用。

英文:

We are facing an annoying problem where we are getting an error on the first deployment attempt of a fresh environment:

resource: /subscriptions/XX/resourceGroups/rg-YY/providers/Microsoft.Web/serverfarms/plan-ZZ, 
metricnamespace: microsoft.web/serverfarms, metricname: CpuPercentage (Code: UnsupportedMetric)

If we redeploy then everything works. The metric 'CpuPercentage' should be supported according to the documentation: https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftwebserverfarms

Our Bicep code:

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appName
  location: location
  kind: 'windows'
  properties: {
    reserved: false
    maximumElasticWorkerCount: 10
  }
  sku: {
    tier: tier
    name: skuName
  }
  tags: tags
}


resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-${appName}'
  location: location
  tags: tags
  properties: {
    targetResourceLocation: location
    targetResourceUri: appServicePlan.id
    enabled: true
    name: 'autoscale-${appName}'
    profiles: [
      {
        capacity: {
          default: '1'
          maximum: '3'
          minimum: '1'
        }
        name: 'DefaultAutoscaleProfile'
        rules: [
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'GreaterThan'
              threshold: 70
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Increase'
              type: 'ChangeCount'
              value: '1'
            }
          }
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'LessThan'
              threshold: 45
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Decrease'
              type: 'ChangeCount'
              value: '1'
            }
          }
        ]
      }
    ]    
  }
}

Any ideas as to what might cause this or if there is any workaround? Tried to split into separate modules to introduce a little bit of delay but that does not seem to work either.

答案1

得分: 1

Azure部署:首次部署时不支持的度量标准错误:

通常,不支持的度量标准错误是由于代码中提供的度量标准不受特定Azure资源支持而引起的。

但是,“CpuPercentage”应该受支持,因为它在MS Doc中明确给出。新添加的资源可能需要一些时间才能使度量标准可用。

在这种情况下,经常重新部署部署通常可以解决问题,因为度量标准将会在那时可用。

尽管重新部署可以快速解决问题,但还有另一种方法可以解决这个问题。您可以通过在现有代码中添加一个部署脚本,并使用一些部署的时间来添加一个超时标志来解决此问题。使用部署脚本模板并根据您的环境更改“timeout”标志的值。

resource awaitscript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
  name: ''
  location: location
  kind: 'AzurePowerShell'
  properties: {
    azPowerShellVersion: '9.7'
    scriptContent: '''
    timeout: 'PT40M'
    retentionInterval: ''
    '''
  }
}

添加了上面的内容后,按照以下方式添加一个“dependsOn”块,以指出等待脚本和应用服务计划:

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-lalluapp'
  ....code....
  dependsOn: [
    appServicePlan,
    awaitscript
  ]
}

我在我的环境中尝试了与您相同的代码,没有添加任何部署脚本,并且在第一次部署中就成功了。

main.bicep

param webAppName string = ''
param location string = resourceGroup().location 
var appServiceplanname = ''

resource appServicePlan 'Microsoft.Web/serverfarms@2020-06-01' = {
  name: appServiceplanname
  location: location
  properties: {
    reserved: true
  }
  sku: {
    name: sku
  }
  kind: 'linux'
}

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-lalluapp'
  location: location
  properties: {
    targetResourceLocation: location
    targetResourceUri: appServicePlan.id
    enabled: true
    name: 'autoscale-lalluapp'
    profiles: [
      {
        capacity: {
          default: '1'
          maximum: '3'
          minimum: '1'
        }
        name: 'DefaultAutoscaleProfile'
        rules: [
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'GreaterThan'
              threshold: 70
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Increase'
              type: 'ChangeCount'
              value: '1'
            }
          }
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'LessThan'
              threshold: 45
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Decrease'
              type: 'ChangeCount'
              value: '1'
            }
          }
        ]
      }
    ]
  }
}

main.parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"value": "xxxxxapp"
},
"sku": {
"value": "F1"
},
"linuxFxVersion": {
"value": "xxxx"
     }
   }
}

部署成功:

Azure部署:首次部署时的UnsupportedMetric

Azure部署:首次部署时的UnsupportedMetric

Azure部署:首次部署时的UnsupportedMetric

有关相关问题,请参阅MS github

英文:

> Azure Deployment: Unsupported Metric on first deploy:

Usually, unsupported Metric error comes when the metrics given in the code is not supported for specific Azure resource.

But "CpuPercentage" should be supported as it is also given in MS Doc clearly. It may take some more time for the metrics to become available for newly added resources.

In such case, redeploying the deployment frequently resolves the issue because the metrics will be available by then.

Though redeploying fixes the issue quickly, there is another way to resolve this. You can add a deployment script in the existing code by adding a timeout flag with some time period for deployment. Use deployment script templates and alter the timeout flag value as per your environment.

resource  awaitscript  'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: ''
location: location
kind: 'AzurePowerShell'
properties: {
azPowerShellVersion: '9.7'
scriptContent: '''
timeout: 'PT40M'
retentionInterval: ''
'''
}
}

Once you added the above one, Add a dependsOn block to point out the await script & an app service plan as shown.

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-lalluapp'
....code...
dependsOn: [
    appServicePlan,
    awaitscript
  ]
}

I tried the same code as you in my environment without adding any deployment scripts and it worked for me in the first deployment itself.

main.bicep:

param webAppName string = ''
param location string = resourceGroup().location 
var appServiceplanname = ''

resource appServicePlan 'Microsoft.Web/serverfarms@2020-06-01' = {
  name: appServiceplanname
  location: location
  properties: {
    reserved: true
  }
  sku: {
    name: sku
  }
  kind: 'linux'
}

resource autoscaleSettings 'Microsoft.Insights/autoscalesettings@2015-04-01' = {
  name: 'autoscale-lalluapp'
  location: location
  //tags: ''
  properties: {
    targetResourceLocation: location
    targetResourceUri: appServicePlan.id
    enabled: true
    name: 'autoscale-lalluapp'
    profiles: [
      {
        capacity: {
          default: '1'
          maximum: '3'
          minimum: '1'
        }
        name: 'DefaultAutoscaleProfile'
        rules: [
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'GreaterThan'
              threshold: 70
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Increase'
              type: 'ChangeCount'
              value: '1'
            }
          }
          {
            metricTrigger: {
              dimensions: []
              metricName: 'CpuPercentage'
              metricNamespace: 'microsoft.web/serverfarms'
              metricResourceUri: appServicePlan.id
              dividePerInstance: false
              timeGrain: 'PT1M'
              statistic: 'Average'
              timeWindow: 'PT10M'
              timeAggregation: 'Average'
              operator: 'LessThan'
              threshold: 45
            }
            scaleAction: {
              cooldown: 'PT10M'
              direction: 'Decrease'
              type: 'ChangeCount'
              value: '1'
            }
          }
        ]
      }
    ]
  }
}

main.parameters.json:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"value": "xxxxxapp"
},
"sku": {
"value": "F1"
},
"linuxFxVersion": {
"value": "xxxx"
     }
   }
}

Deployment succeeded:

Azure部署:首次部署时的UnsupportedMetric

Azure部署:首次部署时的UnsupportedMetric

Azure部署:首次部署时的UnsupportedMetric

Refer MS github for the relevant issues.

huangapple
  • 本文由 发表于 2023年6月8日 21:15:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76432252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定