Skip to content

Commit

Permalink
fix(azure): set diagnostic setting to allow query perf insights (#1422)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

We need to enable diagnostic setting in order to enable query
performance insight. Added manually in portal, but finally found out how
to do it in Bicep:):)

## 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)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced monitoring for PostgreSQL resources through integration with
Application Insights.
- Added diagnostic settings for performance insights, including
configurable log categories and metrics.
  
- **Updates**
- Connection strings for PostgreSQL and Redis are now securely stored as
references in Key Vault.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
arealmaas authored Nov 8, 2024
1 parent d68cc65 commit 5919258
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 5919258

Please sign in to comment.