MCPcopy Index your code
hub / github.com/coder/coder / NewGithub

Method NewGithub

coderd/promoauth/oauth2.go:162–194  ·  view source on GitHub ↗

NewGithub returns a new instrumented oauth2 config for github. It tracks rate limits as well as just the external request counts. nolint:bodyclose

(name string, under OAuth2Config)

Source from the content-addressed store, hash-verified

160//
161//nolint:bodyclose
162func (f *Factory) NewGithub(name string, under OAuth2Config) *Config {
163 cfg := f.New(name, under)
164 cfg.interceptors = append(cfg.interceptors, func(resp *http.Response, err error) {
165 limits, ok := githubRateLimits(resp, err)
166 if !ok {
167 return
168 }
169 labels := prometheus.Labels{
170 "name": cfg.name,
171 "resource": limits.Resource,
172 }
173 // Default to -1 for "do not know"
174 resetIn := float64(-1)
175 if !limits.Reset.IsZero() {
176 now := time.Now()
177 if f.Now != nil {
178 now = f.Now()
179 }
180 resetIn = limits.Reset.Sub(now).Seconds()
181 if resetIn < 0 {
182 // If it just reset, just make it 0.
183 resetIn = 0
184 }
185 }
186
187 f.metrics.rateLimit.With(labels).Set(float64(limits.Limit))
188 f.metrics.rateLimitRemaining.With(labels).Set(float64(limits.Remaining))
189 f.metrics.rateLimitUsed.With(labels).Set(float64(limits.Used))
190 f.metrics.rateLimitReset.With(labels).Set(float64(limits.Reset.Unix()))
191 f.metrics.rateLimitResetIn.With(labels).Set(resetIn)
192 })
193 return cfg
194}
195
196type Config struct {
197 // Name is a human friendly name to identify the oauth2 provider. This should be

Callers 4

TestGithubRateLimitsFunction · 0.95
TestUserOAuth2GithubFunction · 0.80
ConvertConfigFunction · 0.80
configureGithubOAuth2Function · 0.80

Calls 4

NewMethod · 0.95
githubRateLimitsFunction · 0.85
SetMethod · 0.65
IsZeroMethod · 0.45

Tested by 2

TestGithubRateLimitsFunction · 0.76
TestUserOAuth2GithubFunction · 0.64