Skip to content

Commit

Permalink
fix(azure): set diagnostic setting to allow query perf insights
Browse files Browse the repository at this point in the history
  • Loading branch information
arealmaas committed Nov 8, 2024
1 parent bb832d8 commit 3685b37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ module postgresql '../modules/postgreSql/create.bicep' = {
? srcKeyVaultResource.getSecret('dialogportenPgAdminPassword${environment}')
: secrets.dialogportenPgAdminPassword
sku: postgresConfiguration.sku
appInsightWorkspaceName: appInsights.outputs.appInsightsWorkspaceName
enableQueryPerformanceInsight: postgresConfiguration.enableQueryPerformanceInsight
subnetId: vnet.outputs.postgresqlSubnetId
vnetId: vnet.outputs.virtualNetworkId
Expand Down
43 changes: 43 additions & 0 deletions .azure/modules/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ param sku Sku
@description('Enable query performance insight')
param enableQueryPerformanceInsight bool

@description('The name of the Application Insights workspace')
param appInsightWorkspaceName string

@description('The Key Vault to store the PostgreSQL administrator login password')
@secure()
param srcKeyVault object
Expand Down Expand Up @@ -136,6 +139,46 @@ resource pgms_wait_sampling_query_capture_mode 'Microsoft.DBforPostgreSQL/flexib
}
}

resource appInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
name: appInsightWorkspaceName
}

// todo: setting as 0 for now. Will use the log analytics workspace policy instead. Consider setting explicitly in the future.
var diagnosticSettingRetentionPolicy = {
days: 0
enabled: false
}

var diagnosticLogCategories = [
'PostgreSQLLogs'
'PostgreSQLFlexSessions'
'PostgreSQLFlexQueryStoreRuntime'
'PostgreSQLFlexQueryStoreWaitStats'
'PostgreSQLFlexTableStats'
'PostgreSQLFlexDatabaseXacts'
]

resource diagnosticSetting 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if (enableQueryPerformanceInsight) {
name: 'PostgreSQLDiagnosticSetting'
scope: postgres
properties: {
workspaceId: appInsightsWorkspace.id
logs: [for category in diagnosticLogCategories: {
category: category
enabled: true
retentionPolicy: diagnosticSettingRetentionPolicy
}]
metrics: [
{
timeGrain: null
enabled: true
retentionPolicy: diagnosticSettingRetentionPolicy
category: 'AllMetrics'
}
]
}
}

module adoConnectionString '../keyvault/upsertSecret.bicep' = {
name: 'adoConnectionString'
params: {
Expand Down

0 comments on commit 3685b37

Please sign in to comment.