Skip to content

Commit

Permalink
Merge pull request #15320 from stevekuznetsov/skuznets/github-user-agent
Browse files Browse the repository at this point in the history
Add a version package, populate it and use it
  • Loading branch information
k8s-ci-robot authored Nov 21, 2019
2 parents 9c4352d + 3fa95fc commit 55b023d
Show file tree
Hide file tree
Showing 40 changed files with 94 additions and 45 deletions.
2 changes: 1 addition & 1 deletion boskos/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func init() {
}

func main() {
logrusutil.ComponentInit("boskos-metrics")
logrusutil.ComponentInit()
boskos := client.NewClient("Metrics", "http://boskos")
logrus.Infof("Initialzied boskos client!")

Expand Down
2 changes: 1 addition & 1 deletion experiment/resultstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func parseOptions() options {
}

func main() {
logrusutil.ComponentInit("storeship")
logrusutil.ComponentInit()

opt := parseOptions()
for {
Expand Down
2 changes: 1 addition & 1 deletion experiment/tracer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func gatherOptions() options {
}

func main() {
logrusutil.ComponentInit("tracer")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ghproxy/ghproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func flagOptions() *options {
}

func main() {
logrusutil.ComponentInit("ghproxy")
logrusutil.ComponentInit()

o := flagOptions()
flag.Parse()
Expand Down
2 changes: 1 addition & 1 deletion greenhouse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var diskCheckInterval = flag.Duration("disk-check-interval", time.Second*10,
var promMetrics *prometheusMetrics

func init() {
logrusutil.ComponentInit("greenhouse")
logrusutil.ComponentInit()

logrus.SetOutput(os.Stdout)
promMetrics = initMetrics()
Expand Down
2 changes: 1 addition & 1 deletion label_sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func newClient(tokenPath string, tokens, tokenBurst int, dryRun bool, graphqlEnd
// It took about 10 minutes to process all my 8 repos with all wanted "kubernetes" labels (70+)
// Next run takes about 22 seconds to check if all labels are correct on all repos
func main() {
logrusutil.ComponentInit("label_sync")
logrusutil.ComponentInit()

flag.Parse()
if *debug {
Expand Down
2 changes: 1 addition & 1 deletion maintenance/migratestatus/migratestatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (o *options) Validate() error {
}

func main() {
logrusutil.ComponentInit("migratestatus")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions prow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ filegroup(
"//prow/statusreconciler:all-srcs",
"//prow/test:all-srcs",
"//prow/tide:all-srcs",
"//prow/version:all-srcs",
],
tags = ["automanaged"],
)
2 changes: 1 addition & 1 deletion prow/cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (o *options) parse(flags *flag.FlagSet, args []string) error {
}

func main() {
logrusutil.ComponentInit("admission")
logrusutil.ComponentInit()

o := parseOptions()

Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/artifact-uploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (o *Options) Run() error {
}

func main() {
logrusutil.ComponentInit("artifact-uploader")
logrusutil.ComponentInit()

o := newOptions()
if err := options.Load(o); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/branchprotector/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (e *Errors) add(err error) {
}

func main() {
logrusutil.ComponentInit("branchprotector")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/checkconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (o *options) gatherOptions(flag *flag.FlagSet, args []string) error {
}

func main() {
logrusutil.ComponentInit("checkconfig")
logrusutil.ComponentInit()

o, err := parseOptions()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/clonerefs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func main() {
logrusutil.ComponentInit("clonerefs")
logrusutil.ComponentInit()

o := &clonerefs.Options{}
if err := options.Load(o); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/config-bootstrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (o *options) Validate() error {

func main() {
var errors int
logrusutil.ComponentInit("config-bootstrapper")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/crier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func parseOptions() options {
}

func main() {
logrusutil.ComponentInit("crier")
logrusutil.ComponentInit()

o := parseOptions()

Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/deck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func v(fragment string, children ...simplifypath.Node) simplifypath.Node {
}

func main() {
logrusutil.ComponentInit("deck")
logrusutil.ComponentInit()

o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func main() {
logrusutil.ComponentInit("entrypoint")
logrusutil.ComponentInit()

o := entrypoint.NewOptions()
if err := options.Load(o); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func mustRegister(component string, lister lister) *prometheus.Registry {
}

func main() {
logrusutil.ComponentInit("exporter")
logrusutil.ComponentInit()
o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
logrus.WithError(err).Fatal("Invalid options")
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/gcsupload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func main() {
logrusutil.ComponentInit("gcsupload")
logrusutil.ComponentInit()

o := gcsupload.NewOptions()
if err := options.Load(o); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/gerrit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (st *syncTime) Update(newState client.LastSyncState) error {
}

func main() {
logrusutil.ComponentInit("gerrit")
logrusutil.ComponentInit()

defer interrupts.WaitForGracefulShutdown()

Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/hook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func gatherOptions(fs *flag.FlagSet, args ...string) options {
}

func main() {
logrusutil.ComponentInit("hook")
logrusutil.ComponentInit()

o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/horologium/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (o *options) Validate() error {
}

func main() {
logrusutil.ComponentInit("horologium")
logrusutil.ComponentInit()

o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/initupload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func main() {
logrusutil.ComponentInit("initupload")
logrusutil.ComponentInit()

o := initupload.NewOptions()
if err := options.Load(o); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/jenkins-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func gatherOptions() options {
}

func main() {
logrusutil.ComponentInit("jenkins-operator")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/peribolos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (o *options) parseArgs(flags *flag.FlagSet, args []string) error {
}

func main() {
logrusutil.ComponentInit("peribolos")
logrusutil.ComponentInit()

o := parseOptions()

Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/pipeline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func newPipelineConfig(cfg rest.Config, stop <-chan struct{}) (*pipelineConfig,
}

func main() {
logrusutil.ComponentInit("pipeline")
logrusutil.ComponentInit()

o := parseOptions()

Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/plank/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (o *options) Validate() error {
}

func main() {
logrusutil.ComponentInit("plank")
logrusutil.ComponentInit()

o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func main() {
logrusutil.ComponentInit("sidecar")
logrusutil.ComponentInit()

o := sidecar.NewOptions()
if err := options.Load(o); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/sinker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (o *options) Validate() error {
}

func main() {
logrusutil.ComponentInit("sinker")
logrusutil.ComponentInit()

o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/status-reconciler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (o *options) Validate() error {
}

func main() {
logrusutil.ComponentInit("status-reconciler")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/sub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func init() {
}

func main() {
logrusutil.ComponentInit("pubsub-subscriber")
logrusutil.ComponentInit()

configAgent := &config.Agent{}
if err := configAgent.Start(flagOptions.configPath, flagOptions.jobConfigPath); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/tide/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func gatherOptions(fs *flag.FlagSet, args ...string) options {
}

func main() {
logrusutil.ComponentInit("tide")
logrusutil.ComponentInit()

defer interrupts.WaitForGracefulShutdown()

Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/tot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (f fallbackHandler) getURL(jobName string) string {
}

func main() {
logrusutil.ComponentInit("tot")
logrusutil.ComponentInit()

o := gatherOptions()
if err := o.Validate(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions prow/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def prow_image(
goarch = "amd64",
goos = "linux",
pure = "on",
x_defs = {"k8s.io/test-infra/prow/version.Name": name},
)

container_image(
Expand Down
1 change: 1 addition & 0 deletions prow/github/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ go_library(
deps = [
"//ghproxy/ghcache:go_default_library",
"//prow/errorutil:go_default_library",
"//prow/version:go_default_library",
"@com_github_shurcool_githubv4//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@org_golang_x_oauth2//:go_default_library",
Expand Down
28 changes: 18 additions & 10 deletions prow/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ import (
githubql "github.com/shurcooL/githubv4"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2"

"k8s.io/test-infra/ghproxy/ghcache"
"k8s.io/test-infra/prow/errorutil"
"k8s.io/test-infra/prow/version"
)

type timeClient interface {
Expand Down Expand Up @@ -247,14 +249,15 @@ type delegate struct {
maxSleepTime time.Duration
initialDelay time.Duration

gqlc gqlClient
client httpClient
bases []string
dry bool
fake bool
throttle throttler
getToken func() []byte
censor func([]byte) []byte
userAgent string
gqlc gqlClient
client httpClient
bases []string
dry bool
fake bool
throttle throttler
getToken func() []byte
censor func([]byte) []byte

mut sync.Mutex // protects botName and email
userData *User
Expand Down Expand Up @@ -434,7 +437,8 @@ func NewClientWithFields(fields logrus.Fields, getToken func() []byte, censor fu
return &client{
logger: logrus.WithFields(fields).WithField("client", "github"),
delegate: &delegate{
time: &standardTime{},
time: &standardTime{},
userAgent: version.UserAgent(),
gqlc: githubql.NewEnterpriseClient(
graphqlEndpoint,
&http.Client{
Expand Down Expand Up @@ -471,7 +475,8 @@ func NewDryRunClientWithFields(fields logrus.Fields, getToken func() []byte, cen
return &client{
logger: logrus.WithFields(fields).WithField("client", "github"),
delegate: &delegate{
time: &standardTime{},
time: &standardTime{},
userAgent: version.UserAgent(),
gqlc: githubql.NewEnterpriseClient(
graphqlEndpoint,
&http.Client{
Expand Down Expand Up @@ -737,6 +742,9 @@ func (c *client) doRequest(method, path, accept string, body interface{}) (*http
} else {
req.Header.Add("Accept", accept)
}
if c.userAgent != "" {
req.Header.Add("User-Agent", c.userAgent)
}
// Disable keep-alive so that we don't get flakes when GitHub closes the
// connection prematurely.
// https://go-review.googlesource.com/#/c/3210/ fixed it for GET, but not
Expand Down
1 change: 1 addition & 0 deletions prow/logrusutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "k8s.io/test-infra/prow/logrusutil",
visibility = ["//visibility:public"],
deps = [
"//prow/version:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_k8s_apimachinery//pkg/util/sets:go_default_library",
],
Expand Down
Loading

0 comments on commit 55b023d

Please sign in to comment.