# The query behind each alert, saved in the workspace under the alert's own # name, with the columns a responder reads first. Two more read the calls. # # Each call's details sit in properties_s, a string the queries parse as # JSON, and Microsoft publishes neither its format nor its keys. objectId and # modelName are the names Matt Felton's research queried. modelDeploymentName is inferred from Elastic's # model_deployment_name field and the TotalTokens dimension # ModelDeploymentName, and is unverified. If Deployment comes back empty, # read one row's properties_s and correct the key here. locals { calls = "AzureDiagnostics | where TimeGenerated > ago(7d) | where ResourceProvider == \"MICROSOFT.COGNITIVESERVICES\" and Category == \"RequestResponse\" | extend P = parse_json(properties_s) | extend ObjectId = tostring(P.objectId), Deployment = tostring(P.modelDeploymentName), Model = tostring(P.modelName)" saved = merge( { for k, d in local.detections : "ai-${k}" => { display = d.doc query = "${replace(d.query, "ingestion_time() > ago(5m)", "TimeGenerated > ago(7d)")} | project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, ActivityStatusValue, _ResourceId | order by TimeGenerated desc" } }, { "ai-calls-by-caller" = { display = "Inference calls in the last seven days, by account, caller object ID, and deployment" query = "${local.calls} | summarize Calls = count(), First = min(TimeGenerated), Last = max(TimeGenerated), Results = make_set(ResultSignature, 10), IPs = make_set(CallerIPAddress, 10) by Account = _ResourceId, ObjectId, Deployment, Model | order by Calls desc" } "ai-calls-without-object-id" = { display = "Inference calls in the last seven days with no caller object ID. Microsoft does not document objectId for key calls, so an empty value suggests a key and needs checking." query = "${local.calls} | where isempty(ObjectId) | summarize Calls = count(), First = min(TimeGenerated), Last = max(TimeGenerated), Operations = make_set(OperationName, 10) by Account = _ResourceId, CallerIPAddress, Deployment | order by Calls desc" } }, ) } resource "azurerm_log_analytics_saved_search" "ai" { for_each = local.saved name = each.key log_analytics_workspace_id = azurerm_log_analytics_workspace.ai.id category = "AI model logging" display_name = each.value.display query = each.value.query tags = local.tags }