Skip to content

Implement Data Collection Rule for Container Insights#623

Merged
lonegunmanb merged 4 commits intomainfrom
container-insights-dcr
Mar 20, 2025
Merged

Implement Data Collection Rule for Container Insights#623
lonegunmanb merged 4 commits intomainfrom
container-insights-dcr

Conversation

@zioproto
Copy link
Copy Markdown
Contributor

Describe your changes

Implement Data Collection Rule for Container Insights. This completes the work started in PR #446

Issue number

#607

Checklist before requesting a review

  • The pr title can be used to describe what this pr did in CHANGELOG.md file
  • I have executed pre-commit on my machine
  • I have passed pr-check on my machine

@zioproto
Copy link
Copy Markdown
Contributor Author

@lonegunmanb this PR was implemented looking at the documentation example available here:

https://github.com/microsoft/Docker-Provider/tree/ci_prod/scripts/onboarding/aks/onboarding-msi-terraform-syslog

Cc: @ganga1980 and @wanlonghenry in case they have review comments. Thanks

Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

@zioproto We've got the following error:

TestExamplesForV4/application_gateway_ingress_v4 2024-12-20T16:01:45Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; ╷
│ Error: Attempt to get attribute from null value
│ 
│   on ../../v4/log_analytics.tf line 86, in locals:
│   86:   dcr_location = coalesce(local.log_analytics_workspace.location, try(data.azurerm_log_analytics_workspace.main[0].location, null))
│     ├────────────────
│     │ local.log_analytics_workspace is null
│ 
│ This value is null, so it does not have any attributes.
╵}
    apply.go:34: 
        	Error Trace:	/src/test/vendor/github.com/gruntwork-io/terratest/modules/terraform/apply.go:34
        	            				/src/test/vendor/github.com/Azure/terraform-module-test-helper/e2etest.go:107
        	            				/src/test/vendor/github.com/Azure/terraform-module-test-helper/e2etest.go:87
        	            				/src/test/vendor/github.com/Azure/terraform-module-test-helper/e2etest.go:55
        	            				/src/test/e2e/terraform_aks_test.go:211
        	Error:      	Received unexpected error:
        	            	FatalError{Underlying: error while running command: exit status 1; ╷
        	            	│ Error: Attempt to get attribute from null value
        	            	│ 
        	            	│   on ../../v4/log_analytics.tf line 86, in locals:
        	            	│   86:   dcr_location = coalesce(local.log_analytics_workspace.location, try(data.azurerm_log_analytics_workspace.main[0].location, null))
        	            	│     ├────────────────
        	            	│     │ local.log_analytics_workspace is null
        	            	│ 
        	            	│ This value is null, so it does not have any attributes.
        	            	╵}
        	Test:       	TestExamplesForV4/application_gateway_ingress_v4

Need further investigation.

Comment thread log_analytics.tf Outdated
}

locals {
dcr_location = coalesce(local.log_analytics_workspace.location, try(data.azurerm_log_analytics_workspace.main[0].location, null))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we try coalesce(try(local.log_analytics_workspace.location, null), try(data.azurerm_log_analytics_workspace.main[0].location, null)) here?

@zioproto
Copy link
Copy Markdown
Contributor Author

zioproto commented Jan 9, 2025

@lonegunmanb I managed to find the correct expression, the E2E tests are now passing. Please have a look. Thanks

Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @zioproto , some comments

Comment thread log_analytics.tf Outdated
data_sources {
syslog {
streams = ["Microsoft-Syslog"]
facility_names = var.syslog_facilities
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we rename this new variable to monitor_data_collection_rule_data_sources_syslog_facilities?

Comment thread log_analytics.tf Outdated
syslog {
streams = ["Microsoft-Syslog"]
facility_names = var.syslog_facilities
log_levels = var.syslog_levels
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we rename this new variable to monitor_data_collection_rule_data_sources_syslog_levels?

Comment thread log_analytics.tf Outdated
}

extension {
streams = var.streams
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we rename this new variable to monitor_data_collection_rule_extensions_streams?

Comment thread log_analytics.tf
"namespaces" : var.data_collection_settings.namespaces_for_data_collection,
"enableContainerLogV2" : var.data_collection_settings.container_log_v2_enabled,
}
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could use HCL syntax here:

{
        dataCollectionSettings = {
          interval = var.data_collection_settings.data_collection_interval
          namespaceFilteringMode = var.data_collection_settings.namespace_filtering_mode_for_data_collection
          namespaces = var.data_collection_settings.namespaces_for_data_collection
          enableContainerLogV2 = var.data_collection_settings.container_log_v2_enabled
        }
      }

Comment thread log_analytics.tf Outdated
}

resource "azurerm_monitor_data_collection_rule" "dcr" {
count = (var.log_analytics_workspace_enabled && var.oms_agent_enabled) ? 1 : 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would count = (local.create_analytics_workspace && var.oms_agent_enabled) ? 1 : 0 be better?

Comment thread log_analytics.tf Outdated
}

resource "azurerm_monitor_data_collection_rule_association" "dcra" {
count = (var.log_analytics_workspace_enabled && var.oms_agent_enabled) ? 1 : 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would count = (local.create_analytics_workspace && var.oms_agent_enabled) ? 1 : 0 be better?

Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @zioproto, LGTM!

@lonegunmanb lonegunmanb merged commit 252c132 into main Mar 20, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Azure Module Kanban Mar 20, 2025
@lonegunmanb lonegunmanb deleted the container-insights-dcr branch March 20, 2025 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants