Documentation
¶
Overview ¶
Package ghinstall provides a Manager abstraction for looking up GitHub App installations by owner. It encapsulates an LRU cache of installation IDs and handles paginated listing of installations via the GitHub API.
Construct a Manager with New and inject it into consumers that need to resolve an owner name to a GitHub App installation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager interface {
// Get returns the transport and installation ID for the given owner.
// For multi-app managers (e.g. roundRobin), scope and identity inform
// routing decisions such as capacity-aware selection. Single-app
// managers ignore them.
Get(ctx context.Context, owner, scope, identity string) (*ghinstallation.AppsTransport, int64, error)
// GetByInstallation returns the transport for a specific installation ID
// if it belongs to the given owner. Used by the sticky store to retrieve
// a previously-persisted installation.
GetByInstallation(ctx context.Context, owner string, installationID int64) (*ghinstallation.AppsTransport, int64, error)
}
Manager looks up GitHub App installations by owner. scope and identity are used by multi-app implementations for routing; single-app implementations may ignore them.
func New ¶
func New(atr *ghinstallation.AppsTransport) (Manager, error)
New creates a Manager backed by the given AppsTransport.
func NewRoundRobin ¶
NewRoundRobin creates a Manager that distributes requests across the given managers using an atomic round-robin counter.
func NewRoundRobinWithQuota ¶ added in v0.7.0
func NewRoundRobinWithQuota(managers []Manager, q *QuotaConfig) Manager
NewRoundRobinWithQuota is NewRoundRobin with capacity-aware selection layered on top. When quota data is available, requests are routed via argmax(remaining) within the highest non-empty tier (comfortable, tight, or last-resort). When no candidate has quota data, the atomic counter is used.
func NewWithNegativeTTL ¶ added in v0.7.2
func NewWithNegativeTTL(atr *ghinstallation.AppsTransport, negativeTTL time.Duration) (Manager, error)
NewWithNegativeTTL creates a Manager with a configurable TTL for negative (not-installed) cache entries.
type QuotaConfig ¶ added in v0.7.0
type QuotaConfig struct {
// Store is the source of per-installation remaining-quota snapshots,
// populated by the ghtransport response tap. May be nil to disable
// quota-aware selection.
Store *QuotaStore
// SoftFloor: remaining < SoftFloor demotes an install out of the
// preferred pool. Heavy/sticky callers landing on the preferred pool
// always have at least SoftFloor headroom.
SoftFloor int
// HardFloor: remaining < HardFloor excludes an install entirely except
// when every install is below it ("last resort").
HardFloor int
}
QuotaConfig configures three-tier capacity-aware selection for the roundRobin manager.
type QuotaStore ¶ added in v0.7.0
type QuotaStore struct {
// contains filtered or unexported fields
}
QuotaStore tracks per-installation rate-limit state, populated by a transport-layer tap on GitHub responses (see pkg/ghtransport).
The store is a hint, not a source of truth: callers must tolerate missing or stale entries by falling back to capacity-blind selection. Entries older than the configured TTL are reported as missing.
func NewQuotaStore ¶ added in v0.7.0
func NewQuotaStore(ttl time.Duration) *QuotaStore
NewQuotaStore creates a quota store. Snapshots older than ttl are treated as missing.
func (*QuotaStore) Get ¶ added in v0.7.0
func (q *QuotaStore) Get(installID int64) (remaining, limit int, ok bool)
Get returns the most recent snapshot for installID. ok is false if no snapshot exists or if the snapshot is older than the configured TTL.
func (*QuotaStore) Update ¶ added in v0.7.0
func (q *QuotaStore) Update(installID int64, remaining, limit int)
Update records a fresh quota snapshot for installID.