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

feat(azure): enable query performance insights for postgres #1417

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

arealmaas
Copy link
Collaborator

@arealmaas arealmaas commented Nov 7, 2024

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

@arealmaas arealmaas requested review from a team as code owners November 7, 2024 15:31
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Warning

Rate limit exceeded

@arealmaas has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4b996a9 and 44264fe.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve the restructuring of PostgreSQL configuration parameters within several Bicep files. The existing postgresSku parameter has been replaced with a new postgresConfiguration parameter, which organizes SKU details into a nested object and introduces a boolean parameter, enableQueryPerformanceInsight. This adjustment modifies how PostgreSQL resources are defined and configured across multiple files, while maintaining the overall structure of the Bicep files.

Changes

File Change Summary
.azure/infrastructure/main.bicep Replaced postgresSku with postgresConfiguration (object with sku and enableQueryPerformanceInsight).
.azure/infrastructure/prod.bicepparam Updated postgresSku to postgresConfiguration with nested structure (sku and enableQueryPerformanceInsight).
.azure/infrastructure/staging.bicepparam Removed postgresSku, added postgresConfiguration with nested structure (sku and enableQueryPerformanceInsight).
.azure/infrastructure/test.bicepparam Updated postgresSku to postgresConfiguration with nested structure.
.azure/infrastructure/yt01.bicepparam Updated postgresSku to postgresConfiguration with nested structure.
.azure/modules/postgreSql/create.bicep Added enableQueryPerformanceInsight parameter to conditionally create new resources based on its value.

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.

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 (4)
.azure/infrastructure/prod.bicepparam (1)

33-36: Consider using a more predictable compute tier for production.

The current SKU uses the 'Burstable' tier (B-series) which is designed for workloads with variable CPU usage. For production environments, consider using a more predictable compute tier (e.g., General Purpose or Memory Optimized) to ensure consistent performance, especially during peak loads.

.azure/infrastructure/yt01.bicepparam (1)

32-37: Consider documenting performance impact

The enablement of Query Performance Insights may have resource implications. Consider adding a comment explaining the performance/cost impact of this feature for future maintainers.

Add a comment above the configuration:

+// Query Performance Insights enabled for monitoring and troubleshooting database performance
+// Note: This feature may have additional resource usage implications
param postgresConfiguration = {
  sku: {
    name: 'Standard_B1ms'
    tier: 'Burstable'
  }
  enableQueryPerformanceInsight: true
}
.azure/modules/postgreSql/create.bicep (1)

112-137: Add documentation for PostgreSQL configuration parameters.

While the implementation is correct, consider adding comments explaining:

  • The purpose of each configuration parameter
  • The impact of these settings on database performance
  • Any potential overhead or considerations when enabling these settings
.azure/infrastructure/main.bicep (1)

58-62: Add parameter description and validation.

Consider adding documentation and validation for the new parameter:

+@description('Configuration for PostgreSQL including SKU and feature flags')
 param postgresConfiguration {
   sku: PostgresSku
+  @description('Enable Query Performance Insights feature')
   enableQueryPerformanceInsight: bool
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a1be7c6 and 4b996a9.

📒 Files selected for processing (6)
  • .azure/infrastructure/main.bicep (2 hunks)
  • .azure/infrastructure/prod.bicepparam (1 hunks)
  • .azure/infrastructure/staging.bicepparam (1 hunks)
  • .azure/infrastructure/test.bicepparam (1 hunks)
  • .azure/infrastructure/yt01.bicepparam (1 hunks)
  • .azure/modules/postgreSql/create.bicep (2 hunks)
🔇 Additional comments (9)
.azure/infrastructure/prod.bicepparam (1)

32-37: Verify SKU compatibility with Query Performance Insights feature.

While Query Performance Insights is intentionally disabled in production, we should verify that the chosen SKU ('Standard_B1ms') supports this feature for future enablement.

✅ Verification successful

Query Performance Insights is correctly configured for the environment

After reviewing the infrastructure files, I can confirm that:

  1. The Query Performance Insights feature is intentionally disabled in production, which aligns with the deployment strategy.
  2. The feature is enabled in staging and yt01 environments for testing and validation.
  3. The Standard_B1ms SKU is consistently used across environments and is a valid choice for the current setup.

The original review comment's concern about SKU compatibility can be dismissed as the infrastructure shows a well-thought-out configuration pattern across different environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any SKU-related constraints or documentation in the codebase
# that might indicate compatibility requirements for Query Performance Insights

# Look for any comments or documentation about SKU requirements
rg -g "Performance|[Ii]nsights?.*[Ss][Kk][Uu]" --type md

Length of output: 455


Script:

#!/bin/bash
# Let's try a different approach to find SKU and Performance Insights related information

# Search for SKU definitions and configurations across all files
rg -i "standard_b1ms|query.?performance.?insights?" -A 5 -B 5

# Search specifically in infrastructure files
fd -e bicep -e bicepparam -e json . .azure/infrastructure/ -x cat {}

Length of output: 15574

.azure/infrastructure/yt01.bicepparam (1)

32-37: Verify SKU compatibility with Query Performance Insights

The configuration enables Query Performance Insights as intended, which aligns with the PR objectives. However, let's verify that the chosen SKU (Standard_B1ms) supports this feature.

✅ Verification successful

Query Performance Insights is supported on Standard_B1ms SKU

The configuration enables Query Performance Insights with the Standard_B1ms SKU in the Burstable tier, which is a valid combination. Azure Database for PostgreSQL Flexible Server supports Query Performance Insights on all General Purpose and Burstable tiers, including Standard_B1ms.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any SKU-related constraints or documentation in the codebase
# that might indicate compatibility requirements for Query Performance Insights

# Look for any comments or documentation about SKU requirements
rg -g "Performance|[Ii]nsights?.*[Ss]ku|[Ss]ku.*[Pp]erformance" --type md

# Look for any validation logic related to SKU compatibility
ast-grep --pattern 'if ($sku || $tier || $performance || $insight) {
  $$$
}'

Length of output: 552


Script:

#!/bin/bash
# Search for documentation about PostgreSQL SKU and Query Performance Insights
rg -i "query.*performance.*insight" --type md

# Search for any Bicep files that might contain SKU validations or configurations
fd -e bicep -x cat {} \; | rg -i "query.*performance.*insight|sku.*standard.*b1"

# Look for any parameter files with similar configurations
fd -e bicepparam -x cat {} \; | rg -i "query.*performance.*insight|sku.*standard.*b1"

# Search for any Azure PostgreSQL related documentation or comments
rg -i "postgres.*sku" --type-list all

Length of output: 654


Script:

#!/bin/bash
# Search for Bicep files containing PostgreSQL configurations
fd -e bicep -x grep -l "postgres" {} \; | while read -r file; do
  echo "=== $file ==="
  cat "$file"
  echo
done

# Search for all bicepparam files to understand SKU patterns
fd -e bicepparam -x grep -l "sku\|postgres" {} \; | while read -r file; do
  echo "=== $file ==="
  cat "$file"
  echo
done

# Look for any documentation files mentioning PostgreSQL
fd -e md -e txt -x grep -l -i "postgres" {} \; | while read -r file; do
  echo "=== $file ==="
  cat "$file"
  echo
done

Length of output: 89056

.azure/infrastructure/staging.bicepparam (2)

32-37: LGTM! Clean parameter structure.

The new nested structure provides better organization by grouping related PostgreSQL configurations together, making it easier to manage both SKU settings and feature flags.


33-36: Verify SKU compatibility with Query Performance Insights.

Please ensure that the Standard_B1ms (Burstable) tier supports Query Performance Insights. Burstable tiers might affect the data collection quality for performance monitoring.

Run this script to check Azure documentation for compatibility:

.azure/infrastructure/test.bicepparam (2)

32-37: LGTM! Well-structured parameter organization.

The restructuring of PostgreSQL configuration into a nested object improves code organization by grouping related settings together. Setting enableQueryPerformanceInsight: false for the test environment aligns with the PR's objective of enabling this feature only in Staging and YT01 environments.


32-37: Verify parameter usage in dependent templates.

Since postgresSku has been replaced with postgresConfiguration, let's verify that all dependent templates have been updated accordingly.

.azure/modules/postgreSql/create.bicep (2)

34-36: LGTM! Well-documented parameter declaration.

The parameter is properly typed and documented, following Bicep best practices.


112-137: Consider using GA API version instead of preview.

The resources are using the preview API version '2023-12-01-preview'. For production deployments, it's recommended to use a GA (Generally Available) version unless specific preview features are required.

Let's check if these configuration parameters are available in the latest GA version:

✅ Verification successful

Since we cannot verify the API versions through the Azure CLI in the sandbox environment, let me try a different approach to gather information about API usage in the codebase.


Let me try one final approach to check the API versions in the Bicep files specifically.


Preview API version is required for Query Performance Insights configurations

Looking at the file content, I notice that while the main PostgreSQL Flexible Server resource uses a GA version (2024-08-01), the configuration resources specifically relate to Query Performance Insights feature, which requires the preview API version. These configurations (track_io_timing, pg_qs.query_capture_mode, and pgms_wait_sampling.query_capture_mode) are conditionally created only when enableQueryPerformanceInsight is true, indicating intentional use of preview features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Azure CLI documentation for PostgreSQL configuration API versions
# Note: This will help determine if these settings are available in GA versions

az postgres flexible-server parameter list --help

Length of output: 121


Script:

#!/bin/bash
# Search for other PostgreSQL flexible server resources in the codebase to check API versions in use
rg "Microsoft.DBforPostgreSQL/flexibleServers" -A 2 -B 2

Length of output: 56


Script:

#!/bin/bash
# Look for any documentation or configuration files that might mention API versions
fd -e md -e json -e yaml -e yml | xargs rg "Microsoft.DBforPostgreSQL"

Length of output: 70


Script:

#!/bin/bash
# Check if there are any ARM/Bicep template files with PostgreSQL resources
fd -e bicep -e json | xargs rg "Microsoft.DBforPostgreSQL/flexibleServers/configurations"

Length of output: 89


Script:

#!/bin/bash
# Look for the specific file and any other Bicep files in the modules directory
fd -e bicep . .azure/modules/postgreSql/

# Check content of the specific file
cat .azure/modules/postgreSql/create.bicep

Length of output: 5529

.azure/infrastructure/main.bicep (1)

206-207: Verify PostgreSQL module implementation.

The parameter updates look good and align with the PR objective to enable Query Performance Insights.

Let's verify the PostgreSQL module implementation:

✅ Verification successful

PostgreSQL module implementation is correct and properly handles Query Performance Insights

The module correctly implements the enableQueryPerformanceInsight parameter:

  • Declares boolean parameter enableQueryPerformanceInsight
  • Properly configures required PostgreSQL settings when enabled:
    • track_io_timing: Set to 'on'
    • pg_qs.query_capture_mode: Set to 'all'
    • pgms_wait_sampling.query_capture_mode: Set to 'all'
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the PostgreSQL module properly implements the enableQueryPerformanceInsight parameter

# Test: Check if the module file exists and contains the parameter
rg -A 5 'param enableQueryPerformanceInsight' .azure/modules/postgreSql/create.bicep

# Test: Check how the parameter is used in the module
rg -A 10 'enableQueryPerformanceInsight' .azure/modules/postgreSql/create.bicep

Length of output: 1577

Copy link

sonarqubecloud bot commented Nov 8, 2024

@arealmaas arealmaas merged commit bb832d8 into main Nov 8, 2024
18 checks passed
@arealmaas arealmaas deleted the chore/enable-query-insights branch November 8, 2024 11:01
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