-
Notifications
You must be signed in to change notification settings - Fork 340
Azure Monitor: Use Azure.ResourceManager.Monitor package to query metrics #1409
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
Conversation
jairmyree
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the one comment it looks good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request migrates the Azure Monitor metrics querying implementation from the deprecated Azure.Monitor.Query SDK to the newer Azure.ResourceManager.Monitor SDK. The refactoring modernizes the metrics subsystem to align with current Azure SDK recommendations and improves long-term maintainability.
Key Changes:
- Replaced
Azure.Monitor.Querypackage withAzure.ResourceManager.Monitor(version 1.4.0-beta.3) - Removed
IMetricsQueryClientServiceinterface and its implementation, migrating to ARM client pattern viaBaseAzureService.CreateArmClientAsync - Updated metric querying, definitions, and namespaces logic to use ARM Monitor SDK APIs with pageable async enumerables instead of the previous SDK's response patterns
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Packages.props | Removed Azure.Monitor.Query package reference and added Azure.ResourceManager.Monitor beta package |
| tools/Azure.Mcp.Tools.Quota/src/Azure.Mcp.Tools.Quota.csproj | Removed Azure.Monitor.Query package reference (cleanup) |
| tools/Azure.Mcp.Tools.Monitor/src/Azure.Mcp.Tools.Monitor.csproj | Removed Azure.Monitor.Query and added Azure.ResourceManager.Monitor package references |
| tools/Azure.Mcp.Tools.Monitor/src/MonitorSetup.cs | Removed IMetricsQueryClientService from service registration |
| tools/Azure.Mcp.Tools.Monitor/src/Services/IMetricsQueryClientService.cs | Deleted interface (no longer needed with ARM client pattern) |
| tools/Azure.Mcp.Tools.Monitor/src/Services/MetricsQueryClientService.cs | Deleted service implementation (replaced by ARM client from base class) |
| tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorMetricsService.cs | Refactored all three methods to use ARM Monitor SDK, updated constructor to remove metrics client dependency, added ISO string helper method |
| tools/Azure.Mcp.Tools.Monitor/tests/Azure.Mcp.Tools.Monitor.UnitTests/Metrics/MonitorMetricsServiceTests.cs | Updated tests to remove metrics client mocks, marked several tests to skip (require actual ARM client) |
| servers/Azure.Mcp.Server/CHANGELOG.md | Documented breaking change and migration to new SDK |
| core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs | Minor whitespace change |
Comments suppressed due to low confidence (1)
tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorMetricsService.cs:206
- This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.
foreach (var timeSeries in metric.Timeseries)
{
if (timeSeries.Data.Count == 0)
continue;
var compactTimeSeries = new MetricTimeSeries
{
Metadata = new Dictionary<string, string>(),
Start = timeSeries.Data.First().TimeStamp.UtcDateTime,
End = timeSeries.Data.Last().TimeStamp.UtcDateTime,
Interval = interval ?? "PT1M"
};
// Add metadata/dimensions
if (timeSeries.Metadatavalues != null)
{
foreach (var metadata in timeSeries.Metadatavalues)
{
if (metadata.Name?.Value != null && metadata.Value != null)
{
compactTimeSeries.Metadata[metadata.Name.Value] = metadata.Value;
}
}
}
// Extract values into arrays, only including non-null arrays
var avgValues = timeSeries.Data
.Where(v => v.Average.HasValue)
.Select(v => v.Average!.Value)
.ToArray();
if (avgValues.Length > 0)
compactTimeSeries.AvgBuckets = avgValues;
var minValues = timeSeries.Data
.Where(v => v.Minimum.HasValue)
.Select(v => v.Minimum!.Value)
.ToArray();
if (minValues.Length > 0)
compactTimeSeries.MinBuckets = minValues;
var maxValues = timeSeries.Data
.Where(v => v.Maximum.HasValue)
.Select(v => v.Maximum!.Value)
.ToArray();
if (maxValues.Length > 0)
compactTimeSeries.MaxBuckets = maxValues;
var totalValues = timeSeries.Data
.Where(v => v.Total.HasValue)
.Select(v => v.Total!.Value)
.ToArray();
if (totalValues.Length > 0)
compactTimeSeries.TotalBuckets = totalValues;
var countValues = timeSeries.Data
.Where(v => v.Count.HasValue)
.Select(v => v.Count!.Value)
.ToArray();
if (countValues.Length > 0)
compactTimeSeries.CountBuckets = countValues;
compactResult.TimeSeries.Add(compactTimeSeries);
}
What does this PR do?
[Provide a clear, concise description of the changes]This pull request refactors the metrics querying implementation in the monitoring tool to use the newer Azure Resource Manager (ARM) Monitor SDK instead of the deprecated
Azure.Monitor.QuerySDK. The main changes involve updating service registrations, removing the legacy metrics client service, and rewriting metric-related logic to use the new ARM Monitor APIs. This improves maintainability and aligns the codebase with current Azure SDK recommendations.Migration to Azure Resource Manager Monitor SDK
Azure.Monitor.Queryand related models withAzure.ResourceManager.Monitorand its models throughoutMonitorMetricsService, including metric querying, definitions, and namespaces logic. [1] [2] [3] [4] [5] [6] [7]Service and Dependency Updates
IMetricsQueryClientServiceinterface and its implementation (MetricsQueryClientService); updated DI registration and all service usages to rely on ARM Monitor SDK instead. [1] [2] [3]Project and Package Reference Changes
Azure.Monitor.QueryNuGet package reference and addedAzure.ResourceManager.Monitorto both the solution-wide packages and the monitoring tool project file. [1] [2] [3]Testing and Code Clean-up
These changes modernize the metrics querying subsystem and ensure future compatibility with Azure SDKs.
GitHub issue number?
#1272
Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationeng/scripts/Process-PackageReadMe.ps1. See Package README/servers/Azure.Mcp.Server/docs/azmcp-commands.mdand/or/docs/fabric-commands.md.\eng\scripts\Update-AzCommandsMetadata.ps1to update tool metadata in azmcp-commands.md (required for CI)ToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.json/servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline