-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools for PR 9354 (#23714)
* Add step for emitting rate limits for a token * add step to eng/common sync template * Fix resource label output * Use propery name instead of nested 'resource' property * Add percent metric too * Add divide by zero safety --------- Co-authored-by: Patrick Hallisey <[email protected]>
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
eng/common/pipelines/templates/steps/emit-rate-limit-metrics.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
parameters: | ||
- name: GitHubUser | ||
type: string | ||
- name: GitHubToken | ||
type: string | ||
|
||
steps: | ||
- pwsh: | | ||
$headers = @{ | ||
"Authorization" = "Bearer $env:GITHUB_TOKEN" | ||
"X-GitHub-Api-Version" = "2022-11-28" | ||
} | ||
$response = Invoke-RestMethod -Uri 'https://api.github.com/rate_limit' -Headers $headers -Method Get | ||
$timestamp = Get-Date | ||
foreach ($property in $response.resources.PSObject.Properties) | ||
{ | ||
$labels = @{ user= $env:GITHUB_USER; resource= $property.Name } | ||
$remaining = $property.Value.remaining | ||
$limit = $property.Value.limit | ||
$used = $property.Value.used | ||
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_remaining_total"; value= $remaining; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)" | ||
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_limit_total"; value= $limit; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)" | ||
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_used_total"; value= $used; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)" | ||
if ($limit -ne 0) { | ||
$percent = $used / $limit * 100 | ||
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_used_percent"; value= $percent; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)" | ||
} | ||
} | ||
displayName: Check GitHub Rate Limit | ||
env: | ||
GITHUB_TOKEN: ${{ parameters.GitHubToken}} | ||
GITHUB_USER: ${{ parameters.GitHubUser}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters