Please help me to understand why from last few days Azure Microsoft Insights API 2016-09-01 is giving the following error{
"code": "BadRequest",
"message": "only conditions of the form '<name> eq <value>' are allowed, where <name> = 'timeGrain', 'startTime', 'endTime', 'name.value', 'aggregationType', 'debugRegion' : ( name.value eq 'Disk Write Bytes' ) and timeGrain eq duration'PT5M' and startTime eq 2017-10-25T13:27:49.620 0000 and endTime eq 2017-10-25T13:32:49.620 0000 "
}
few days back it was working fine Old working URL---> https://management.azure.com/subscriptions/452529bb-083b-411a-a5c2-30c735222/resourceGroups/Preprod2-Resource-Group/providers/Microsoft.Compute/virtualMachines/mw-mcs-test3/providers/microsoft.insights/metrics?api-version=2016-09-01&$filter=%28+name.value+eq+%27Disk+Write+Operations%2FSec%27+or++name.value+eq+%27Percentage+CPU%27+or++name.value+eq+%27Network+In%27+or++name.value+eq+%27Network+Out%27+or++name.value+eq+%27Disk+Read+Operations%2FSec%27+or++name.value+eq+%27Disk+Read+Bytes%27+or++name.value+eq+%27Disk+Write+Bytes%27++%29+and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-05-26T10%3A52%3A28.475%2B0000+and+endTime+eq+2017-05-26T10%3A57%3A28.476%2B0000+
New not working URL--->https://management.azure.com/subscriptions/452529bb-083b-411a-a5c2-30c735222/resourceGroups/MWatchLab-dev-kafka-bridge-oldcore-357248/providers/Microsoft.Compute/virtualMachines/dev-kafka-bridge-oldcore/providers/microsoft.insights/metrics?api-version=2016-09-01&$filter=%28+name.value+eq+%27Disk+Write+Operations%2FSec%27+or++name.value+eq+%27Percentage+CPU%27+or++name.value+eq+%27Network+In%27+or++name.value+eq+%27Network+Out%27+or++name.value+eq+%27Disk+Read+Operations%2FSec%27+or++name.value+eq+%27Disk+Read+Bytes%27+or++name.value+eq+%27Disk+Write+Bytes%27++%29+and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-10-26T05%3A28%3A34.919%2B0000+and+endTime+eq+2017-10-26T05%3A33%3A34.919%2B0000+
Please help me fix this its is causing huge issues in my production environment.
I can repro the issue when there is no "()" for the metrics names.
I assume that you mentioned not working URL is not corresponding your error info. As you mentioned 2 URL just resource group and virtual machine name are not the same exclude start time and end time. Please have a try to use the following URL to test it again. it works correctly on my side.
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourcegroup}/providers/Microsoft.Compute/virtualMachines/{machineName}/providers/microsoft.insights/metrics?$filter=(%20name.value%20eq%20'Disk%20Write%20Operations/Sec'%20or%20%20name.value%20eq%20'Percentage%20CPU'%20or%20%20name.value%20eq%20'Network%20In'%20or%20%20name.value%20eq%20'Network%20Out'%20or%20%20name.value%20eq%20'Disk%20Read%20Operations/Sec'%20or%20%20name.value%20eq%20'Disk%20Read%20Bytes'%20or%20%20name.value%20eq%20'Disk%20Write%20Bytes'%20%20)%20and%20timeGrain%20eq%20duration'PT5M'%20and%20startTime%20eq%202017-10-26T05:28:34.919Z%20and%20endTime%20eq%202017-10-26T05:33:34.919&api-version=2016-09-01
If use C# SDK is acceptable, we could use Microsoft.Azure.Management.Monitor.Fluent to that, following is my demo code, it works correctly on my side.
var azureTenantId = "tenant id";
var azureSecretKey = "secret key";
var azureAppId = "client id";
var subscriptionId = "subscription id";
var resourceGroup = "resource group";
var machineName = "machine name";
var serviceCreds = ApplicationTokenProvider.LoginSilentAsync(azureTenantId, azureAppId, azureSecretKey).Result;
MonitorClient monitorClient = new MonitorClient(serviceCreds) { SubscriptionId = subscriptionId };
var resourceUrl = $"subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{machineName}";
var metricNames = "(name.value eq 'Disk Write Operations/Sec' or name.value eq 'Percentage CPU' or name.value eq 'Network In' or name.value eq 'Network Out' or name.value eq 'Disk Read Operations/Sec' or name.value eq 'Disk Read Bytes' or name.value eq 'Disk Write Bytes')";
string timeGrain = " and timeGrain eq duration'PT5M'";
string startDate = " and startTime eq 2017-10-26T05:28:34.919Z";
string endDate = " and endTime eq 2017-10-26T05:33:34.919Z";
var odataFilterMetrics = new ODataQuery<MetricInner>(
$"{metricNames}{timeGrain}{startDate}{endDate}");
var metrics = monitorClient.Metrics.ListWithHttpMessagesAsync(resourceUrl, odataFilterMetrics).Result;
The issue was earlier +and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-05-26T10%3A52%3A28.475%2B0000+and+endTime+eq+2017-05-26T10%3A57%3A28.476%2B0000+
was supported (i.e in java i was using SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")) but i dono nowadays they have removed %2B0000 so only this will work +and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-05-26T10%3A52%3A28.475+and+endTime+eq+2017-05-26T10%3A57%3A28.476
(so now i have changed to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"))