2
votes

I'm working on deploying an application to Azure Gov Cloud Stage & Prod. On Dev & QA we use APIM connected to AppInsights to gather statistics and generate alerts, however, AppInsights is not available in Stage Gov Cloud.

  1. Is there any official timeline for availability of Application Insights in Gov Cloud on Stage?

  2. As a workaround we planned to create an Application Insights resource on Dev (say AI-dev) which would be associated with APIM in Stage (say APIM-stage). However, when we want to do the association, we go to APIM-stage in Azure Portal and try to select an Application Insights resource - there is none available, the existing AppInsights resources in Dev and QA are not visible from the the APIM in Stage. Is it possible to configure Stage in such a way they will be visible? If yes, then how? We are looking for any means to make this association - either manually or automatically with an API.

  3. Is there any other workaround available to gather application/APIM request statistics for Stage/Prod deployments? The ultimate goal is to have request alerts (e.g. for bad requests) working for Stage/Prod.

1

1 Answers

0
votes

Here is what we've found after investigation:

  1. Microsoft says that the target date for having Application Insights in Gov Cloud on Stage is end of Q4 2018 - as of 10/11/2018.

2./3.

It is possible to associate Application Insights located in Dev (Commercial Cloud) with APIM located in Gov Cloud Stage in two ways - either using VSTS pipeline tasks or REST API. It turns out that Azure Portal GUI will still not show any association or show an invalid association after doing that but the end result is it's working.

Method 1 (tested and working)

VSTS task:

task: AzureResourceGroupDeployment@2

VSTS task template:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appinsights-name": {
      "type": "string"
    },
    "instrumentation": {
      "type": "string"
    },
    "apim-name": {
      "type": "string"
    },
    "api-name": {
      "type": "string"
    }
  },
  "resources": [
    {
      "type": "Microsoft.ApiManagement/service/loggers",
      "name": "[concat(parameters('apim-name'), '/', parameters('appinsights-name'))]",
      "apiVersion": "2018-01-01",
      "scale": null,
      "properties": {
        "loggerType": "applicationInsights",
        "description": null,
        "credentials": {
          "instrumentationKey": "[parameters('instrumentation')]"
        },
        "isBuffered": true
      }
    },
    {
      "type": "Microsoft.ApiManagement/service/apis/diagnostics",
      "name": "[concat(parameters('apim-name'), '/', parameters('api-name'), '/', 'applicationinsights')]",
      "apiVersion": "2018-01-01",
      "scale": null,
      "properties": {
        "enabled": true
      }
    },
    {
      "type": "Microsoft.ApiManagement/service/apis/diagnostics/loggers",
      "name": "[concat(parameters('apim-name'), '/', parameters('api-name'), '/', 'applicationinsights', '/',parameters('appinsights-name'))]",
      "apiVersion": "2018-01-01",
      "scale": null,
      "properties": {
        "loggerType": "applicationInsights",
        "description": null,
        "credentials": {
          "instrumentationKey": "[parameters('instrumentation')]"
        },
        "isBuffered": true,
        "resourceId": "[parameters('appinsights-name')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.ApiManagement/service/apis/diagnostics', parameters('apim-name'), parameters('api-name'), 'applicationinsights')]"
      ]
    }
  ]
}

Method 2 (not tested)

PUT https://management.usgovcloudapi.net/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{apimServiceName}/loggers/applicationinsights?api-version=2018-01-01 HTTP/1.1
Authorization: Bearer
Content-Type: application/json
{
    "properties": {
        "loggerType": "applicationinsights",
        "description": null,
        "isBuffered": true,
        "resourceId": null,
        "credentials":{
            "instrumentationKey":"<ApplicationInsights-InstrumentationKey>"
        }
    }
}


PUT https://management.usgovcloudapi.net/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{apimServiceName}/diagnostics/applicationinsights?api-version=2018-01-01 HTTP/1.1
Authorization: Bearer
Content-Type: application/json

{
    "properties": {
        "enabled": true
    }
}