You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何引用嵌套子资源?Azure ML在线部署诊断配置问题

Azure ML在线部署诊断设置的ARM模板数组引用方案

要为Azure机器学习在线部署(Machine Learning Online Deployments)添加诊断设置,但在线部署是在线端点(Machine Learning Online Endpoint)的子资源,且两者均为数组形式,无法正确引用资源定义。

原可正常运行的ARM模板如下:

@description('Subscription ID where the resources are located.')
param subscriptionId string

@description('Name of the resource group containing the resources.')
param resourceGroupName string

@description('The name of the existing Operational Insights (Log Analytics) workspace.')
param logWorkspaceName string

@description('The name of the existing Azure Machine Learning workspace.')
param machineLearningWorkspaceName string

@description('The name of the existing Azure Machine Learning Workspace Online Endpoints.')
param onlineEndpoints array

@description('Reference to the existing Operational Insights workspace.')
resource operationalInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
  name: logWorkspaceName
  scope: resourceGroup(subscriptionId, resourceGroupName)
}

@description('Reference to the existing Azure Machine Learning Workspace resource.')
resource machineLearningWorkspace 'Microsoft.MachineLearningServices/workspaces@2024-10-01' existing = {
  name: machineLearningWorkspaceName
}

resource machineLearningWorkspaceOnlineEndpoints 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints@2024-10-01' existing = [
  for onlineEndpoint in onlineEndpoints: {
    #disable-next-line use-parent-property
    name: '${machineLearningWorkspace.name}/${onlineEndpoint}'
  }
]

@description('Diagnostic settings for Machine Learning Workspace Online Endpoints')
resource diagnosticsOnlineEndpoints 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
  for (onlineEndpoint, i) in onlineEndpoints: {
    name: '${onlineEndpoint}diag'
    scope: machineLearningWorkspaceOnlineEndpoints[i]
    properties: {
      logAnalyticsDestinationType: 'Dedicated'
      workspaceId: operationalInsightsWorkspace.id
      logs: [
        {
          category: null
          categoryGroup: 'allLogs'
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
      metrics: [
        {
          category: 'Traffic'
          timeGrain: null
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
    }
  }
]

用户尝试的错误代码(无法正确关联端点和部署):

resource machineLearningWorkspaceOnlineDeployments 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments@2024-10-01' existing = [
  for onlineDeployment in onlineDeployments: {
    #disable-next-line use-parent-property
    name: '${machineLearningWorkspace.name}/${onlineEndpoint}/${onlineDeployment}'
  }
]

解决方案

问题核心在于原参数设计没有关联端点和其对应的部署,需要调整参数结构,让每个端点明确对应自己的部署列表,再通过嵌套循环实现资源引用和诊断设置创建。

步骤1:调整参数定义

将原onlineEndpoints数组参数修改为对象数组,每个对象包含端点名称和对应的部署列表:

@description('Existing Azure Machine Learning Online Endpoints and their deployments')
param endpointsWithDeployments array = [
  {
    endpointName: 'endpoint1'
    deployments: ['deployment1', 'deployment2']
  }
  {
    endpointName: 'endpoint2'
    deployments: ['deployment3']
  }
]

步骤2:引用在线部署资源

通过嵌套for循环,先遍历每个端点,再遍历该端点下的所有部署,创建资源引用:

resource machineLearningWorkspaceOnlineDeployments 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments@2024-10-01' existing = [
  for endpoint in endpointsWithDeployments: {
    for deployment in endpoint.deployments: {
      #disable-next-line use-parent-property
      name: '${machineLearningWorkspace.name}/${endpoint.endpointName}/${deployment}'
    }
  }
]

步骤3:为在线部署创建诊断设置

同样使用嵌套循环,为每个部署生成对应的诊断设置:

@description('Diagnostic settings for Machine Learning Workspace Online Deployments')
resource diagnosticsOnlineDeployments 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
  for endpoint in endpointsWithDeployments: {
    for deployment in endpoint.deployments: {
      name: '${endpoint.endpointName}-${deployment}-diag'
      scope: machineLearningWorkspaceOnlineDeployments[endpoint.endpointName][deployment]
      properties: {
        logAnalyticsDestinationType: 'Dedicated'
        workspaceId: operationalInsightsWorkspace.id
        logs: [
          {
            category: null
            categoryGroup: 'allLogs'
            enabled: true
            retentionPolicy: {
              days: 0
              enabled: false
            }
          }
        ]
        metrics: [
          {
            category: 'Traffic'
            timeGrain: null
            enabled: true
            retentionPolicy: {
              days: 0
              enabled: false
            }
          }
        ]
      }
    }
  }
]

完整修改后的ARM模板

@description('Subscription ID where the resources are located.')
param subscriptionId string

@description('Name of the resource group containing the resources.')
param resourceGroupName string

@description('The name of the existing Operational Insights (Log Analytics) workspace.')
param logWorkspaceName string

@description('The name of the existing Azure Machine Learning workspace.')
param machineLearningWorkspaceName string

@description('Existing Azure Machine Learning Online Endpoints and their deployments')
param endpointsWithDeployments array = [
  {
    endpointName: 'endpoint1'
    deployments: ['deployment1', 'deployment2']
  }
  {
    endpointName: 'endpoint2'
    deployments: ['deployment3']
  }
]

@description('Reference to the existing Operational Insights workspace.')
resource operationalInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
  name: logWorkspaceName
  scope: resourceGroup(subscriptionId, resourceGroupName)
}

@description('Reference to the existing Azure Machine Learning Workspace resource.')
resource machineLearningWorkspace 'Microsoft.MachineLearningServices/workspaces@2024-10-01' existing = {
  name: machineLearningWorkspaceName
}

// 引用在线端点资源
resource machineLearningWorkspaceOnlineEndpoints 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints@2024-10-01' existing = [
  for endpoint in endpointsWithDeployments: {
    name: '${machineLearningWorkspace.name}/${endpoint.endpointName}'
  }
]

// 引用在线部署资源
resource machineLearningWorkspaceOnlineDeployments 'Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments@2024-10-01' existing = [
  for endpoint in endpointsWithDeployments: {
    for deployment in endpoint.deployments: {
      #disable-next-line use-parent-property
      name: '${machineLearningWorkspace.name}/${endpoint.endpointName}/${deployment}'
    }
  }
]

// 在线端点的诊断设置
@description('Diagnostic settings for Machine Learning Workspace Online Endpoints')
resource diagnosticsOnlineEndpoints 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
  for endpoint in endpointsWithDeployments: {
    name: '${endpoint.endpointName}diag'
    scope: machineLearningWorkspaceOnlineEndpoints[endpoint.endpointName]
    properties: {
      logAnalyticsDestinationType: 'Dedicated'
      workspaceId: operationalInsightsWorkspace.id
      logs: [
        {
          category: null
          categoryGroup: 'allLogs'
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
      metrics: [
        {
          category: 'Traffic'
          timeGrain: null
          enabled: true
          retentionPolicy: {
            days: 0
            enabled: false
          }
        }
      ]
    }
  }
]

// 在线部署的诊断设置
@description('Diagnostic settings for Machine Learning Workspace Online Deployments')
resource diagnosticsOnlineDeployments 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
  for endpoint in endpointsWithDeployments: {
    for deployment in endpoint.deployments: {
      name: '${endpoint.endpointName}-${deployment}-diag'
      scope: machineLearningWorkspaceOnlineDeployments[endpoint.endpointName][deployment]
      properties: {
        logAnalyticsDestinationType: 'Dedicated'
        workspaceId: operationalInsightsWorkspace.id
        logs: [
          {
            category: null
            categoryGroup: 'allLogs'
            enabled: true
            retentionPolicy: {
              days: 0
              enabled: false
            }
          }
        ]
        metrics: [
          {
            category: 'Traffic'
            timeGrain: null
            enabled: true
            retentionPolicy: {
              days: 0
              enabled: false
            }
          }
        ]
      }
    }
  }
]

内容的提问来源于stack exchange,提问作者Guilherme Matheus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 15:53:20