-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add step for emitting rate limits for a token
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
eng/common/pipelines/templates/steps/emit-ratelimit-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,25 @@ | ||
parameters: | ||
- name: User | ||
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.Value) | ||
{ | ||
Write-Host "logmetric: $( @{ name= "github_rate_limit_remaining_total"; value= $property.remaining; timestamp= $timestamp; labels= @{ user=$env:GITHUB_USER; resource=$property.resource }} | ConvertTo-Json -Compress)" | ||
Write-Host "logmetric: $( @{ name= "github_rate_limit_limit_total"; value= $property.limit; timestamp= $timestamp; labels= @{ user=$env:GITHUB_USER; resource=$property.resource }} | ConvertTo-Json -Compress)" | ||
Write-Host "logmetric: $( @{ name= "github_rate_limit_used_total"; value= $property.used; timestamp= $timestamp; labels= @{ user=$env:GITHUB_USER; resource=$property.resource }} | ConvertTo-Json -Compress)" | ||
} | ||
displayName: Check GitHub Rate Limit | ||
env: | ||
GITHUB_TOKEN: ${{ parameters.GitHubToken}} | ||
GITHUB_USER: ${{ parameters.User}} |
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