prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  app-insights az cli extension seems not working properly in AzureChinaCloud (China East 2)
  - If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)
  
  ### Extension name (the extension in question)
  application-insights
  
  ### Description of issue (in as much detail as possible)
  I have properly logged in with a certain subscription in AzureChinaCloud (China East2)
  ```
  az account show
  {
    "environmentName": "AzureChinaCloud",
    "id": "5b5d5f37-8aca-49f8-8682-7ed6d2f00424",
    "isDefault": true,
    "name": "Project Vienna PROD - ChinaEast2",
    "state": "Enabled",
    "tenantId": "a55a4d5b-9241-49b1-b4ff-befa8db00269",
    "user": {
      "name": "oe-wanglongjiang@cme.gbl",
      "type": "user"
    }
  }
  ```
  However run any az monitor app-insights command always failed with error "The subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found" 
  
  for example, api-key show
  ```
  az monitor app-insights api-key show --app model-monitoring-chinaeast2 --resource-group model-mgmt-chinaeast2 --api-key MMSModelMonitoringApiKey
  The subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found.
  ```
  
  I doubted application-insights is not working in AzureChinaCloud, any insight of it? Appreciate
  
  </issue>
  <code>
  [start of src/application-insights/setup.py]
  1 #!/usr/bin/env python
  2 
  3 # --------------------------------------------------------------------------------------------
  4 # Copyright (c) Microsoft Corporation. All rights reserved.
  5 # Licensed under the MIT License. See License.txt in the project root for license information.
  6 # --------------------------------------------------------------------------------------------
  7 
  8 from codecs import open
  9 from setuptools import setup, find_packages
  10 
  11 VERSION = "0.1.1"
  12 
  13 CLASSIFIERS = [
  14     'Development Status :: 4 - Beta',
  15     'Intended Audience :: Developers',
  16     'Intended Audience :: System Administrators',
  17     'Programming Language :: Python',
  18     'Programming Language :: Python :: 2',
  19     'Programming Language :: Python :: 2.7',
  20     'Programming Language :: Python :: 3',
  21     'Programming Language :: Python :: 3.4',
  22     'Programming Language :: Python :: 3.5',
  23     'Programming Language :: Python :: 3.6',
  24     'License :: OSI Approved :: MIT License',
  25 ]
  26 
  27 DEPENDENCIES = []
  28 
  29 with open('README.rst', 'r', encoding='utf-8') as f:
  30     README = f.read()
  31 with open('HISTORY.rst', 'r', encoding='utf-8') as f:
  32     HISTORY = f.read()
  33 
  34 setup(
  35     name='application-insights',
  36     version=VERSION,
  37     description='Support for managing Application Insights components and querying metrics, events, and logs from such components.',
  38     long_description=README + '\n\n' + HISTORY,
  39     license='MIT',
  40     author='Ace Eldeib',
  41     author_email='aleldeib@microsoft.com',
  42     url='https://github.com/Azure/azure-cli-extensions/tree/master/src/application-insights',
  43     classifiers=CLASSIFIERS,
  44     packages=find_packages(exclude=["tests"]),
  45     package_data={'azext_applicationinsights': ['azext_metadata.json']},
  46     install_requires=DEPENDENCIES
  47 )
  48
  [end of src/application-insights/setup.py]
  [start of src/application-insights/azext_applicationinsights/_client_factory.py]
  1 # --------------------------------------------------------------------------------------------
  2 # Copyright (c) Microsoft Corporation. All rights reserved.
  3 # Licensed under the MIT License. See License.txt in the project root for license information.
  4 # --------------------------------------------------------------------------------------------
  5 
  6 
  7 def applicationinsights_data_plane_client(cli_ctx, _, subscription=None):
  8     """Initialize Log Analytics data client for use with CLI."""
  9     from .vendored_sdks.applicationinsights import ApplicationInsightsDataClient
  10     from azure.cli.core._profile import Profile
  11     profile = Profile(cli_ctx=cli_ctx)
  12     cred, _, _ = profile.get_login_credentials(
  13         resource="https://api.applicationinsights.io",
  14         subscription_id=subscription
  15     )
  16     return ApplicationInsightsDataClient(cred)
  17 
  18 
  19 def applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):
  20     """Initialize Log Analytics mgmt client for use with CLI."""
  21     from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient
  22     from azure.cli.core._profile import Profile
  23     profile = Profile(cli_ctx=cli_ctx)
  24     # Use subscription from resource_id where possible, otherwise use login.
  25     if subscription:
  26         cred, _, _ = profile.get_login_credentials(subscription_id=subscription)
  27         return ApplicationInsightsManagementClient(
  28             cred,
  29             subscription
  30         )
  31     cred, sub_id, _ = profile.get_login_credentials()
  32     return ApplicationInsightsManagementClient(
  33         cred,
  34         sub_id
  35     )
  36 
  37 
  38 def cf_query(cli_ctx, _, subscription=None):
  39     return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).query
  40 
  41 
  42 def cf_metrics(cli_ctx, _, subscription=None):
  43     return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).metrics
  44 
  45 
  46 def cf_events(cli_ctx, _, subscription=None):
  47     return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).events
  48 
  49 
  50 def cf_components(cli_ctx, _, subscription=None):
  51     return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).components
  52 
  53 
  54 def cf_api_key(cli_ctx, _, subscription=None):
  55     return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).api_keys
  56
  [end of src/application-insights/azext_applicationinsights/_client_factory.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/application-insights/azext_applicationinsights/_client_factory.py b/src/application-insights/azext_applicationinsights/_client_factory.py
  --- a/src/application-insights/azext_applicationinsights/_client_factory.py
  +++ b/src/application-insights/azext_applicationinsights/_client_factory.py
  @@ -10,7 +10,7 @@
       from azure.cli.core._profile import Profile
       profile = Profile(cli_ctx=cli_ctx)
       cred, _, _ = profile.get_login_credentials(
  -        resource="https://api.applicationinsights.io",
  +        resource=cli_ctx.cloud.endpoints.app_insights_resource_id,
           subscription_id=subscription
       )
       return ApplicationInsightsDataClient(cred)
  @@ -19,20 +19,8 @@
   def applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):
       """Initialize Log Analytics mgmt client for use with CLI."""
       from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient
  -    from azure.cli.core._profile import Profile
  -    profile = Profile(cli_ctx=cli_ctx)
  -    # Use subscription from resource_id where possible, otherwise use login.
  -    if subscription:
  -        cred, _, _ = profile.get_login_credentials(subscription_id=subscription)
  -        return ApplicationInsightsManagementClient(
  -            cred,
  -            subscription
  -        )
  -    cred, sub_id, _ = profile.get_login_credentials()
  -    return ApplicationInsightsManagementClient(
  -        cred,
  -        sub_id
  -    )
  +    from azure.cli.core.commands.client_factory import get_mgmt_service_client
  +    return get_mgmt_service_client(cli_ctx, ApplicationInsightsManagementClient, subscription_id=subscription)
   
   
   def cf_query(cli_ctx, _, subscription=None):
  diff --git a/src/application-insights/setup.py b/src/application-insights/setup.py
  --- a/src/application-insights/setup.py
  +++ b/src/application-insights/setup.py
  @@ -8,7 +8,7 @@
   from codecs import open
   from setuptools import setup, find_packages
   
  -VERSION = "0.1.1"
  +VERSION = "0.1.2"
   
   CLASSIFIERS = [
       'Development Status :: 4 - Beta',
  
verification_info: {"golden_diff": "diff --git a/src/application-insights/azext_applicationinsights/_client_factory.py b/src/application-insights/azext_applicationinsights/_client_factory.py\n--- a/src/application-insights/azext_applicationinsights/_client_factory.py\n+++ b/src/application-insights/azext_applicationinsights/_client_factory.py\n@@ -10,7 +10,7 @@\n     from azure.cli.core._profile import Profile\n     profile = Profile(cli_ctx=cli_ctx)\n     cred, _, _ = profile.get_login_credentials(\n-        resource=\"https://api.applicationinsights.io\",\n+        resource=cli_ctx.cloud.endpoints.app_insights_resource_id,\n         subscription_id=subscription\n     )\n     return ApplicationInsightsDataClient(cred)\n@@ -19,20 +19,8 @@\n def applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):\n     \"\"\"Initialize Log Analytics mgmt client for use with CLI.\"\"\"\n     from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient\n-    from azure.cli.core._profile import Profile\n-    profile = Profile(cli_ctx=cli_ctx)\n-    # Use subscription from resource_id where possible, otherwise use login.\n-    if subscription:\n-        cred, _, _ = profile.get_login_credentials(subscription_id=subscription)\n-        return ApplicationInsightsManagementClient(\n-            cred,\n-            subscription\n-        )\n-    cred, sub_id, _ = profile.get_login_credentials()\n-    return ApplicationInsightsManagementClient(\n-        cred,\n-        sub_id\n-    )\n+    from azure.cli.core.commands.client_factory import get_mgmt_service_client\n+    return get_mgmt_service_client(cli_ctx, ApplicationInsightsManagementClient, subscription_id=subscription)\n \n \n def cf_query(cli_ctx, _, subscription=None):\ndiff --git a/src/application-insights/setup.py b/src/application-insights/setup.py\n--- a/src/application-insights/setup.py\n+++ b/src/application-insights/setup.py\n@@ -8,7 +8,7 @@\n from codecs import open\n from setuptools import setup, find_packages\n \n-VERSION = \"0.1.1\"\n+VERSION = \"0.1.2\"\n \n CLASSIFIERS = [\n     'Development Status :: 4 - Beta',\n", "issue": "app-insights az cli extension seems not working properly in AzureChinaCloud (China East 2)\n- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)\r\n\r\n### Extension name (the extension in question)\r\napplication-insights\r\n\r\n### Description of issue (in as much detail as possible)\r\nI have properly logged in with a certain subscription in AzureChinaCloud (China East2)\r\n```\r\naz account show\r\n{\r\n  \"environmentName\": \"AzureChinaCloud\",\r\n  \"id\": \"5b5d5f37-8aca-49f8-8682-7ed6d2f00424\",\r\n  \"isDefault\": true,\r\n  \"name\": \"Project Vienna PROD - ChinaEast2\",\r\n  \"state\": \"Enabled\",\r\n  \"tenantId\": \"a55a4d5b-9241-49b1-b4ff-befa8db00269\",\r\n  \"user\": {\r\n    \"name\": \"oe-wanglongjiang@cme.gbl\",\r\n    \"type\": \"user\"\r\n  }\r\n}\r\n```\r\nHowever run any az monitor app-insights command always failed with error \"The subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found\" \r\n\r\nfor example, api-key show\r\n```\r\naz monitor app-insights api-key show --app model-monitoring-chinaeast2 --resource-group model-mgmt-chinaeast2 --api-key MMSModelMonitoringApiKey\r\nThe subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found.\r\n```\r\n\r\nI doubted application-insights is not working in AzureChinaCloud, any insight of it? Appreciate\n", "before_files": [{"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.1.1\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = []\n\nwith open('README.rst', 'r', encoding='utf-8') as f:\n    README = f.read()\nwith open('HISTORY.rst', 'r', encoding='utf-8') as f:\n    HISTORY = f.read()\n\nsetup(\n    name='application-insights',\n    version=VERSION,\n    description='Support for managing Application Insights components and querying metrics, events, and logs from such components.',\n    long_description=README + '\\n\\n' + HISTORY,\n    license='MIT',\n    author='Ace Eldeib',\n    author_email='aleldeib@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions/tree/master/src/application-insights',\n    classifiers=CLASSIFIERS,\n    packages=find_packages(exclude=[\"tests\"]),\n    package_data={'azext_applicationinsights': ['azext_metadata.json']},\n    install_requires=DEPENDENCIES\n)\n", "path": "src/application-insights/setup.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\n\ndef applicationinsights_data_plane_client(cli_ctx, _, subscription=None):\n    \"\"\"Initialize Log Analytics data client for use with CLI.\"\"\"\n    from .vendored_sdks.applicationinsights import ApplicationInsightsDataClient\n    from azure.cli.core._profile import Profile\n    profile = Profile(cli_ctx=cli_ctx)\n    cred, _, _ = profile.get_login_credentials(\n        resource=\"https://api.applicationinsights.io\",\n        subscription_id=subscription\n    )\n    return ApplicationInsightsDataClient(cred)\n\n\ndef applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):\n    \"\"\"Initialize Log Analytics mgmt client for use with CLI.\"\"\"\n    from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient\n    from azure.cli.core._profile import Profile\n    profile = Profile(cli_ctx=cli_ctx)\n    # Use subscription from resource_id where possible, otherwise use login.\n    if subscription:\n        cred, _, _ = profile.get_login_credentials(subscription_id=subscription)\n        return ApplicationInsightsManagementClient(\n            cred,\n            subscription\n        )\n    cred, sub_id, _ = profile.get_login_credentials()\n    return ApplicationInsightsManagementClient(\n        cred,\n        sub_id\n    )\n\n\ndef cf_query(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).query\n\n\ndef cf_metrics(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).metrics\n\n\ndef cf_events(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).events\n\n\ndef cf_components(cli_ctx, _, subscription=None):\n    return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).components\n\n\ndef cf_api_key(cli_ctx, _, subscription=None):\n    return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).api_keys\n", "path": "src/application-insights/azext_applicationinsights/_client_factory.py"}]}