From bb832d8d923114e204b448d3fbb6a23c249aad3a Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 8 Nov 2024 12:01:38 +0100 Subject: [PATCH] feat(azure): enable query performance insights for postgres (#1417) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - Sets the necessary server properties to enable Query Performance Insights - Enabled on Test, Staging and YT01 - Minor refactor to make things a tad cleaner ## Related Issue(s) - #{issue number} ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) ## Summary by CodeRabbit - **New Features** - Introduced a new configuration structure for PostgreSQL with enhanced settings, including the ability to enable query performance insights. - Added parameters to manage PostgreSQL SKU details more effectively. - **Bug Fixes** - Resolved inconsistencies in PostgreSQL parameter definitions across multiple configuration files. - **Documentation** - Updated documentation to reflect changes in PostgreSQL configuration management. --------- Co-authored-by: Ole Jørgen Skogstad --- .azure/infrastructure/main.bicep | 9 +++++-- .azure/infrastructure/prod.bicepparam | 9 ++++--- .azure/infrastructure/staging.bicepparam | 9 ++++--- .azure/infrastructure/test.bicepparam | 9 ++++--- .azure/infrastructure/yt01.bicepparam | 9 ++++--- .azure/modules/postgreSql/create.bicep | 30 ++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 14 deletions(-) diff --git a/.azure/infrastructure/main.bicep b/.azure/infrastructure/main.bicep index 576a1861b..a3f6ec9fd 100644 --- a/.azure/infrastructure/main.bicep +++ b/.azure/infrastructure/main.bicep @@ -55,7 +55,11 @@ import { Sku as SlackNotifierSku } from '../modules/functionApp/slackNotifier.bi param slackNotifierSku SlackNotifierSku import { Sku as PostgresSku } from '../modules/postgreSql/create.bicep' -param postgresSku PostgresSku + +param postgresConfiguration { + sku: PostgresSku + enableQueryPerformanceInsight: bool +} import { Sku as ServiceBusSku } from '../modules/serviceBus/main.bicep' param serviceBusSku ServiceBusSku @@ -199,7 +203,8 @@ module postgresql '../modules/postgreSql/create.bicep' = { administratorLoginPassword: contains(keyVaultSourceKeys, 'dialogportenPgAdminPassword${environment}') ? srcKeyVaultResource.getSecret('dialogportenPgAdminPassword${environment}') : secrets.dialogportenPgAdminPassword - sku: postgresSku + sku: postgresConfiguration.sku + enableQueryPerformanceInsight: postgresConfiguration.enableQueryPerformanceInsight subnetId: vnet.outputs.postgresqlSubnetId vnetId: vnet.outputs.virtualNetworkId tags: tags diff --git a/.azure/infrastructure/prod.bicepparam b/.azure/infrastructure/prod.bicepparam index 2eb2d4c17..2d1284449 100644 --- a/.azure/infrastructure/prod.bicepparam +++ b/.azure/infrastructure/prod.bicepparam @@ -29,9 +29,12 @@ param slackNotifierSku = { applicationServicePlanName: 'Y1' applicationServicePlanTier: 'Dynamic' } -param postgresSku = { - name: 'Standard_B1ms' - tier: 'Burstable' +param postgresConfiguration = { + sku: { + name: 'Standard_B1ms' + tier: 'Burstable' + } + enableQueryPerformanceInsight: false } param redisSku = { diff --git a/.azure/infrastructure/staging.bicepparam b/.azure/infrastructure/staging.bicepparam index 40ebabf97..2aef7d15e 100644 --- a/.azure/infrastructure/staging.bicepparam +++ b/.azure/infrastructure/staging.bicepparam @@ -29,9 +29,12 @@ param slackNotifierSku = { applicationServicePlanName: 'Y1' applicationServicePlanTier: 'Dynamic' } -param postgresSku = { - name: 'Standard_B1ms' - tier: 'Burstable' +param postgresConfiguration = { + sku: { + name: 'Standard_B1ms' + tier: 'Burstable' + } + enableQueryPerformanceInsight: true } param redisSku = { diff --git a/.azure/infrastructure/test.bicepparam b/.azure/infrastructure/test.bicepparam index ce73b3286..80e51c54f 100644 --- a/.azure/infrastructure/test.bicepparam +++ b/.azure/infrastructure/test.bicepparam @@ -29,9 +29,12 @@ param slackNotifierSku = { applicationServicePlanName: 'Y1' applicationServicePlanTier: 'Dynamic' } -param postgresSku = { - name: 'Standard_B2s' - tier: 'Burstable' +param postgresConfiguration = { + sku: { + name: 'Standard_B2s' + tier: 'Burstable' + } + enableQueryPerformanceInsight: true } param redisSku = { diff --git a/.azure/infrastructure/yt01.bicepparam b/.azure/infrastructure/yt01.bicepparam index 0e40d97a0..c471b737d 100644 --- a/.azure/infrastructure/yt01.bicepparam +++ b/.azure/infrastructure/yt01.bicepparam @@ -29,9 +29,12 @@ param slackNotifierSku = { applicationServicePlanName: 'Y1' applicationServicePlanTier: 'Dynamic' } -param postgresSku = { - name: 'Standard_B1ms' - tier: 'Burstable' +param postgresConfiguration = { + sku: { + name: 'Standard_B1ms' + tier: 'Burstable' + } + enableQueryPerformanceInsight: true } param redisSku = { diff --git a/.azure/modules/postgreSql/create.bicep b/.azure/modules/postgreSql/create.bicep index e209cd610..b0c992b1d 100644 --- a/.azure/modules/postgreSql/create.bicep +++ b/.azure/modules/postgreSql/create.bicep @@ -31,6 +31,9 @@ type Sku = { @description('The SKU of the PostgreSQL server') param sku Sku +@description('Enable query performance insight') +param enableQueryPerformanceInsight bool + @description('The Key Vault to store the PostgreSQL administrator login password') @secure() param srcKeyVault object @@ -106,6 +109,33 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2024-08-01' = { tags: tags } +resource track_io_timing 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2023-12-01-preview' = if (enableQueryPerformanceInsight) { + parent: postgres + name: 'track_io_timing' + properties: { + value: 'on' + source: 'user-override' + } +} + +resource pg_qs_query_capture_mode 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2023-12-01-preview' = if (enableQueryPerformanceInsight) { + parent: postgres + name: 'pg_qs.query_capture_mode' + properties: { + value: 'all' + source: 'user-override' + } +} + +resource pgms_wait_sampling_query_capture_mode 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2023-12-01-preview' = if (enableQueryPerformanceInsight) { + parent: postgres + name: 'pgms_wait_sampling.query_capture_mode' + properties: { + value: 'all' + source: 'user-override' + } +} + module adoConnectionString '../keyvault/upsertSecret.bicep' = { name: 'adoConnectionString' params: {