Skip to content

[WIP] Add weekly data fetching functionality#135

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/add-weekly-data-fetch-functionality
Closed

[WIP] Add weekly data fetching functionality#135
Copilot wants to merge 1 commit intomainfrom
copilot/add-weekly-data-fetch-functionality

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

let _CustomerType = '1P+3P';
let target_tools = dynamic([
"bing_grounding", "azure_ai_search", "python_openapi_tool",
"knowledge_base_retrieve", "bing_custom_search", "azure_fabric",
"sharepoint_grounding", "browser_automation"
]);
// Function to get data for a specific week offset
let getData = (weekOffset: int) {
let startTime = now() - (weekOffset + 1) * 7d;
let endTime = now() - weekOffset * 7d;
let workflow_ind = bizops
| where TIMESTAMP between (startTime .. endTime)
| where Kind == "workflow"
| extend subres_id = substring(ResponseId, 2, 24)
| distinct env_dt_traceId, ResponseId, UserAgent;
let submcpinvoked = cluster('aoaiagents1.westus').database('prod').Log
| where TIMESTAMP between (startTime .. endTime)
| where ['service.name'] == "tool-server"
| where isnotempty(response_id)
| summarize submcptoolinvoked = make_set_if(tool_name, isnotempty(tool_name)) by response_id;
let base = bizops
| where TIMESTAMP between (startTime .. endTime)
| where Kind == 'prompt' and Status == 'Completed'
| extend Date = startofday(TIMESTAMP)
| project ToolsEnabled, ResponseId, env_dt_traceId, SubscriptionId, ParentResponseId
| join kind=leftouter workflow_ind on env_dt_traceId
| extend workflow_ind = case(ParentResponseId startswith "wfresp", 1,
isnotempty(env_dt_traceId1), 1, 0)
| where workflow_ind == 0
| join kind=leftouter submcpinvoked on $left.ResponseId == $right.response_id;
// Direct tool usage (everything but 'remote_tool')
let direct_tool_usage = base
| mv-expand ToolName = todynamic(ToolsEnabled)
| extend ToolName = iff(ToolName startswith "web_search", "web_search", tostring(ToolName))
| where ToolName != "remote_tool"
| project ResponseId, SubscriptionId, ToolName;
// MCP remote subtool usage (only your target_tools)
let remote_tool_usage = base
| where isnotempty(submcptoolinvoked) and submcptoolinvoked != "[]"
| mv-expand ToolName = submcptoolinvoked
| extend ToolName = tostring(ToolName)
| where ToolName in (target_tools)
| project ResponseId, SubscriptionId, ToolName;
let tool_usage = union direct_tool_usage, remote_tool_usage;
tool_usage
| summarize count_distinct_Responses = count_distinct(ResponseId) by SubscriptionId, ToolName
| join kind=leftouter (cluster("https://cogsvcfollower.centralus.kusto.windows.net/").database("Platform").DimSubscription
| project tostring(AzSubscriptionGuid), CloudCustomerGuid) on $left.SubscriptionId == $right.AzSubscriptionGuid
| join kind=inner (cluster("https://cogsvcfollower.centralus.kusto.windows.net/").database("Platform").DimCustomer
| project CloudCustomerGuid, Name, CustomerType) on CloudCustomerGuid
| extend CustomerCat = case(
CustomerType == 'External' and Name !contains 'Microsoft', '3P',
CustomerType == 'Internal' or (CustomerType == 'External' and Name contains 'Microsoft'), '1P',
'Other'
)
| where CustomerCat == (_CustomerType) or _CustomerType == "1P+3P"
| summarize Responses = sum(count_distinct_Responses), NumCCIDs = count_distinct(CloudCustomerGuid) by ToolName
| extend WeekOffset = weekOffset
};
// Get data for current week, last week, and 4 weeks ago
let currentWeek = getData(0); // now-7d to now (last 7 days)
let lastWeek = getData(1); // now-14d to now-7d (previous week)
let fourWeeksAgo = getData(4); // now-35d to now-28d (4 weeks ago)
// Combine and calculate WoW and Wo4W
currentWeek
| join kind=fullouter lastWeek on ToolName
| join kind=fullouter fourWeeksAgo on ToolName
| extend ToolName = coalesce(ToolName, ToolName1, ToolName2)
| extend CurrentResponses = coalesce(Responses, 0)
| extend LastWeekResponses = coalesce(Responses1, 0)
| extend FourWeeksAgoResponses = coalesce(Responses2, 0)
| extend CurrentCCIDs = coalesce(NumCCIDs, 0)
| extend LastWeekCCIDs = coalesce(NumCCIDs1, 0)
| extend FourWeeksAgoCCIDs = coalesce(NumCCIDs2, 0)
| extend WoW_Responses = round(iff(LastWeekResponses > 0, 100.0 * (CurrentResponses - LastWeekResponses) / LastWeekResponses, 0.0), 2)
| extend Wo4W_Responses = round(iff(FourWeeksAgoResponses > 0, 100.0 * (CurrentResponses - FourWeeksAgoResponses) / FourWeeksAgoResponses, 0.0), 2)
| extend WoW_CCIDs = round(iff(LastWeekCCIDs > 0, 100.0 * (CurrentCCIDs - LastWeekCCIDs) / LastWeekCCIDs, 0.0), 2)
| extend Wo4W_CCIDs = round(iff(FourWeeksAgoCCIDs > 0, 100.0 * (CurrentCCIDs - FourWeeksAgoCCIDs) / FourWeeksAgoCCIDs, 0.0), 2)
| project ToolName,
CurrentWeek_Responses = CurrentResponses,
LastWeek_Responses = LastWeekResponses,
FourWeeksAgo_Responses = FourWeeksAgoResponses,
WoW_Responses = strcat(tostring(WoW_Responses), "%"),
Wo4W_Responses = strcat(tostring(Wo4W_Responses), "%"),
CurrentWeek_CCIDs = CurrentCCIDs,
LastWeek_CCIDs = LastWeekCCIDs,
FourWeeksAgo_CCIDs = FourWeeksAgoCCIDs,
WoW_CCIDs = strcat(tostring(WoW_CCIDs), "%"),
Wo4W_CCIDs = strcat(tostring(Wo4W_CCIDs), "%")
| order by CurrentWeek_Responses desc

can you update above query to filter out the subscriptions retrieved from this query
https://ms.portal.azure.com#@72f988bf-86f1-41af-91ab-2d7cd011db47/blade/Microsoft_OperationsManagementSuite_Workspace/Logs.ReactView/resourceId/%2Fsubscriptions%2Fcc5f64cd-70f0-430c-ba64-25ca5628dacf%2Fresourcegroups%2Fai-foundry%2Fproviders%2Fmicrosoft.operationalinsights%2Fworkspaces%2Fai-foundry-prod-logs/source/LogsBlade.AnalyticsShareLinkToQuery/q/H4sIAAAAAAAAA32QwU7DMAyG73uKaJe1hyylrANpKhcOaBK37Y68xO0CaVLZKQPEw5NKCBW0YflgWf7s%252F7fDKKyPSB7cbjiwJttHGzzv4eBQ1OIU6IV70JgtFE8HlNZVs15pI2%252BKppCr60LLA6xXsqw0VOvy1oBuFCGHgTS2FIaeFVjZhMEbelc9hVdrkFh1VlPg0MRl6JFg3A7OerbtMbL6ETClZaKNdKHlRb7cTvQ%252F3T9uZi6ZchCR485Dz8cQ97YbzcTAGhxQdtnyTKT4FKcjEooRe0A%252FikIj7hJvUhVTN5uXRVnJ4irlPP%252BGeOg6IPvxB6w7eMt%252BdfJ8M%252FtHwvnzdX3GVJpNr3hGHcV00dZ8ASRmJwzZAQAA/limit/5000


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@lindazqli lindazqli closed this Mar 2, 2026
@lindazqli lindazqli deleted the copilot/add-weekly-data-fetch-functionality branch March 2, 2026 23:57
Copilot stopped work on behalf of lindazqli due to an error March 2, 2026 23:57
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.

2 participants