@@ -21,18 +21,19 @@ type OAuth2Config interface {
21
21
// InstrumentedOAuth2Config extends OAuth2Config with a `Do` method that allows
22
22
// external oauth related calls to be instrumented. This is to support
23
23
// "ValidateToken" which is not an oauth2 specified method.
24
+ // These calls still count against the api rate limit, and should be instrumented.
24
25
type InstrumentedOAuth2Config interface {
25
26
OAuth2Config
26
27
27
28
// Do is provided as a convenience method to make a request with the oauth2 client.
28
29
// It mirrors `http.Client.Do`.
29
- // We need this because Coder adds some extra functionality to
30
- // oauth clients such as the `ValidateToken()` method.
31
30
Do (ctx context.Context , source string , req * http.Request ) (* http.Response , error )
32
31
}
33
32
34
33
var _ OAuth2Config = (* Config )(nil )
35
34
35
+ // Factory allows us to have 1 set of metrics for all oauth2 providers.
36
+ // Primarily to avoid any prometheus errors registering duplicate metrics.
36
37
type Factory struct {
37
38
metrics * metrics
38
39
}
@@ -107,10 +108,11 @@ func (c *Config) wrapClient(ctx context.Context, source string) context.Context
107
108
return context .WithValue (ctx , oauth2 .HTTPClient , c .oauthHTTPClient (ctx , source ))
108
109
}
109
110
111
+ // oauthHTTPClient returns an http client that will instrument every request made.
110
112
func (c * Config ) oauthHTTPClient (ctx context.Context , source string ) * http.Client {
111
113
cli := & http.Client {}
112
114
113
- // Check if the context has an http client already.
115
+ // Check if the context has a http client already.
114
116
if hc , ok := ctx .Value (oauth2 .HTTPClient ).(* http.Client ); ok {
115
117
cli = hc
116
118
}
@@ -126,6 +128,8 @@ type instrumentedTripper struct {
126
128
underlying http.RoundTripper
127
129
}
128
130
131
+ // newInstrumentedTripper intercepts a http request, and increments the
132
+ // externalRequestCount metric.
129
133
func newInstrumentedTripper (c * Config , source string , under http.RoundTripper ) * instrumentedTripper {
130
134
if under == nil {
131
135
under = http .DefaultTransport
0 commit comments