From d2ccb87487e9c2a2e6324244decd0fdded0e1505 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 1 Feb 2024 00:02:58 -0800 Subject: [PATCH] Improved logging, minor tweaks to deployment script and documentation --- deploy/deploy.ps1 | 3 +++ deploy/functionApp.bicep | 12 ++++++------ deploy/main.bicep | 5 +++-- docs/contributing/README.md | 2 +- docs/deployment/README.md | 2 +- engine/app/logs/config.json | 2 +- engine/app/logs/logs.py | 4 ++-- engine/app/main.py | 3 +++ 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/deploy/deploy.ps1 b/deploy/deploy.ps1 index e274332..a0f7262 100644 --- a/deploy/deploy.ps1 +++ b/deploy/deploy.ps1 @@ -193,6 +193,7 @@ DynamicParam { $validators = @{ functionName = '^(?=^.{2,59}$)([^-][\w-]*[^-])$' appServiceName = '^(?=^.{2,59}$)([^-][\w-]*[^-])$' + functionPlanName = '^(?=^.{1,40}$)([\w-]*)$' appServicePlanName = '^(?=^.{1,40}$)([\w-]*)$' cosmosAccountName = '^(?=^.{3,44}$)([^-][a-z0-9-]*[^-])$' cosmosContainerName = '^(?=^.{1,255}$)([^/\\#?]*)$' @@ -211,11 +212,13 @@ DynamicParam { if(-not $Function) { $validators.Remove('functionName') + $validators.Remove('functionPlanName') $validators.Remove('storageAccountName') } if($Function) { $validators.Remove('appServiceName') + $validators.Remove('appServicePlanName') } $attrApp = [System.Management.Automation.ParameterAttribute]::new() diff --git a/deploy/functionApp.bicep b/deploy/functionApp.bicep index cda8ab7..4d08e58 100644 --- a/deploy/functionApp.bicep +++ b/deploy/functionApp.bicep @@ -1,8 +1,8 @@ @description('Function App Name') param functionAppName string -@description('Function App Plan Name') -param functionAppPlanName string +@description('Function Plan Name') +param functionPlanName string @description('CosmosDB URI') param cosmosDbUri string @@ -50,8 +50,8 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' existing name: storageAccountName } -resource functionAppPlan 'Microsoft.Web/serverfarms@2021-02-01' = { - name: functionAppPlanName +resource functionPlan 'Microsoft.Web/serverfarms@2021-02-01' = { + name: functionPlanName location: location sku: { name: 'EP1' @@ -75,7 +75,7 @@ resource functionApp 'Microsoft.Web/sites@2021-03-01' = { } properties: { httpsOnly: true - serverFarmId: functionAppPlan.id + serverFarmId: functionPlan.id keyVaultReferenceIdentity: managedIdentityId siteConfig: { acrUseManagedIdentityCreds: privateAcr ? true : false @@ -210,7 +210,7 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = { resource diagnosticSettingsPlan 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = { name: 'diagSettings' - scope: functionAppPlan + scope: functionPlan properties: { metrics: [ { diff --git a/deploy/main.bicep b/deploy/main.bicep index cd3fdaa..3e80369 100644 --- a/deploy/main.bicep +++ b/deploy/main.bicep @@ -40,6 +40,7 @@ param tags object = {} param resourceNames object = { functionName: '${namePrefix}-${uniqueString(guid)}' appServiceName: '${namePrefix}-${uniqueString(guid)}' + functionPlanName: '${namePrefix}-asp-${uniqueString(guid)}' appServicePlanName: '${namePrefix}-asp-${uniqueString(guid)}' cosmosAccountName: '${namePrefix}-dbacct-${uniqueString(guid)}' cosmosContainerName: '${namePrefix}-ctr' @@ -143,8 +144,8 @@ module appService 'appService.bicep' = if (!deployAsFunc) { params: { location: location azureCloud: azureCloud - appServicePlanName: resourceNames.appServicePlanName appServiceName: resourceNames.appServiceName + appServicePlanName: resourceNames.appServicePlanName keyVaultUri: keyVault.outputs.keyVaultUri cosmosDbUri: cosmos.outputs.cosmosDocumentEndpoint databaseName: resourceNames.cosmosDatabaseName @@ -165,8 +166,8 @@ module functionApp 'functionApp.bicep' = if (deployAsFunc) { params: { location: location azureCloud: azureCloud - functionAppPlanName: resourceNames.appServicePlanName functionAppName: resourceNames.functionName + functionPlanName: resourceNames.appServicePlanName keyVaultUri: keyVault.outputs.keyVaultUri cosmosDbUri: cosmos.outputs.cosmosDocumentEndpoint databaseName: resourceNames.cosmosDatabaseName diff --git a/docs/contributing/README.md b/docs/contributing/README.md index 0649a34..f5af5e7 100644 --- a/docs/contributing/README.md +++ b/docs/contributing/README.md @@ -63,7 +63,7 @@ Next, use the following commands to update the Azure IPAM containers within your az acr build -r -t ipam:latest -f ./Dockerfile . # Function Container -az acr build -r -t ipamfunc:latest -f .Dockerfile.func . +az acr build -r -t ipamfunc:latest -f ./Dockerfile.func . ``` If you're using the legacy Azure IPAM multi-container deployment (prior to v3.0.0), please use the following commands to update your containers instead diff --git a/docs/deployment/README.md b/docs/deployment/README.md index 475f2e1..db93a1c 100644 --- a/docs/deployment/README.md +++ b/docs/deployment/README.md @@ -234,7 +234,7 @@ $ResourceNames = @{ ```powershell $ResourceNames = @{ functionName = 'myfunction01' - appServicePlanName = 'myappserviceplan01' + functionPlanName = 'myfunctionplan01' cosmosAccountName = 'mycosmosaccount01' cosmosContainerName = 'mycontainer01' cosmosDatabaseName = 'mydatabase01' diff --git a/engine/app/logs/config.json b/engine/app/logs/config.json index e066486..e806fee 100644 --- a/engine/app/logs/config.json +++ b/engine/app/logs/config.json @@ -1,7 +1,7 @@ { "logger": { "path": "./logs", - "filename": "access.log", + "filename": "ipam.log", "level": "info", "rotation": "30 days", "retention": "12 months", diff --git a/engine/app/logs/logs.py b/engine/app/logs/logs.py index 87f815a..5ec8c80 100644 --- a/engine/app/logs/logs.py +++ b/engine/app/logs/logs.py @@ -47,7 +47,7 @@ class IPAMLogger: logging_config = config.get('logger') logger = cls.customize_logging( - os.path.join(tempfile.gettempdir(), "logs", "access.log") if os.environ.get('FUNCTIONS_WORKER_RUNTIME') else logging_config.get('path'), + os.environ.get('IPAM_LOGFILE_LOCATION', os.path.join(tempfile.gettempdir(), "logs", "ipam.log")), level=logging_config.get('level'), retention=logging_config.get('retention'), rotation=logging_config.get('rotation'), @@ -79,7 +79,7 @@ class IPAMLogger: retention=retention, enqueue=True, backtrace=True, - level=level.upper(), + level='DEBUG', format=format ) diff --git a/engine/app/main.py b/engine/app/main.py index 3fb2931..6a28da7 100644 --- a/engine/app/main.py +++ b/engine/app/main.py @@ -32,6 +32,7 @@ import copy import json import shutil import tempfile +import traceback from pathlib import Path from urllib.parse import urlparse @@ -478,6 +479,8 @@ async def find_reservations() -> None: await azure.match_resv_to_vnets() except Exception as e: logger.error('Error running network check loop!') + tb = traceback.format_exc() + logger.debug(tb); raise e @app.exception_handler(StarletteHTTPException)