Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(azure): set diagnostic setting to allow query perf insights #1422

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI:

Diagnostic Log Categories for Azure PostgreSQL Flexible Server

PostgreSQLLogs

  • Contains general PostgreSQL server logs.
  • Includes error messages, authentication attempts, and general server events.
  • Essential for troubleshooting server-level issues and security monitoring.

PostgreSQLFlexSessions

  • Tracks active database sessions and connections.
  • Helps monitor concurrent users and connection patterns.
  • Useful for identifying connection leaks or excessive concurrent connections.

PostgreSQLFlexQueryStoreRuntime

  • Captures query execution statistics and runtime metrics.
  • Shows query execution times, CPU usage, and I/O statistics.
  • Critical for performance tuning and identifying slow queries.

PostgreSQLFlexQueryStoreWaitStats

  • Records what queries are waiting for and why.
  • Helps identify bottlenecks like I/O, locks, or resource contention.
  • Essential for diagnosing performance issues and resource conflicts.

PostgreSQLFlexTableStats

  • Provides statistics about table usage and operations.
  • Includes information about table scans, row counts, and index usage.
  • Useful for capacity planning and database optimization.

PostgreSQLFlexDatabaseXacts

  • Monitors database transactions.
  • Tracks transaction rates, durations, and commit/rollback patterns.
  • Important for understanding database workload and transaction health.

]

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
Loading