-
Notifications
You must be signed in to change notification settings - Fork 160
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
Data Connection Rule / Endpoint and Log Analytics DCR-driven table for structured logging #1171
Comments
There is not Farmer support, and it would definitely be appreciated. I tried to figure out the changes to get a VM to send syslog using DCR a while back and wasn't able to get it working end to end through ARM. If you have more to share on what you got working or could submit a draft PR to get things started, please mention me and I'll be happy to help. |
I managed to get a few things working with the JSON escape hatch.
let loggingName = "log-analytics"
let logging = logAnalytics {
name loggingName
retention_period 30<Days>
daily_cap 1<Gb> // Need alert if we hit limit, see below
}
let serilogDcr // Hard coded Serilog columns
serilogTableName
dcrName
location
workspaceResourceId
logWorkspaceName
streamName =
$"""{{
"type": "microsoft.insights/datacollectionrules",
"apiVersion": "2023-03-11",
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces/tables', '{logWorkspaceName}', '{serilogTableName}')]"
],
"name": "{dcrName}",
"location": "{location}",
"tags": {{}},
"properties": {{
"streamDeclarations": {{
"{streamName}": {{
"columns": [
{{
"name": "TimeGenerated",
"type": "datetime"
}},
{{
"name": "Event",
"type": "dynamic"
}}
]
}}
}},
"dataSources": {{}},
"destinations": {{
"logAnalytics": [
{{
"workspaceResourceId": "{workspaceResourceId}",
"name": "{logWorkspaceName}"
}}
]
}},
"dataFlows": [
{{
"streams": [
"{streamName}"
],
"destinations": [
"{logWorkspaceName}"
],
"transformKql": "source",
"outputStream": "{streamName}"
}}
]
}}
}}"""
|> Resource.ofJson
let serilogTable // Hard coded Serilog columns / Analytics plan
serilogTableName
logWorkspaceName
retentionInDays =
$"""{{
"type": "Microsoft.OperationalInsights/workspaces/tables",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', '{logWorkspaceName}')]"
],
"name": "{logWorkspaceName}/{serilogTableName}",
"properties": {{
"plan": "Analytics",
"retentionInDays": "{retentionInDays}",
"schema": {{
"columns": [
{{
"name": "TimeGenerated",
"type": "datetime"
}},
{{
"name": "Event",
"type": "dynamic"
}}
],
"name": "{serilogTableName}"
}},
"totalRetentionInDays": "{retentionInDays}"
}}
}}"""
|> Resource.ofJson
let deployLocation = Location.UKSouth
let workspaceResourceId = $"/subscriptions/{subId}/resourceGroups/{resGroupName}/providers/Microsoft.OperationalInsights/workspaces/{loggingName}"
let serilogTableName = "Serilog_CL"
let logTable = serilogTable serilogTableName loggingName 30
let dcr =
serilogDcr
serilogTableName
"SerilogDCR"
deployLocation.ArmValue
workspaceResourceId
loggingName
$"Custom-{serilogTableName}" |
I managed to get the Serilog ingestion working by clicking it together in the portal before I started, and the only thing I have to add to the Farmer deploy now to finish the recreation is the MonitoringMetricsPublisher role for my AppService's SystemIdentity with scope of the DCR. That will be something like this but I am still trying to get it to deploy let metricsPublishingRole =
{ Name = createRoleName app.Name.ResourceName.Value app.SystemIdentity.PrincipalId Roles.MonitoringMetricsPublisher
RoleDefinitionId = Roles.MonitoringMetricsPublisher
PrincipalId = app.SystemIdentity.PrincipalId
PrincipalType = Arm.RoleAssignment.PrincipalType.ServicePrincipal
Scope = Arm.RoleAssignment.AssignmentScope.SpecificResource dcr.ResourceId
Dependencies = Set.ofList [ dcr.ResourceId; app.ResourceId ] } :> IArmResource |
Got it - scoping to the resource seems bugged, returning e.g.
If I just scope to the resource group it deploys though. let metricsPublishingRole =
{ Name = createRoleName app.Name.ResourceName.Value app.SystemIdentity.PrincipalId Roles.MonitoringMetricsPublisher
RoleDefinitionId = Roles.MonitoringMetricsPublisher
PrincipalId = app.SystemIdentity.PrincipalId
PrincipalType = Arm.RoleAssignment.PrincipalType.ServicePrincipal
Scope = Arm.RoleAssignment.AssignmentScope.ResourceGroup // Tried to scope to DCR but failed with unknown resource id
Dependencies = Set.empty } I will test if the Serilog and OTel data is flowing through and confirm. |
Role assignment worked as I have metrics coming through. I will need to create a DCE even though they are optional for ARM-created DCRs, because the Serilog plugin needs the URL. Once I have this all working I'll share the complete sample. |
@ninjarobot Here's a complete working sample. It has Serilog structured logging, OTel metric and Traces plus the search query alert for data limits. I will hopefully find time to make a proper Farmer PR rather than using the JSON, I just need to re-familiarise myself with the code, it's been a while! |
I have just set up structured logging in Log Analytics using Serilog's most recent plugin.
As part of that, you have to follow a guide showing you how to use the Log Ingestion API.
The steps are roughly
I had to do all of these steps in the portal as I couldn't find Farmer support for them, although I may have missed it.
There is a guide to deploying with ARM.
I think we would need the abilities to
This is another one I am happy to pick up and have a go at if it sounds like I am on the right track? :)
The text was updated successfully, but these errors were encountered: