Azure / azure-powershell

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

Update-AzScheduledQueryRule removed already defined system assigned maanged identity #23352

Open AlyaKoni opened 10 months ago

AlyaKoni commented 10 months ago

Description

I have a already defined alert rule with a system assigned maanged identity. Now I like to update the rule with Update-AzScheduledQueryRule. The update works without any error and the rule is correctly updated. May the system assigned maanged identity is removed from the alert rule.

Issue script & Debug output

$null = Update-AzScheduledQueryRule -InputObject $alertRule.Id `
          -DisplayName $AlertName `
          -Description "Triggers an alert for the condition: $AlertText" `
          -ActionGroupResourceId $ActionGroupId `
          -Enabled:$true `
          -Scope $LogAnaWrkspc.ResourceId `
          -Severity $Severity `
          -WindowSize ([System.TimeSpan]::FromMinutes($TimeWindowInMinutes)) `
          -EvaluationFrequency ([System.TimeSpan]::FromMinutes($FrequencyInMinutes)) `
          -CriterionAllOf $alertCondition

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.9
PSEdition                      Core
GitCommitId                    7.3.9
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.13.1                Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     4.6.0                 Az.Monitor                          {Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2, Add-AzWebtest…
Script     3.2.0                 Az.OperationalInsights              {Disable-AzOperationalInsightsIISLogCollection, Disable-AzOperationalInsightsLin…
Script     6.11.2                Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDepl…

Error output

N/A
isra-fel commented 10 months ago

@JoyerJin did we touch this cmdlet in the latest version of Az.Monitor? If not, please look into this issue. Thanks.

JoyerJin commented 10 months ago

Hi Yeming,

We did not change this cmdlet.

Now the cmdlet api version is 2021-08-01, it is an old version. Azure Portal is using version 2023-03-15-preview. The managed identity for alert rule is preview feature. Could you check with service team?

Here is request and response:

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

HTTP Method:
PATCH

Absolute Uri:
https://management.azure.com/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/ps1-test/providers/Microsoft.Insights/scheduledQueryRules/test-rule-joyer?api-version=2021-08-01

Headers:
x-ms-unique-id                : 8
x-ms-client-request-id        : 1a367593-5510-47c6-a182-e4190412d4c1
CommandName                   : Update-AzScheduledQueryRule
FullCommandName               : Update-AzScheduledQueryRule_UpdateExpanded
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v11.0.0,PSVersion/v7.3.9,Az.ScheduledQueryRule/5.0.0

Body:
{
  "properties": {
    "description": "triggers",
    "displayName": "test",
    "enabled": true,
    "scopes": [
      "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/ps1-test/providers/Microsoft.Compute/virtualMachines/test-vm"
    ]
  }
}

DEBUG: 2:26:05 PM - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: BeforeCall: 
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id               : d9f9126b-f411-4ce1-96e6-1226f6cbe3f7
x-ms-correlation-request-id   : d9f9126b-f411-4ce1-96e6-1226f6cbe3f7
x-ms-routing-request-id       : JAPANEAST:20231117T062609Z:d9f9126b-f411-4ce1-96e6-1226f6cbe3f7
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
X-Cache                       : CONFIG_NOCACHE
X-MSEdge-Ref                  : Ref A: D7BA4EF5DE0D418899F96F6315B6C16E Ref B: TYO201100114029 Ref C: 2023-11-17T06:26:03Z
Date                          : Fri, 17 Nov 2023 06:26:08 GMT

Body:
{
  "id": "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/ps1-test/providers/microsoft.insights/scheduledqueryrules/test-rule-joyer",
  "name": "test-rule-joyer",
  "type": "microsoft.insights/scheduledqueryrules",
  "location": "eastus",
  "systemData": {
    "createdBy": "v-jiaji@microsoft.com",
    "createdByType": "User",
    "createdAt": "2023-11-17T06:24:57.5350349Z",
    "lastModifiedBy": "v-jiaji@microsoft.com",
    "lastModifiedByType": "User",
    "lastModifiedAt": "2023-11-17T06:26:03.7117592Z"
  },
  "properties": {
    "createdWithApiVersion": "2021-08-01",
    "displayName": "test",
    "description": "triggers",
    "severity": 4,
    "enabled": true,
    "evaluationFrequency": "PT5M",
    "scopes": [
      "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/ps1-test/providers/Microsoft.Compute/virtualMachines/test-vm"
    ],
    "windowSize": "PT10M",
    "criteria": {
      "allOf": [
        {
          "query": "Perf | where ObjectName == \"Processor\" and CounterName == \"% Processor Time\" | summarize AggregatedValue = avg(CounterValue) by bin(TimeGenerated, 5m), Computer",
          "timeAggregation": "Average",
          "metricMeasureColumn": "AggregatedValue",
          "dimensions": [
            {
              "name": "Computer",
              "operator": "Include",
              "values": [
                "*"
              ]
            }
          ],
          "operator": "GreaterThan",
          "threshold": 70.0,
          "failingPeriods": {
            "numberOfEvaluationPeriods": 1,
            "minFailingPeriodsToAlert": 1
          }
        }
      ]
    }
  }
}

Thanks, Joyer

isra-fel commented 10 months ago

As @JoyerJin showed, the Update-AzScheduledQueryRule cmdlet sent a PATCH API to perform a partial update, which should not impact the other properties such as managed identity. I'll loop in service team to identify if this is a bug.

microsoft-github-policy-service[bot] commented 10 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @AzmonAlerts.