From 516695b275f8c08b1e872000e76c51f17babe68d Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Sun, 27 Feb 2022 19:17:58 -0500 Subject: [PATCH] Set UserAgent to 'actions-runner-controller' for all Http Client. (#1140) I can't find any requests made by user agent `actions-runner-controller` in GitHub.com's telemetry in the past 7 days. Turns out we only set user agent `actions-runner-controller` if we are configured to use BasicAuth which is not the case for most customers I think. I update the code a little bit to make sure it always set `actions-runner-controller` as UserAgent for the GitHub HttpClient in ARC. A further step would be somehow baking the ARC release version into the UserAgent as well. --- github/github.go | 3 ++- github/github_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/github/github.go b/github/github.go index d8d0acf6..6def3f50 100644 --- a/github/github.go +++ b/github/github.go @@ -51,7 +51,6 @@ type BasicAuthTransport struct { func (p BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { req.SetBasicAuth(p.Username, p.Password) - req.Header.Set("User-Agent", "actions-runner-controller") return http.DefaultTransport.RoundTrip(req) } @@ -136,6 +135,8 @@ func (c *Config) NewClient() (*Client, error) { } } + client.UserAgent = "actions-runner-controller" + return &Client{ Client: client, regTokens: map[string]*github.RegistrationToken{}, diff --git a/github/github_test.go b/github/github_test.go index 92383a19..f7c11f62 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -152,3 +152,10 @@ func TestCleanup(t *testing.T) { t.Errorf("expired token still exists") } } + +func TestUserAgent(t *testing.T) { + client := newTestClient() + if client.UserAgent != "actions-runner-controller" { + t.Errorf("UserAgent should be set to actions-runner-controller") + } +}