Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudError: Azure Error: InvalidApiVersionParameter The api-version '2015-05-01' is invalid #4121

Closed
nikundu opened this issue Jan 3, 2019 · 15 comments
Labels
Monitor - ApplicationInsights Service Attention Workflow: This issue is responsible by Azure service team. Swagger

Comments

@nikundu
Copy link

nikundu commented Jan 3, 2019

While creating app-insight resource, I am getting the following error. I am using python 2.7. And below is the output for pip freeze | grep "azure". I am using the following versions
applicationinsights==0.11.7
azure-applicationinsights==0.1.0
azure-mgmt-applicationinsights==0.1.1

ERROR:
autoscaler-config-munger:create_app_insights_resource: 127 - ERROR - App Insight resource api response not have status code 200 or 201 in response. exception details Azure Error: InvalidApiVersionParameter
Message: The api-version '2015-05-01' is invalid. The supported versions are '2018-11-01,2018-09-01,2018-08-01,2018-07-01,2018-06-01,2018-05-01,2018-02-01,2018-01-01,2017-12-01,2017-08-01,2017-06-01,2017-05-10,2017-05-01,2017-03-01,2016-09-01,2016-07-01,2016-06-01,2016-02-01,2015-11-01,2015-01-01,2014-04-01-preview,2014-04-01,2014-01-01,2013-03-01,2014-02-26,2014-04'.
Traceback (most recent call last):
File "/Users/nikundu/Downloads/autoscaler-master/transit/solution-helper/autoscaler-config-munger.py", line 103, in create_app_insights_resource
insights_properties)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/mgmt/applicationinsights/operations/components_operations.py", line 349, in create_or_update
raise exp
CloudError: Azure Error: InvalidApiVersionParameter
Message: The api-version '2015-05-01' is invalid. The supported versions are '2018-11-01,2018-09-01,2018-08-01,2018-07-01,2018-06-01,2018-05-01,2018-02-01,2018-01-01,2017-12-01,2017-08-01,2017

pip freeze output

NIKUNDU-M-P133:~ nikundu$ pip freeze | grep "azure"
azure==4.0.0
azure-applicationinsights==0.1.0
azure-batch==4.1.3
azure-cli-acr==2.1.10
azure-cli-acs==2.3.12
azure-cli-ams==0.3.1
azure-cli-backup==1.2.1
azure-cli-billing==0.2.0
azure-cli-cognitiveservices==0.2.4
azure-cli-command-modules-nspkg==2.0.2
azure-cli-configure==2.0.19
azure-cli-consumption==0.4.0
azure-cli-core==2.0.52
azure-cli-cosmosdb==0.2.5
azure-cli-dms==0.1.1
azure-cli-eventgrid==0.2.0
azure-cli-find==0.2.12
azure-cli-interactive==0.4.0
azure-cli-lab==0.1.4
azure-cli-maps==0.3.2
azure-cli-nspkg==3.0.3
azure-cli-policyinsights==0.1.0
azure-cli-rdbms==0.3.5
azure-cli-reservations==0.4.1
azure-cli-role==2.1.11
azure-cli-servicebus==0.3.2
azure-cli-servicefabric==0.1.9
azure-cli-telemetry==1.0.0
azure-common==1.1.16
azure-cosmosdb-nspkg==2.0.2
azure-cosmosdb-table==1.0.5
azure-datalake-store==0.0.39
azure-eventgrid==1.2.0
azure-graphrbac==0.53.0
azure-keyvault==1.1.0
azure-loganalytics==0.1.0
azure-mgmt==4.0.0
azure-mgmt-advisor==1.0.1
azure-mgmt-applicationinsights==0.1.1
azure-mgmt-authorization==0.50.0
azure-mgmt-batch==5.0.1
azure-mgmt-batchai==2.0.0
azure-mgmt-billing==0.2.0
azure-mgmt-cdn==3.0.0
azure-mgmt-cognitiveservices==3.0.0
azure-mgmt-commerce==1.0.1
azure-mgmt-compute==4.3.1
azure-mgmt-consumption==2.0.0
azure-mgmt-containerinstance==1.4.0
azure-mgmt-containerregistry==2.4.0
azure-mgmt-containerservice==4.2.2
azure-mgmt-cosmosdb==0.5.2
azure-mgmt-datafactory==0.6.0
azure-mgmt-datalake-analytics==0.6.0
azure-mgmt-datalake-nspkg==3.0.1
azure-mgmt-datalake-store==0.5.0
azure-mgmt-datamigration==0.1.0
azure-mgmt-devspaces==0.1.0
azure-mgmt-devtestlabs==2.2.0
azure-mgmt-dns==2.1.0
azure-mgmt-eventgrid==0.4.0
azure-mgmt-eventhub==2.2.0
azure-mgmt-hanaonazure==0.1.1
azure-mgmt-iotcentral==0.1.0
azure-mgmt-iothub==0.5.0
azure-mgmt-iothubprovisioningservices==0.2.0
azure-mgmt-keyvault==1.1.0
azure-mgmt-loganalytics==0.2.0
azure-mgmt-logic==3.0.0
azure-mgmt-machinelearningcompute==0.4.1
azure-mgmt-managementgroups==0.1.0
azure-mgmt-managementpartner==0.1.0
azure-mgmt-maps==0.1.0
azure-mgmt-marketplaceordering==0.1.0
azure-mgmt-media==1.0.1
azure-mgmt-monitor==0.5.2
azure-mgmt-msi==0.2.0
azure-mgmt-network==2.3.0
azure-mgmt-notificationhubs==2.0.0
azure-mgmt-nspkg==3.0.2
azure-mgmt-policyinsights==0.1.0
azure-mgmt-powerbiembedded==2.0.0
azure-mgmt-rdbms==1.5.0
azure-mgmt-recoveryservices==0.1.0
azure-mgmt-recoveryservicesbackup==0.1.1
azure-mgmt-redis==5.0.0
azure-mgmt-relay==0.1.0
azure-mgmt-reservations==0.3.1
azure-mgmt-resource==2.0.0
azure-mgmt-scheduler==2.0.0
azure-mgmt-search==2.0.0
azure-mgmt-servicebus==0.5.3
azure-mgmt-servicefabric==0.2.0
azure-mgmt-signalr==0.1.1
azure-mgmt-sql==0.9.1
azure-mgmt-storage==3.1.0
azure-mgmt-subscription==0.2.0
azure-mgmt-trafficmanager==0.50.0
azure-mgmt-web==0.35.0
azure-nspkg==3.0.2
azure-servicebus==0.21.1
azure-servicefabric==6.3.0.0
azure-servicemanagement-legacy==0.20.6
azure-storage==0.36.0
azure-storage-blob==1.3.1
azure-storage-common==1.4.0
azure-storage-file==1.4.0
azure-storage-nspkg==3.1.0
azure-storage-queue==1.4.0
csr-azure-utils==0.0.97
msrestazure==0.5.1

@vishleshpatel
Copy link

+1

@lmazuel lmazuel added Application Insights Service Attention Workflow: This issue is responsible by Azure service team. labels Jan 4, 2019
@lmazuel
Copy link
Member

lmazuel commented Jan 4, 2019

@alexeldeib what do you think?

@alexeldeib
Copy link
Contributor

alexeldeib commented Jan 4, 2019

I couldn't repro this? I created a fresh venv with 2.7 and pip installed the dependencies listed. Installed azure-cli and ran az login, then ran the following which successfully created the component:

from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.applicationinsights import ApplicationInsightsManagementClient
from azure.mgmt.applicationinsights.models import ApplicationInsightsComponent


client = get_client_from_cli_profile(ApplicationInsightsManagementClient)
component = ApplicationInsightsComponent("East US", "web")
print(client.components.create_or_update("ace-test", "bug-test", component))

Could you share some details on how you are using/instantiating client? 2015-05-01 is definitely a valid API version.

@nikundu
Copy link
Author

nikundu commented Jan 4, 2019

The piece of code that I am using to create this component is shown below.

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.applicationinsights import ApplicationInsightsManagementClient

self.credentials = ServicePrincipalCredentials(
            client_id=self.client_id,
            secret=self.client_secret,
            tenant=self.tenant
        )
        self.network_client = NetworkManagementClient(
            self.credentials, self.subscription_id)
        self.appInsights_client = ApplicationInsightsManagementClient(credentials=self.credentials,
                                                                      subscription_id=self.subscription_id)
    def create_app_insights_resource(self, app_name):
        insights_properties = {}
        insights_properties['location'] = self.region
        insights_properties['kind'] = 'other'
        insights_properties['application_type'] = 'other'
        insights_properties['flow_type'] = 'Bluefield'
        insights_properties['request_source'] = 'rest'

        try:
            self.customer_resource_group = ''
            response = self.appInsights_client.components.create_or_update(self.customer_resource_group,
                                                                           app_name,
                                                                           insights_properties)
            logger.info("App Insight resource created successfully: %s" % response)
            self.instrumentation_key, self.app_id = response.instrumentation_key, response.app_id
        except Exception as e:
            if hasattr(e, 'status_code') and e.status_code == 201:
                if hasattr(e, 'response') and hasattr(e.response, 'content'):
                    content_dict = json.loads(e.response.content)
                    if 'properties' in content_dict and 'AppId' in content_dict['properties']:
                        self.app_id = content_dict['properties']['AppId']
                    else:
                        logger.exception("Instrumentation key don't exist in response content. exception: {}".format(e))
                        return None
                    if 'properties' in content_dict and 'InstrumentationKey' in content_dict['properties']:
                        self.instrumentation_key = content_dict['properties']['InstrumentationKey']
                    else:
                        logger.exception(
                            "Instrumentation key don't exist in response content. exception: {}".format(e))
                        return None
                else:
                    logger.exception("App Insight resource api response do not have either response or content \
                    in response. exception details {}".format(e))
                    return None
            else:
                logger.exception("App Insight resource api response not have status code 200 or 201 \
                    in response. exception details {}".format(e))
                return None

        logger.info("Instrumentation Key and APP ID for App Insights: %s %s" % (self.instrumentation_key, self.app_id))
        os.environ['INSTRUMENTATION_KEY'] = self.instrumentation_key
        os.environ['APP_ID'] = self.app_id
        return self.instrumentation_key, self.app_id

**NOTE:**ERROR - App Insight resource api response not have status code 200 or 201 in response. exception details Azure Error: InvalidApiVersionParameter

@alexeldeib
Copy link
Contributor

@nikundu I'm still not able to repro this using SP authentication and manually newing up a client. Are you experiencing this persistently? Can you provide a fiddler trace of the network calls?

@lmazuel this looks good to me functionally. That error comes from network call through ARM right? I may need to take a look at ARM/RP logs.

from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.applicationinsights import ApplicationInsightsManagementClient
from azure.mgmt.applicationinsights.models import ApplicationInsightsComponent
from azure.common.credentials import ServicePrincipalCredentials

credentials = ServicePrincipalCredentials(
  client_id="removed",
  secret="removed",
  tenant="removed"
)

client = ApplicationInsightsManagementClient(credentials=credentials, subscription_id="removed")

component = ApplicationInsightsComponent("East US", "web")
print(client.components.create_or_update("ace-test", "bug-test-2", component))

@alexeldeib
Copy link
Contributor

Many of the versions listed in that error are not supported by the App Insights API. This makes me feel the client is trying to make a call to a different API using that version, and getting rejected? The URL I see in the implementation looks good, but that set of versions looks like it's from a different RP.

@alexeldeib
Copy link
Contributor

alexeldeib commented Jan 4, 2019

@nikundu issue is here:

self.customer_resource_group = ''
response = self.appInsights_client.components.create_or_update(self.customer_resource_group,
  app_name,
  insights_properties)

Using empty string for resource group name, the URL ends up something like /subscriptions/.../resourceGroups/providers/microsoft.insights/components/foo (missing resource group name in middle, I guess since double slash escapes to single slash). This hits a different backend API which exposes different versions, resulting in the error you see.

@lmazuel
Copy link
Member

lmazuel commented Jan 5, 2019

@alexeldeib To avoid this issue, we usually plug the Swagger with a RG regexp check, that will fail in Python before the call is being made. This is using this common type:
https://github.com/Azure/azure-rest-api-specs/blob/a4368ac83299657f35f105033353c2133db89176/specification/common-types/resource-management/v1/types.json#L290-L300

You can copy paste it, or reference it directly in your swagger with ".." folder syntax.
https://github.com/Azure/azure-rest-api-specs/blob/3f432a5b0af58d49759a20e2b2ef3ebb7ae691b5/specification/storage/resource-manager/Microsoft.Storage/stable/2018-07-01/blob.json#L42

Would you be able to update the Swagger this way? Thanks!

@vishleshpatel
Copy link

Thx a lot @alexeldeib @lmazuel for quickly jumping on this. In my case, it was incorrect app id credentials giving an error.

@nikundu
Copy link
Author

nikundu commented Jan 7, 2019

Thanks @alexeldeib @lmazuel for help me out on this issue. I am able to create app-insights now.

@lmazuel lmazuel added the Swagger label Jan 7, 2019
@plattenschieber
Copy link

@nikundu issue is here:

self.customer_resource_group = ''
response = self.appInsights_client.components.create_or_update(self.customer_resource_group,
  app_name,
  insights_properties)

Using empty string for resource group name, the URL ends up something like >/subscriptions/.../resourceGroups/providers/microsoft.insights/components/foo (missing resource >group name in middle, I guess since double slash escapes to single slash). This hits a different backend > API which exposes different versions, resulting in the error you see.

This error is really mean - thanks for the explanation @alexeldeib 💯 It would be great to include some more details in the error message (e.g. which API was triggered from who) to support finding such neaty errors. Anyone from Microsoft reading this thread?

@alexeldeib
Copy link
Contributor

I'm not sure off the top of my head where this ends up routed, I think it would be on that team to fix (possibly ARM throwing a generic error on resource Id validation?). @lmazuel do you happen to know?

Either way, I will fix the swagger validation per above and PR the fix, which should prevent this once it's baked into the SDK/CLI clients.

@lmazuel
Copy link
Member

lmazuel commented Mar 1, 2019

@alexeldeib could you link your Swagger PR here, so we can track progress on this?
I believe this is routed to ARM itself (Microsoft.Resources). It's that all Swagger checks for non-empty RG name:
https://github.com/Azure/azure-rest-api-specs/blob/c8b825f5e12855c9b5ff29e144bf35a85f607e4a/specification/common-types/resource-management/v1/types.json#L296

@alexeldeib
Copy link
Contributor

@lmazuel sorry for delay -- Azure/azure-rest-api-specs#5505

@ghost
Copy link

ghost commented May 7, 2020

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

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Monitor - ApplicationInsights Service Attention Workflow: This issue is responsible by Azure service team. Swagger
Projects
None yet
Development

No branches or pull requests

7 participants