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): connect cae to azure monitor #1486

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,40 @@ module slackNotifier '../modules/functionApp/slackNotifier.bicep' = {
}
}

module containerAppIdentity '../modules/managedIdentity/main.bicep' = {
scope: resourceGroup
name: 'containerAppIdentity'
params: {
name: '${namePrefix}-cae-id'
location: location
tags: tags
}
}

module containerAppEnv '../modules/containerAppEnv/main.bicep' = {
scope: resourceGroup
name: 'containerAppEnv'
params: {
namePrefix: namePrefix
location: location
appInsightWorkspaceName: appInsights.outputs.appInsightsWorkspaceName
appInsightsConnectionString: appInsights.outputs.connectionString
monitorMetricsIngestionEndpoint: monitorWorkspace.outputs.containerAppEnvironmentMetricsIngestionEndpoint
userAssignedIdentityId: containerAppIdentity.outputs.managedIdentityId
subnetId: vnet.outputs.containerAppEnvironmentSubnetId
tags: tags
}
}

module monitorMetricsPublisherRoles '../modules/monitor-workspace/addMetricsPublisherRoles.bicep' = {
scope: resourceGroup
name: 'monitorMetricsPublisherRoles'
params: {
monitorWorkspaceName: monitorWorkspace.outputs.monitorWorkspaceName
principalIds: [containerAppIdentity.outputs.managedIdentityPrincipalId]
}
}
arealmaas marked this conversation as resolved.
Show resolved Hide resolved

module appInsightsReaderAccessPolicy '../modules/applicationInsights/addReaderRoles.bicep' = {
scope: resourceGroup
name: 'appInsightsReaderAccessPolicy'
Expand Down
40 changes: 39 additions & 1 deletion .azure/modules/containerAppEnv/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@ param tags object
@description('The name of the Application Insights workspace')
param appInsightWorkspaceName string

@description('The Application Insights connection string')
param appInsightsConnectionString string

@description('The metrics ingestion endpoint of the Azure Monitor workspace')
param monitorMetricsIngestionEndpoint string

@description('The ID of the user-assigned managed identity')
param userAssignedIdentityId string

resource appInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
name: appInsightWorkspaceName
}

resource containerAppEnv 'Microsoft.App/managedEnvironments@2024-03-01' = {
resource containerAppEnv 'Microsoft.App/managedEnvironments@2024-02-02-preview' = {
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
name: '${namePrefix}-cae'
location: location
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${userAssignedIdentityId}': {}
}
}
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
Expand All @@ -32,6 +47,29 @@ resource containerAppEnv 'Microsoft.App/managedEnvironments@2024-03-01' = {
infrastructureSubnetId: subnetId
internal: false
}
appInsightsConfiguration: {
connectionString: appInsightsConnectionString
}
openTelemetryConfiguration: {
tracesConfiguration: {
destinations: ['appInsights']
}
logsConfiguration: {
destinations: ['appInsights']
}
metricsConfiguration: {
destinations: ['metrics-ingestion']
}
destinationsConfiguration: {
otlpConfigurations: [
{
endpoint: monitorMetricsIngestionEndpoint
name: 'metrics-ingestion'
insecure: false
}
]
}
}
}
tags: tags
}
Expand Down
17 changes: 17 additions & 0 deletions .azure/modules/managedIdentity/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@description('The location where the resources will be deployed')
param location string

@description('The name of the managed identity')
param name string

@description('Tags to apply to resources')
param tags object

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: name
location: location
tags: tags
}

output managedIdentityId string = managedIdentity.id
output managedIdentityPrincipalId string = managedIdentity.properties.principalId
25 changes: 25 additions & 0 deletions .azure/modules/monitor-workspace/addMetricsPublisherRoles.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@description('The name of the Monitor workspace')
param monitorWorkspaceName string

@description('Array of principal IDs to assign the Monitoring Metrics Publisher role to')
param principalIds array

resource monitorWorkspace 'Microsoft.Monitor/accounts@2023-04-03' existing = {
name: monitorWorkspaceName
}

@description('This is the built-in Monitoring Metrics Publisher role. See https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#monitoring-metrics-publisher')
resource monitoringMetricsPublisherRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
scope: subscription()
name: '3913510d-42f4-4e42-8a64-420c390055eb'
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = [for principalId in principalIds: {
scope: monitorWorkspace
name: guid(monitorWorkspace.id, principalId, monitoringMetricsPublisherRole.id)
properties: {
roleDefinitionId: monitoringMetricsPublisherRole.id
principalId: principalId
principalType: 'ServicePrincipal'
}
}]
52 changes: 52 additions & 0 deletions .azure/modules/monitor-workspace/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,57 @@ resource monitorWorkspace 'Microsoft.Monitor/accounts@2023-04-03' = {
tags: tags
}

resource containerAppEnvironmentDataCollectionEndpoint 'Microsoft.Insights/dataCollectionEndpoints@2023-03-11' = {
name: '${namePrefix}-cae-dce'
location: location
properties: {
description: 'DCE for Container App Environment'
networkAcls: {
publicNetworkAccess: 'Enabled'
}
}
tags: tags
}

resource containerAppEnvironmentDataCollectionRule 'Microsoft.Insights/dataCollectionRules@2023-03-11' = {
name: '${namePrefix}-cae-dcr'
location: location
properties: {
description: 'DCR for Container App Environment'
dataCollectionEndpointId: containerAppEnvironmentDataCollectionEndpoint.id
dataSources: {
prometheusForwarder: [
{
streams: [
'Microsoft-PrometheusMetrics'
]
name: 'PrometheusDataSource'
}
]
}
destinations: {
monitoringAccounts: [
{
accountResourceId: monitorWorkspace.id
name: 'MonitoringAccountDestination'
}
]
}
dataFlows: [
{
streams: [
'Microsoft-PrometheusMetrics'
]
destinations: [
'MonitoringAccountDestination'
]
}
]
}
tags: tags
}

output monitorWorkspaceId string = monitorWorkspace.id
output monitorWorkspaceName string = monitorWorkspace.name
output containerAppEnvironmentMetricsIngestionEndpoint string = containerAppEnvironmentDataCollectionEndpoint.properties.metricsIngestion.endpoint
output containerAppEnvironmentLogsIngestionEndpoint string = containerAppEnvironmentDataCollectionEndpoint.properties.logsIngestion.endpoint
Loading