sergevm
sergevm

Reputation: 353

ARM template - configure diagnostics logs

I'm trying to configure some diagnostics logs on an app service using ARM templates. While some configuration is correctly applied with the template, some of the configuration properties such as the retentionInDays and the sasUrl (for blob storage) are not applied.

I'm basically using this format:

          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Information"
              },
              "azureTableStorage": {
                "level": "Off",
                "sasUrl": null
              },
              "azureBlobStorage": {
                "level": "Verbose",
                "sasUrl": "[variables('mySasUrl')]",
                "retentionInDays": 1,
                "enabled": true
              }
            },
            "httpLogs": {
              "fileSystem": {
                "retentionInMb": 50,
                "retentionInDays": 1,
                "enabled": true
              },
              "azureBlobStorage": {
                "sasUrl": null,
                "retentionInDays": 1,
                "enabled": false
              }
            },
            "failedRequestsTracing": {
              "enabled": true
            },
            "detailedErrorMessages": {
              "enabled": true
            }

which largely follows this sample, but extends it with the blob storage settings. The azureBlobStorage settings are partially picked up (the level is correctly applied), but as I said, the sasUrl and the retentionInDays is not applied. Anyone got this working?

Upvotes: 1

Views: 1718

Answers (3)

David Chelliah
David Chelliah

Reputation: 1349

The app server logs ARM properties format that you've shown in your post is correct.

The symptom that you've referred in OP (some configuration is correctly applied with the template, some of the configuration properties such as the retentionInDays and the sasUrl (for blob storage) are not applied) can happen when you've both appSettings and logs configured through your ARM template.

When you apply sasUrl through the Azure Resource Manager and it creates following appsettings keys in your configuration

  • DIAGNOSTICS_AZUREBLOBCONTAINERSASURL
  • DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS

Then latter while ARM applies you appSettings, it resets everything Off (removing above required configs) and resets the appSettings with the values mentioned in you ARM template - appSettings section. It results in the inconsistent behaviour that you notice.

Add a dependency to logs resource, so that it will execute after appSettings by introducing a dependency through dependsOn "[resourceId('Microsoft.Web/sites/config', variables('webAppName'), 'appsettings')]"

I have written a detailed post on Configure app and web server logs to a storage account in ARM template

Upvotes: 1

Quinn Vissak
Quinn Vissak

Reputation: 151

I think your issue lies in the generation of your SAS URI. Here's the link to the documentation: https://learn.microsoft.com/en-us/azure/storage/common/storage-dotnet-shared-access-signature-part-1#examples-of-sas-uris

It was difficult to find exactly how to generate the signature for your URL, but using the Azure PowerShell CLI tool made it simple:

  1. Get your storage account resource: $storage = Get-AzureRmStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>";
  2. If you don't already have a container, create one: New-AzureStorageContainer -Name "<your-blob-storage-container-name>" -Context $storage.Context -Permission Off;
  3. Generate your SAS URI: Write-Host (New-AzureStorageContainerSASToken -Name "<your-blob-storage-container-name>" -Permission rw -Context $storage.Context -StartTime (Get-Date) -ExpiryTime (Get-Date).AddYears(100) -FullUri);

Note that for each container, you need to generate a URI.

Upvotes: 0

Brando Zhang
Brando Zhang

Reputation: 28267

According to your description and provided link, I have created a test demo on my side.It works well.

I guess you may set the wrong blob SAS url. I suggest you could generate a container level SAS url and try again.

The SAS format like below:

https://{yourstorageaccount}.blob.core.windows.net/mycontainer?sv=2015-04-05&sr=c&sig={sig}&st=2017-10-30T02:09:57Z&se=2217-10-30T02:09:57Z&sp=rwdl

More details about mt test template, you could refer to below codes:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "brandosptestName": {
      "type": "string",
      "minLength": 1
    },
    "brandosptestSkuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    }
  },
  "variables": {
    "bandotestName": "[concat('bandotest', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "name": "[parameters('brandosptestName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "sku": {
        "name": "[parameters('brandosptestSkuName')]"
      },
      "dependsOn": [ ],
      "tags": {
        "displayName": "brandosptest"
      },
      "properties": {
        "name": "[parameters('brandosptestName')]",
        "numberOfWorkers": 1
      }
    },
    {
      "name": "[variables('bandotestName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "resources": [
        {
          "name": "logs",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites',variables('bandotestName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },
              "azureTableStorage": {
                "level": "Off",
                "sasUrl": null
              },
              "azureBlobStorage": {
                "level": "Verbose",
                "sasUrl": "url",
                "retentionInDays": 7
              },
              "httpLogs": {
                "fileSystem": {
                  "retentionInMb": 35,
                  "retentionInDays": 7,
                  "enabled": false
                },
                "azureBlobStorage": {
                  "sasUrl": "url",
                  "retentionInDays": 7,
                  "enabled": true
                }
              },
              "failedRequestsTracing": {
                "enabled": false
              },
              "detailedErrorMessages": {
                "enabled": false
              }
            }
          }
        }
      ],

      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('brandosptestName'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', parameters('brandosptestName')))]": "Resource",
        "displayName": "bandotest"
      },
      "properties": {
        "name": "[variables('bandotestName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('brandosptestName'))]"
      }
    }
  ],
  "outputs": {
  }
}

Result:

enter image description here

Upvotes: 1

Related Questions