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(apim): add diagnostics settings #1423

Merged
merged 3 commits into from
Mar 12, 2025
Merged

Conversation

tjololo
Copy link
Member

@tjololo tjololo commented Mar 11, 2025

Description

Add diagnostics settings to test apim

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)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features

    • Enhanced monitoring and diagnostic capabilities for our API services, improving system observability and performance insights.
  • Style

    • Applied formatting improvements to configuration settings for clearer presentation.

@tjololo tjololo requested a review from a team as a code owner March 11, 2025 20:01
Copy link
Contributor

coderabbitai bot commented Mar 11, 2025

📝 Walkthrough

Walkthrough

This pull request modifies the Terraform configuration for Azure API Management diagnostics by renaming an existing diagnostic resource and adding a new one. The azurerm_api_management_diagnostic resource previously named apimdiagnostic is renamed to application_insights, and a new resource named azuremonitor is introduced. Additionally, a formatting change is made in the apim.tf file, which adds a blank line between two attributes without affecting functionality.

Changes

File Change Summary
infrastructure/adminservices-test/altinn-apim-test-rg/analytics.tf Renamed azurerm_api_management_diagnostic "apimdiagnostic" to azurerm_api_management_diagnostic "application_insights" and added a new resource azurerm_api_management_diagnostic "azuremonitor" with diagnostic settings.
infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf Added a blank line for formatting clarity between the publisher_email and sku_name attributes in the API Management resource block.

Suggested reviewers

  • monteiro-renato

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8906830 and b250289.

📒 Files selected for processing (2)
  • infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf (1 hunks)
  • infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf
  • infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)

🪧 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 generate docstrings to generate docstrings for this 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.

@tjololo tjololo changed the title feat: add diagnostics settings feat(apim): add diagnostics settings Mar 11, 2025
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

🧹 Nitpick comments (1)
infrastructure/adminservices-test/altinn-apim-test-rg/analytics.tf (1)

18-65: Comprehensive Diagnostic Configuration Review
The new azurerm_api_management_diagnostic resource is well-structured and covers all necessary aspects of diagnostics by including detailed blocks for frontend and backend requests/responses. A few points for your consideration:

  • Sampling Percentage: The sampling_percentage is set to 0.0, which implies that no traffic will be sampled. Confirm that this is the intended behavior for your test environment.
  • Payload Capture: The setting body_bytes = 32 is applied consistently. Verify that capturing 32 bytes is sufficient to obtain the required diagnostic details.
  • Headers Logging: The lists under all header logging blocks (frontend_request, frontend_response, backend_request, and backend_response) are comprehensive. Double-check that these headers align with your logging and observability standards.
    Overall, the diagnostic settings enhance the observability for the API Management service effectively.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df6ff2b and 8894a83.

📒 Files selected for processing (2)
  • infrastructure/adminservices-test/altinn-apim-test-rg/analytics.tf (1 hunks)
  • infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: altinn-apim-test-rg
infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf

[error] 1-1: Terraform formatting check failed. Run 'terraform fmt' to format the code.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
infrastructure/adminservices-test/altinn-apim-test-rg/apim.tf (1)

1-9: Terraform Formatting Consistency
The resource block now includes a blank line (at line 7) between the publisher_email and sku_name attributes. However, the pipeline error indicates that the file does not pass the Terraform formatting check. Please run terraform fmt to auto-format the file according to Terraform’s style guidelines.

🧰 Tools
🪛 GitHub Actions: altinn-apim-test-rg

[error] 1-1: Terraform formatting check failed. Run 'terraform fmt' to format the code.

infrastructure/adminservices-test/altinn-apim-test-rg/analytics.tf (2)

1-6: Application Insights Resource Configuration
The new azurerm_application_insights resource is clearly defined with proper variable interpolation for naming, resource group association, and location setup. Consider reviewing if additional optional settings (e.g., retention policies or sampling configs) might further enhance your monitoring configuration later on.


8-16: API Management Logger Setup
The azurerm_api_management_logger resource is correctly integrated with the Application Insights resource via the instrumentation key. Ensure that the referenced api_management_name is accurate and that the logger meets the telemetry requirements for your diagnostics testing.

Copy link

github-actions bot commented Mar 11, 2025

Terraform environment test

Format and Style 🖌success

Initialization ⚙️success

Validation 🤖success

Validation Output

Success! The configuration is valid.


Plan 📖success

Show Plan

[Lines containing Refreshing state removed]
[Truncated to 120000 bytes! See logoutput for complete plan]
Acquiring state lock. This may take a few moments...
data.azurerm_container_registry.altinncr: Reading...
data.azurerm_container_registry.altinncr: Read complete after 1s [id=/subscriptions/a6e9ee7d-2b65-41e1-adfb-0c8c23515cf9/resourceGroups/acr/providers/Microsoft.ContainerRegistry/registries/altinncr]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_api_management_diagnostic.azuremonitor will be created
  + resource "azurerm_api_management_diagnostic" "azuremonitor" {
      + always_log_errors         = true
      + api_management_logger_id  = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/altinn-apim-test-rg/providers/Microsoft.ApiManagement/service/altinn-apim-test-apim/loggers/altinn-apim-test-apimlogger"
      + api_management_name       = "altinn-apim-test-apim"
      + http_correlation_protocol = "W3C"
      + id                        = (known after apply)
      + identifier                = "azuremonitor"
      + log_client_ip             = true
      + resource_group_name       = "altinn-apim-test-rg"
      + sampling_percentage       = 0
      + verbosity                 = "information"

      + backend_request {
        }

      + backend_response {
        }

      + frontend_request {
        }

      + frontend_response {
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: tfplan.out

To perform exactly these actions, run the following command to apply:
    terraform apply "tfplan.out"
Releasing state lock. This may take a few moments...

Context Values
Pusher @tjololo
Action workflow_dispatch
Working Directory ./infrastructure/adminservices-test/altinn-apim-test-rg
State File github.com/altinn/altinn-platform/environments/test/altinn-apim-test-rg.tfstate
Plan File github.com_altinn_altinn-platform_environments_test_altinn-apim-test-rg.tfstate.tfplan

@sduranc
Copy link
Collaborator

sduranc commented Mar 12, 2025

LGTM but why does it need its own AI (app insights)? I thought it was gonna use either the tenant/owner's or ours.

@tjololo
Copy link
Member Author

tjololo commented Mar 12, 2025

LGTM but why does it need its own AI (app insights)? I thought it was gonna use either the tenant/owner's or ours.

Just a test apim that I use to test the removal of subscription keys and extra logging (trace/metrics for the client id in the JWT-token) Once I'm done the whole environment is going to be deleted.

@tjololo tjololo merged commit e553437 into main Mar 12, 2025
8 checks passed
@tjololo tjololo deleted the feat/apim-add-diagnostics branch March 12, 2025 08:51
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