Skip to content

Commit

Permalink
Add step for emitting rate limits for a token
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr authored and azure-sdk committed Nov 7, 2024
1 parent fbbd758 commit 0a7fce2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions eng/common/pipelines/templates/steps/emit-ratelimit-metrics.yml
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}}
5 changes: 5 additions & 0 deletions eng/common/pipelines/templates/steps/git-push-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ steps:
condition: succeeded()
workingDirectory: ${{ parameters.WorkingDirectory }}

- template: ./emit-ratelimit-metrics.yml
parameters:
User: 'azure-sdk'
GitHubToken: $(azuresdk-github-pat)

- task: PowerShell@2
displayName: Push changes
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
Expand Down

0 comments on commit 0a7fce2

Please sign in to comment.