(core github.Rate)
| 578 | } |
| 579 | |
| 580 | func (g *githubClient) recordLimits(core github.Rate) { |
| 581 | limit := params.GithubRateLimit{ |
| 582 | Limit: core.Limit, |
| 583 | Used: core.Used, |
| 584 | Remaining: core.Remaining, |
| 585 | Reset: core.Reset.Unix(), |
| 586 | } |
| 587 | cache.SetCredentialsRateLimit(g.entity.Credentials.ID, limit) |
| 588 | |
| 589 | // Record Prometheus metrics |
| 590 | credID := fmt.Sprintf("%d", g.entity.Credentials.ID) |
| 591 | credName := g.entity.Credentials.Name |
| 592 | endpoint := g.entity.Credentials.Endpoint.Name |
| 593 | if endpoint == "" { |
| 594 | endpoint = g.entity.Credentials.BaseURL |
| 595 | } |
| 596 | |
| 597 | labels := map[string]string{ |
| 598 | "credential_name": credName, |
| 599 | "credential_id": credID, |
| 600 | "endpoint": endpoint, |
| 601 | } |
| 602 | |
| 603 | metrics.GithubRateLimitLimit.With(labels).Set(float64(core.Limit)) |
| 604 | metrics.GithubRateLimitRemaining.With(labels).Set(float64(core.Remaining)) |
| 605 | metrics.GithubRateLimitUsed.With(labels).Set(float64(core.Used)) |
| 606 | metrics.GithubRateLimitResetTimestamp.With(labels).Set(float64(core.Reset.Unix())) |
| 607 | } |
| 608 | |
| 609 | func NewRateLimitClient(ctx context.Context, credentials params.ForgeCredentials) (common.RateLimitClient, error) { |
| 610 | httpClient, err := credentials.GetHTTPClient(ctx) |
no test coverage detected