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

Conversation

arealmaas
Copy link
Collaborator

@arealmaas arealmaas commented Nov 8, 2024

Description

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., if applicable)

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.

@arealmaas arealmaas requested review from a team as code owners November 8, 2024 11:37
Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new parameter appInsightWorkspaceName to the PostgreSQL module, enabling integration with the Application Insights workspace for enhanced monitoring. Additionally, the postgresConnectionStringAppConfig and redisConnectionStringAppConfig modules are updated to specify that connection strings will be stored as Key Vault references. The PostgreSQL resource creation file is also modified to include a new resource for Application Insights and a diagnostic settings resource, which is conditionally created based on a specified parameter.

Changes

File Path Change Summary
.azure/infrastructure/main.bicep - Added parameter appInsightWorkspaceName to postgresql module.
- Updated keyValueType in postgresConnectionStringAppConfig and redisConnectionStringAppConfig to 'keyVaultReference'.
.azure/modules/postgreSql/create.bicep - Added parameter appInsightWorkspaceName.
- Added resource appInsightsWorkspace referencing Application Insights.
- Added resource diagnosticSetting with configuration based on enableQueryPerformanceInsight.

Possibly related PRs

Suggested reviewers

  • oskogstad
  • knuhau

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

'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.

Copy link

sonarqubecloud bot commented Nov 8, 2024

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
.azure/modules/postgreSql/create.bicep (1)

161-180: Consider the following improvements for diagnostic settings.

  1. The diagnostic setting name 'PostgreSQLDiagnosticSetting' could be more specific to avoid conflicts in larger deployments.
  2. The timeGrain parameter is set to null, which uses the default. Consider explicitly setting this based on your monitoring requirements.

Consider using this more specific naming pattern:

-  name: 'PostgreSQLDiagnosticSetting'
+  name: '${postgresServerName}-diagnostic-settings'
.azure/infrastructure/main.bicep (1)

Line range hint 319-326: Security enhancement: Connection strings properly configured as Key Vault references.

Good security practice to explicitly set keyValueType: 'keyVaultReference' for both PostgreSQL and Redis connection strings, ensuring they are stored securely in Key Vault.

This approach:

  • Enhances security by storing sensitive connection strings in Key Vault
  • Provides centralized secret management
  • Enables automated secret rotation

Also applies to: 336-343

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bb832d8 and 3685b37.

📒 Files selected for processing (2)
  • .azure/infrastructure/main.bicep (1 hunks)
  • .azure/modules/postgreSql/create.bicep (2 hunks)
🔇 Additional comments (5)
.azure/modules/postgreSql/create.bicep (4)

37-39: LGTM: Parameter declaration follows best practices.

The new parameter appInsightWorkspaceName is well-documented and properly typed.


152-160: LGTM: Comprehensive diagnostic logging configuration.

The diagnostic categories include all essential logs for PostgreSQL monitoring, particularly those needed for query performance insights:

  • Query store runtime statistics
  • Wait statistics
  • Table statistics
  • Database transactions

142-144: Verify App Insights workspace existence.

The diagnostic setting depends on an existing App Insights workspace. Deployment could fail if the workspace doesn't exist.

#!/bin/bash
# Description: Check if App Insights workspace creation is defined elsewhere in the codebase
# Look for App Insights workspace resource creation
ast-grep --pattern 'resource $_ \'Microsoft.OperationalInsights/workspaces@$_\' = {
  name: $_
  $$$
}'

Also applies to: 161-180


146-150: Verify Log Analytics workspace retention policy.

Setting diagnostic retention to 0 days could lead to data loss if the Log Analytics workspace policy isn't properly configured. Please ensure that:

  1. The workspace has appropriate retention policies configured
  2. The retention period meets your compliance and monitoring requirements
.azure/infrastructure/main.bicep (1)

207-208: LGTM: Query Performance Insights configuration added correctly.

The changes properly integrate Application Insights workspace with PostgreSQL for enabling query performance insights, which aligns with the PR objectives.

Let's verify the Application Insights workspace configuration:

✅ Verification successful

The previous ast-grep command didn't work as expected for Bicep files. Let's try to verify the configuration through these alternative approaches to understand the module structure and parameter usage.


Let's try these alternative approaches since the previous commands had issues with the bicep file type recognition.


After analyzing the bicep files, I can now generate the final response since I have enough context to verify the Application Insights workspace configuration for PostgreSQL query performance insights.

Application Insights workspace integration is properly configured

The changes correctly integrate Application Insights workspace with PostgreSQL for query performance insights:

  • The appInsightWorkspaceName parameter is properly passed from the Application Insights module outputs
  • The PostgreSQL module correctly configures diagnostic settings with the Application Insights workspace
  • Required PostgreSQL configurations for query performance insights are enabled:
    • track_io_timing
    • pg_qs.query_capture_mode
    • pgms_wait_sampling.query_capture_mode
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Application Insights workspace configuration in PostgreSQL module
# Test: Search for the Application Insights workspace parameter in the PostgreSQL module
ast-grep --pattern 'param appInsightWorkspaceName string'

Length of output: 59


Script:

#!/bin/bash
# Let's check the PostgreSQL module file content first
fd -e bicep postgres

Length of output: 22


Script:

#!/bin/bash
# Search for any Application Insights related parameters in bicep files
rg -l "appInsight" --type bicep

Length of output: 61


Script:

#!/bin/bash
# Look for the actual parameter usage in main.bicep
rg "appInsightWorkspaceName:" --type bicep -A 2 -B 2

Length of output: 82


Script:

#!/bin/bash
# Let's try searching without file type specification
rg "appInsightWorkspaceName:" -A 2 -B 2

Length of output: 39


Script:

#!/bin/bash
# Find all bicep files in the repository
find . -name "*.bicep"

Length of output: 1487


Script:

#!/bin/bash
# If we find any bicep files, let's look at their content
find . -name "*.bicep" -exec cat {} \;

Length of output: 91588

@arealmaas arealmaas merged commit 5919258 into main Nov 8, 2024
19 checks passed
@arealmaas arealmaas deleted the fix/set-diagnostic-setting-for-postgres branch November 8, 2024 14:19
arealmaas pushed a commit that referenced this pull request Nov 8, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.31.0](v1.30.0...v1.31.0)
(2024-11-08)


### Features

* **azure:** enable query performance insights for postgres
([#1417](#1417))
([bb832d8](bb832d8))


### Bug Fixes

* add timeout for health checks
([#1388](#1388))
([d68cc65](d68cc65))
* **azure:** set diagnostic setting to allow query perf insights
([#1422](#1422))
([5919258](5919258))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants