Skip to content

Commit 922907a

Browse files
authored
feat(github)!: HTTP metrics for outbound requests (#1210)
We currently don't track requests to GitHub from the SDK. This starts to track them. Introduces possibility of double-counting outgoing HTTP requests in the case where users also override `http.DefaultTransport` Sort of related to #1208
1 parent 3c77103 commit 922907a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

modules/github-bots/sdk/github.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"chainguard.dev/sdk/octosts"
2626
"github.com/chainguard-dev/clog"
27+
"github.com/chainguard-dev/terraform-infra-common/pkg/httpmetrics"
2728
"github.com/google/go-github/v75/github"
2829
"golang.org/x/oauth2"
2930
)
@@ -40,8 +41,10 @@ func NewGitHubClient(ctx context.Context, org, repo, policyName string, opts ...
4041
policyName: policyName,
4142
})
4243

44+
httpClient := oauth2.NewClient(ctx, ts)
45+
httpClient.Transport = httpmetrics.WrapTransport(httpClient.Transport)
4346
client := GitHubClient{
44-
inner: github.NewClient(oauth2.NewClient(ctx, ts)),
47+
inner: github.NewClient(httpClient),
4548
ts: ts,
4649
bufSize: 1024 * 1024, // 1MB buffer for requests
4750
org: org,
@@ -81,7 +84,7 @@ func NewInstallationClient(ctx context.Context, org, repo string, tr *ghinstalla
8184
transport: tr,
8285
})
8386
client := GitHubClient{
84-
inner: github.NewClient(&http.Client{Transport: tr}),
87+
inner: github.NewClient(&http.Client{Transport: httpmetrics.WrapTransport(tr)}),
8588
ts: ts,
8689
bufSize: 1024 * 1024, // 1MB buffer for requests
8790
org: org,

0 commit comments

Comments
 (0)