azure-cli-extensions icon indicating copy to clipboard operation
azure-cli-extensions copied to clipboard

"az monitor app-insights component create" fails with HTTP Error

Open ChrisKlug opened this issue 4 years ago • 15 comments

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name az monitor app-insights component create Extension Name: application-insights. Version: 0.1.13.

Errors:

'HTTPError' object has no attribute '_message'
Traceback (most recent call last):
cliextensions/application-insights/azext_applicationinsights/custom.py, ln 74, in create_or_update_component
    return client.create_or_update(resource_group_name, application, component)
mgmt_applicationinsights/v2020_02_02_preview/operations/_components_operations.py, ln 359, in create_or_update
...
cliextensions/application-insights/azext_applicationinsights/custom.py, ln 76, in create_or_update_component
    ex.error._message = ex.error._message + HELP_MESSAGE
AttributeError: 'HTTPError' object has no attribute '_message'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az monitor app-insights component create --app {} --location {} --kind {} -g {} --workspace {}

Expected Behavior

An Application Insights resource is created and connected to a workspace

Environment Summary

Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-debian-bullseye-sid
Python 3.6.10
Installer: DEB

azure-cli 2.19.1

Extensions:
application-insights 0.1.13

Additional Context

ChrisKlug avatar Feb 17 '21 11:02 ChrisKlug

monitor

yonzhan avatar Feb 17 '21 11:02 yonzhan

Trying to first create an Insights resource without a workspace, and then update it using az monitor app-insights component update --app {} -g {} --workspace "/subscriptions/XXXXXXXXXXXXX/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/<my-workspace>" causes cli.azure.cli.core.azclierror: Operation failed with status: 'Bad Request'. Details: Could not retrieve Log Analytics workspace.. Even if the workspace definitely exists

ChrisKlug avatar Feb 17 '21 13:02 ChrisKlug

Trying to first create an Insights resource without a workspace, and then update it using az monitor app-insights component update --app {} -g {} --workspace "/subscriptions/XXXXXXXXXXXXX/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/<my-workspace>" causes cli.azure.cli.core.azclierror: Operation failed with status: 'Bad Request'. Details: Could not retrieve Log Analytics workspace.. Even if the workspace definitely exists

Hi ChrisKlug. Please use the name of workspace instead of ID and try again:

az monitor app-insights component update --app {} -g {} --workspace "my-workspace"

BTW we've already written a test case similar to your case. Maybe it can help you.

kairu-ms avatar Feb 18 '21 09:02 kairu-ms

Using just the name caused it to not be found, which makes me believe it uses the same resource group. And in my case, they are not in the same group

ChrisKlug avatar Feb 18 '21 09:02 ChrisKlug

Using just the name caused it to not be found, which makes me believe it uses the same resource group. And in my case, they are not in the same group

I see. Are them in same location and subscription? Different location and subscription may block to access that workspace on service side.

kairu-ms avatar Feb 19 '21 02:02 kairu-ms

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

Issue Details

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name az monitor app-insights component create Extension Name: application-insights. Version: 0.1.13.

Errors:

'HTTPError' object has no attribute '_message'
Traceback (most recent call last):
cliextensions/application-insights/azext_applicationinsights/custom.py, ln 74, in create_or_update_component
    return client.create_or_update(resource_group_name, application, component)
mgmt_applicationinsights/v2020_02_02_preview/operations/_components_operations.py, ln 359, in create_or_update
...
cliextensions/application-insights/azext_applicationinsights/custom.py, ln 76, in create_or_update_component
    ex.error._message = ex.error._message + HELP_MESSAGE
AttributeError: 'HTTPError' object has no attribute '_message'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az monitor app-insights component create --app {} --location {} --kind {} -g {} --workspace {}

Expected Behavior

An Application Insights resource is created and connected to a workspace

Environment Summary

Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-debian-bullseye-sid
Python 3.6.10
Installer: DEB

azure-cli 2.19.1

Extensions:
application-insights 0.1.13

Additional Context

Author: ChrisKlug
Assignees: kairu-ms
Labels:

Monitor, OKR3.2 Candidate, Service Attention, feature-request

Milestone: S184

ghost avatar Feb 19 '21 02:02 ghost

They are both West Europe, in the same subscription

ChrisKlug avatar Feb 19 '21 08:02 ChrisKlug

They are both West Europe, in the same subscription

I've test your scenario (same location and subscription but different resource group), it works for me. image

kairu-ms avatar Feb 22 '21 07:02 kairu-ms

Yeah, it seems like it just started working for some reason on Friday. No changes to the scripts or anything. It just "magically" started working again... Doesn't inspire too much confidence though when it stops and starts working intermittently with the same code... But thanks for looking into it!

ChrisKlug avatar Feb 22 '21 07:02 ChrisKlug

Yeah, it seems like it just started working for some reason on Friday. No changes to the scripts or anything. It just "magically" started working again... Doesn't inspire too much confidence though when it stops and starts working intermittently with the same code... But thanks for looking into it!

It must be caused by an issue on service. Hi @sameergMS, @dadunl. can you help with this issue.

kairu-ms avatar Feb 22 '21 07:02 kairu-ms

Same issue here with a customer.

Different log analytics workspace in a different subscription and resource group per Cloud Adoption Framework. I don't think it's a CLI issue, I think it's a platform issue as it can be replicated in the portal also.

piquet-h avatar Sep 02 '21 21:09 piquet-h

@ChrisKlug @kairu-ms Old topic, any new insights lately?

Looks like an underlying issue, within the Azure platform. I have the same problem, but with Bicep templates. It fails the first time, as far as I know a second BICEP-deployment does it's job. This might explain why it "magically" started working again (comment feb 22, 2021) for Chris.

  • Same Tenant
  • Same Azure Subscription
  • Bicep should figure out dependencies on its own, unlike ARM-templates

Bicep setup:

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
  name: 'loganalytics-nameofproject'
  location: location
  properties: {
    sku: {
      name: 'PerGB2018'
    }
    retentionInDays: 120
    features: {
      searchVersion: 1
      legacy: 0
      enableLogAccessUsingOnlyResourcePermissions: true
    }
  }
}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = { 
  kind: 'web'
  location: location
  name: 'appInsights-nameofproject'
  properties: {
    Application_Type: 'web'
    WorkspaceResourceId: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.OperationalInsights/workspaces/loganalytics-nameofproject'
  }  
}

Azure error info:

Operation name
Update insights component
Time stamp
Thu Sep 29 2022 16:25:23 GMT+0200 (Central European Summer Time)
Event initiated by {...}
Error code
BadRequest
Message
Could not retrieve Log Analytics workspace.

Can it be the same issue? Feel free to contact me for extra details.

merijng avatar Sep 29 '22 14:09 merijng

I am also seeing same issue (intermittent) as @merijng . I am simply deploying a bicep template consisting of a log analytics workspace and application insight and deployment fails occasionally saying 'Could not find the log analytics workspace' though the workspace has been deployed fine already.

@ChrisKlug , @kairu-ms - Do you have any recent update on this issue please. Thanks !!

rahulsaxena1987 avatar May 24 '23 05:05 rahulsaxena1987

@AllyW and @kairu-ms and CC @rahulsaxena1987

I would not focus too much on this specific error. Now I had a different one, for a new project. It fails the first time, and the second time it works. Cannot find Subscription with name {subscriptionid}

It is still on the Update insights component activity, in the Activity log of Azure. Bicep template is still as described in my previous post.

hopefully this helps :)

merijng avatar Jun 26 '23 06:06 merijng

I have the same issue and it didn't work even on the 2nd try.

I'm running this from an azure pipeline. The service connection I use provides me access to the Resource Group A but not to Resource Group B where the Log Analytics Workspace lies. Is this a problem?

I don't want to create a new Log Analytics Workspace. I just want to deploy an Application Insights in RG A that references the Log Analytics Workspace in RG B.

Do I need to update my service connection to provide access not only to RG A but also to RG B?

Thanks!

luisgmgouveia avatar Jan 30 '24 11:01 luisgmgouveia