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(grafana): add dialogporten test #1192

Merged
merged 8 commits into from
Dec 19, 2024
Merged

feat(grafana): add dialogporten test #1192

merged 8 commits into from
Dec 19, 2024

Conversation

sduranc
Copy link
Collaborator

@sduranc sduranc commented Dec 19, 2024

Description

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

    • Introduced new data sources for Azure resource group and Log Analytics workspace.
    • Added role assignments for "Monitoring Reader" and "Log Analytics Reader" to enhance Grafana dashboard capabilities.
    • Added a new provider configuration for Azure Resource Manager to manage resources under a different subscription.
  • Bug Fixes

    • Updated existing role assignment to include new scope for "Log Analytics Reader".

Copy link

coderabbitai bot commented Dec 19, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces new Terraform configuration changes for Azure infrastructure, specifically in the altinn-monitor-test-rg directory. The modifications focus on adding data sources for a new resource group and Log Analytics workspace, and expanding Grafana dashboard role assignments. These changes enhance the monitoring and access configuration for the "Dialogporten" context, adding new role assignments for monitoring and log analytics reading permissions.

Changes

File Change Summary
infrastructure/adminservices-test/altinn-monitor-test-rg/data.tf Added two new data sources:
- azurerm_resource_group for dp-be-test-rg
- azurerm_log_analytics_workspace for dp-be-test-insightsWorkspace
infrastructure/adminservices-test/altinn-monitor-test-rg/grafana.tf Added new role assignments:
- monitoring_reader_rg_dp_test
- grafana_identity_reader_rg_dp_test
- Modified existing log_analytics_reader role assignment with new scope
infrastructure/adminservices-test/altinn-monitor-test-rg/providers.tf Added new provider configuration for Azure Resource Manager with alias dp, specifying a different subscription_id

📜 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 7d6ad14 and 7939005.

📒 Files selected for processing (1)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/providers.tf (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/providers.tf

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

@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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4971dac and 784cf67.

📒 Files selected for processing (2)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/data.tf (1 hunks)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/grafana.tf (2 hunks)
🧰 Additional context used
📓 Learnings (1)
infrastructure/adminservices-test/altinn-monitor-test-rg/data.tf (1)
Learnt from: monteiro-renato
PR: Altinn/altinn-platform#1138
File: infrastructure/adminservices-test/altinn-monitor-test-rg/lasttest.tf:1-10
Timestamp: 2024-11-27T09:21:33.566Z
Learning: In the `infrastructure/adminservices-test/altinn-monitor-test-rg` Terraform configuration, it's acceptable to add resources like `azurerm_resource_group` and `azurerm_monitor_workspace` without including additional variables, outputs, provider, or backend configurations.
🔇 Additional comments (4)
infrastructure/adminservices-test/altinn-monitor-test-rg/data.tf (2)

4-7: LGTM: Resource group data source configuration is correct.

The resource group data source is properly configured with:

  • Consistent naming convention (dp-be-test-rg)
  • Appropriate location (norwayeast)

9-12: LGTM: Log Analytics workspace data source is properly configured.

The configuration correctly references the resource group name using the data source dependency.

infrastructure/adminservices-test/altinn-monitor-test-rg/grafana.tf (2)

44-50: LGTM: Monitoring Reader role assignment for Dialogporten test resource group.

The role assignment is properly configured with:

  • Correct scope using the data source
  • Appropriate role definition ID
  • System-assigned identity from Grafana

Line range hint 44-110: Verify the role assignments in Azure Portal.

Please ensure that:

  1. The Grafana managed identity has the correct permissions
  2. The role assignments are properly scoped
  3. The Log Analytics workspace is accessible from Grafana

Comment on lines 105 to 110
resource "azurerm_role_assignment" "log_analytics_reader" {
principal_id = azurerm_dashboard_grafana.grafana.identity[0].principal_id
scope = data.azurerm_log_analytics_workspace.dp_law_test.id
role_definition_name = "Log Analytics Reader"
skip_service_principal_aad_check = true
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Resource naming conflict: Duplicate resource name 'log_analytics_reader'.

There's already an existing resource named log_analytics_reader (line ~100). Terraform requires unique resource names within the same configuration.

Rename the resource to avoid the conflict:

-resource "azurerm_role_assignment" "log_analytics_reader" {
+resource "azurerm_role_assignment" "log_analytics_reader_dp" {
   principal_id                     = azurerm_dashboard_grafana.grafana.identity[0].principal_id
   scope                            = data.azurerm_log_analytics_workspace.dp_law_test.id
   role_definition_name             = "Log Analytics Reader"
   skip_service_principal_aad_check = true
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
resource "azurerm_role_assignment" "log_analytics_reader" {
principal_id = azurerm_dashboard_grafana.grafana.identity[0].principal_id
scope = data.azurerm_log_analytics_workspace.dp_law_test.id
role_definition_name = "Log Analytics Reader"
skip_service_principal_aad_check = true
}
resource "azurerm_role_assignment" "log_analytics_reader_dp" {
principal_id = azurerm_dashboard_grafana.grafana.identity[0].principal_id
scope = data.azurerm_log_analytics_workspace.dp_law_test.id
role_definition_name = "Log Analytics Reader"
skip_service_principal_aad_check = true
}

Comment on lines +52 to +57
resource "azurerm_role_assignment" "grafana_identity_reader_rg_dp_test" {
scope = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4"
role_definition_name = "Monitoring Reader"
principal_id = azurerm_dashboard_grafana.grafana.identity[0].principal_id
skip_service_principal_aad_check = true
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace hardcoded subscription ID with a variable or data source.

The subscription ID is hardcoded in the scope. This makes the configuration less maintainable and portable across environments.

Consider using the existing data source:

-  scope                            = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4"
+  scope                            = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
resource "azurerm_role_assignment" "grafana_identity_reader_rg_dp_test" {
scope = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4"
role_definition_name = "Monitoring Reader"
principal_id = azurerm_dashboard_grafana.grafana.identity[0].principal_id
skip_service_principal_aad_check = true
}
resource "azurerm_role_assignment" "grafana_identity_reader_rg_dp_test" {
scope = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
role_definition_name = "Monitoring Reader"
principal_id = azurerm_dashboard_grafana.grafana.identity[0].principal_id
skip_service_principal_aad_check = true
}

Copy link

@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-monitor-test-rg/providers.tf (1)

24-24: Add documentation for the Dialogporten provider

Consider adding a more detailed comment explaining the purpose of this provider and its relationship with the monitoring infrastructure. This will help future maintainers understand the separation of concerns between the two subscriptions.

-# Dialogporten
+# Dialogporten provider configuration
+# This provider is used to access monitoring resources in the Dialogporten subscription
+# for integration with the main monitoring infrastructure
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac5dee1 and 5c585cc.

📒 Files selected for processing (2)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/data.tf (1 hunks)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/providers.tf (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/data.tf
🔇 Additional comments (1)
infrastructure/adminservices-test/altinn-monitor-test-rg/providers.tf (1)

25-30: Verify pre-registered providers in the Dialogporten subscription

The configuration looks correct, but since skip_provider_registration = true is set, please ensure that all necessary Azure resource providers are pre-registered in the Dialogporten subscription (8a353de8-d81d-468d-a40d-f3574b6bb3f4).

Copy link

github-actions bot commented Dec 19, 2024

Terraform environment test

Format and Style 🖌failure

Initialization ⚙️success

Validation 🤖success

Validation Output

Success! The configuration is valid.


Plan 📖success

Show Plan

[Lines containing Refreshing state removed]
[Maybe further truncated see logs for complete plan output]
Acquiring state lock. This may take a few moments...
data.azurerm_client_config.current: Reading...
data.azurerm_monitor_data_collection_rule.prometheus: Reading...
data.azurerm_client_config.current: Read complete after 0s [id=Y2xpZW50Q29uZmlncy9jbGllbnRJZD1mMDNmNzU3OS01ZjM5LTRkN2YtYmNlYS04ZTVjYjZkN2FjYTQ7b2JqZWN0SWQ9MDJiMTdkMjgtN2VjOC00MDg0LTkyY2UtZDI2MDUxZmE0OTk4O3N1YnNjcmlwdGlvbklkPTFjZThlOWFmLWMyZDYtNDRlNy05YzVlLTA5OWEzMDgwNTZmZTt0ZW5hbnRJZD1jZDAwMjZkOC0yODNiLTRhNTUtOWJmYS1kMGVmNGE4YmEyMWM=]
data.azurerm_monitor_data_collection_rule.prometheus: Read complete after 0s [id=/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/MA_k6tests-amw_norwayeast_managed/providers/Microsoft.Insights/dataCollectionRules/k6tests-amw]
data.azurerm_resource_group.rg_dp_test: Reading...
data.azurerm_resource_group.rg_dp_test: Read complete after 0s [id=/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg]
data.azurerm_log_analytics_workspace.dp_law_test: Reading...
data.azurerm_log_analytics_workspace.dp_law_test: Read complete after 1s [id=/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg/providers/Microsoft.OperationalInsights/workspaces/dp-be-test-insightsWorkspace]

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

Terraform will perform the following actions:

  # azurerm_kubernetes_cluster.k6tests will be updated in-place
  ~ resource "azurerm_kubernetes_cluster" "k6tests" {
        id                                  = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/k6tests-rg/providers/Microsoft.ContainerService/managedClusters/k6tests-cluster"
        name                                = "k6tests-cluster"
        tags                                = {}
        # (31 unchanged attributes hidden)

      ~ default_node_pool {
            name                          = "default"
            tags                          = {}
            # (30 unchanged attributes hidden)

          - upgrade_settings {
              - drain_timeout_in_minutes      = 0 -> null
              - max_surge                     = "10%" -> null
              - node_soak_duration_in_minutes = 0 -> null
            }
        }

        # (4 unchanged blocks hidden)
    }

  # azurerm_kubernetes_cluster_node_pool.spot will be updated in-place
  ~ resource "azurerm_kubernetes_cluster_node_pool" "spot" {
        id                            = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/k6tests-rg/providers/Microsoft.ContainerService/managedClusters/k6tests-cluster/agentPools/spot"
        name                          = "spot"
      ~ node_labels                   = {
          - "kubernetes.azure.com/scalesetpriority" = "spot" -> null
            # (1 unchanged element hidden)
        }
      ~ node_taints                   = [
          - "kubernetes.azure.com/scalesetpriority=spot:NoSchedule",
        ]
        tags                          = {}
        # (29 unchanged attributes hidden)
    }

  # azurerm_role_assignment.grafana_identity_reader_rg_dp_test will be created
  + resource "azurerm_role_assignment" "grafana_identity_reader_rg_dp_test" {
      + condition_version                = (known after apply)
      + id                               = (known after apply)
      + name                             = (known after apply)
      + principal_id                     = "ccc9af1e-ab07-4895-8a2e-446fce26e871"
      + principal_type                   = (known after apply)
      + role_definition_id               = (known after apply)
      + role_definition_name             = "Monitoring Reader"
      + scope                            = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4"
      + skip_service_principal_aad_check = true
    }

  # azurerm_role_assignment.log_analytics_reader_dp_test will be created
  + resource "azurerm_role_assignment" "log_analytics_reader_dp_test" {
      + condition_version                = (known after apply)
      + id                               = (known after apply)
      + name                             = (known after apply)
      + principal_id                     = "ccc9af1e-ab07-4895-8a2e-446fce26e871"
      + principal_type                   = (known after apply)
      + role_definition_id               = (known after apply)
      + role_definition_name             = "Log Analytics Reader"
      + scope                            = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg/providers/Microsoft.OperationalInsights/workspaces/dp-be-test-insightsWorkspace"
      + skip_service_principal_aad_check = true
    }

  # azurerm_role_assignment.monitoring_reader_rg_dp_test will be created
  + resource "azurerm_role_assignment" "monitoring_reader_rg_dp_test" {
      + condition_version                = (known after apply)
      + id                               = (known after apply)
      + name                             = (known after apply)
      + principal_id                     = "ccc9af1e-ab07-4895-8a2e-446fce26e871"
      + principal_type                   = (known after apply)
      + role_definition_id               = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05"
      + role_definition_name             = (known after apply)
      + scope                            = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg"
      + skip_service_principal_aad_check = true
    }

Plan: 3 to add, 2 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 @sduranc
Action push
Working Directory ./infrastructure/adminservices-test/altinn-monitor-test-rg
State File github.com/altinn/altinn-platform/environments/test/altinn-monitor-test-rg.tfstate
Plan File github.com_altinn_altinn-platform_environments_test_altinn-monitor-test-rg.tfstate.tfplan

@sduranc sduranc merged commit aed7cf7 into main Dec 19, 2024
6 checks passed
@sduranc sduranc deleted the add-dg-to-grafana branch December 19, 2024 12:44
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.

1 participant