到目前为止,我成功使用 Application Insights REST API 来获取带有 X-Api-Key header 的指标。 https://api.applicationinsights.io/beta/apps/xxxxxxxxxx/metrics/customMetrics%2FmetricName?timespan=PT2H&interval=PT20M&aggregation=min
但是,通过我们的新仪表板抓取多个指标,我们严重达到了 1500 个请求/API key 限制。
有些人建议尝试使用多个 api key ,但我想阻止这种方法。
根据文档,使用 AAD 进行身份验证将删除每日上限 ( https://dev.applicationinsights.io/documentation/Authorization/Rate-limits )
但是我无法使用AAD进行身份验证(在nodejs中,但我怀疑它在任何语言中都是相同的)
我在一个简单的应用程序中使用了adal-node
,我成功获得了一个 token ,但是我无法将其转发到Request
var context = new AuthenticationContext(authorityUrl);
context.acquireTokenWithClientCredentials(resource, clientId, clientSecret, function(err, tokenResponse) {
if (err) {
console.log('well that didn\'t work: ' + err.stack);
} else {
console.log(tokenResponse);
request({'url' : 'https://api.applicationinsights.io/beta/apps/xxxxxxxxx/metrics/customMetrics%2Fmetrics?timespan=PT2H&interval=PT20M&aggregation=min',
headers: {
'Authorization': 'Bearer ' + tokenResponse.accessToken
}
}, function (error,response,body){
console.log(body);
});
}
});
我收到以下错误消息
提供的身份验证对此资源无效
给定的 API key 对于请求的资源无效
我怀疑我错过了什么:)
最佳答案
我们的 REST API 不直接支持 AAD。您的资源由 Azure 资源管理器管理,并且只有它才能验证特定用户是否有权访问该资源。 API key 是我们直接将授权短路到资源的方法,而不是在用户上下文中。
您以您自己的身份授予此 AAD 应用对此资源的访问权限,因此身份验证仍在用户上下文中进行。必须改为调用 ARM:' https://management.azure.com/subscriptions/xxxxxx/resourcegroups/xxxxx/providers/microsoft.insights/components/xxxxx/api/metrics/customMetrics%2Fmetrics?api-version=2014-12-01-preview×pan=PT2H&interval=PT20M&aggregation=min '
文档链接至此处 - 尽管未明确解释:https://dev.applicationinsights.io/documentation/Authorization
这将为您带来更高的速率限制,并且仍然返回与 REST API 相同的响应。
关于rest - 使用 AAD 在 Application Insights REST API 上进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978366/