Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: Monitor rate limit wait duration #17567

Merged
merged 7 commits into from
Jan 26, 2021
Merged

metrics: Monitor rate limit wait duration #17567

merged 7 commits into from
Jan 26, 2021

Conversation

ryanslade
Copy link
Contributor

@ryanslade ryanslade commented Jan 22, 2021

This change tracks the amount of time we spend waiting on code host rate
limits once they've been exceeded.

It uses header data tracked by our rate limit monitor and there only supports
GitLab and GitHub as these are the only hosts supported by our monitor.

Closes: #17200

@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #17567 (d1b7619) into main (c293f39) will increase coverage by 0.00%.
The diff coverage is 46.15%.

@@           Coverage Diff           @@
##             main   #17567   +/-   ##
=======================================
  Coverage   51.53%   51.54%           
=======================================
  Files        1717     1717           
  Lines       85381    85396   +15     
  Branches     7761     7765    +4     
=======================================
+ Hits        44005    44018   +13     
  Misses      37501    37501           
- Partials     3875     3877    +2     
Flag Coverage Δ
go 50.41% <46.15%> (+<0.01%) ⬆️
integration 30.72% <ø> (-0.02%) ⬇️
storybook 30.66% <ø> (+0.04%) ⬆️
typescript 54.26% <ø> (+0.01%) ⬆️
unit 34.59% <ø> (ø)
Impacted Files Coverage Δ
internal/extsvc/github/common.go 54.28% <ø> (ø)
internal/extsvc/github/v4.go 76.72% <0.00%> (ø)
internal/extsvc/github/version.go 52.94% <0.00%> (ø)
internal/ratelimit/monitor.go 63.63% <14.28%> (-3.49%) ⬇️
internal/repos/gitlab.go 72.97% <50.00%> (+0.02%) ⬆️
internal/repos/github.go 60.48% <70.00%> (+0.67%) ⬆️
internal/extsvc/github/v3.go 80.39% <100.00%> (ø)
client/web/src/settings/SettingsPage.tsx 64.70% <0.00%> (-11.77%) ⬇️
client/web/src/nav/StatusMessagesNavItem.tsx 85.96% <0.00%> (-1.76%) ⬇️
client/shared/src/search/query/providers.ts 62.06% <0.00%> (+20.68%) ⬆️

@ryanslade ryanslade requested a review from a team January 26, 2021 08:25

This panel indicates time spent waiting for the GitHub graphql API rate limiter.

Indicates how long we`re waiting on the rate limit once it has been exceeded`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you quote this on purpose? Or did you mean this:

Suggested change
Indicates how long we`re waiting on the rate limit once it has been exceeded`
Indicates how long we're waiting on the rate limit once it has been exceeded.

Copy link
Contributor Author

@ryanslade ryanslade Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, our doc generator seems to be doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated docs look fine in the browser though

@@ -50,6 +50,13 @@ func (r *MonitorRegistry) Count() int {
return len(r.monitors)
}

// MetricsCollector is used so that we can inject metric collection functions for
// difference monitor configurations.
type MetricsCollector struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use an interface instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because then each caller would have to define their own type to implement it which doesn't seem necessary.

@ryanslade ryanslade marked this pull request as ready for review January 26, 2021 08:40
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Jan 26, 2021

Notifying subscribers in CODENOTIFY files for diff c293f39...d1b7619.

Notify File(s)
@LawnGnome internal/extsvc/github/common.go
internal/extsvc/github/v3.go
internal/extsvc/github/v4.go
internal/extsvc/github/version.go
@bobheadxi monitoring/definitions/repo_updater.go
@christinaforney doc/admin/observability/dashboards.md
@eseliger internal/extsvc/github/common.go
internal/extsvc/github/v3.go
internal/extsvc/github/v4.go
internal/extsvc/github/version.go
@slimsag monitoring/definitions/repo_updater.go
@sourcegraph/distribution doc/admin/observability/dashboards.md
monitoring/definitions/repo_updater.go

@ryanslade ryanslade changed the title ratelimit metrics metrics: Monitor rate limit wait duration Jan 26, 2021
@ryanslade ryanslade merged commit 0b87765 into main Jan 26, 2021
@ryanslade ryanslade deleted the ratelimit-metrics branch January 26, 2021 09:18
Comment on lines +82 to +83
githubRatelimitWaitCounter.WithLabelValues("rest", "TESTNAME").Add((time.Millisecond * 100).Seconds())
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... looks like debugging lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks for spotting that!

githubRemainingGauge.WithLabelValues(resource, svc.DisplayName).Set(n)
},
WaitDuration: func(n time.Duration) {
githubRatelimitWaitCounter.WithLabelValues(resource, svc.DisplayName).Add(n.Seconds())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a ever-growing number on a Grafana panel making sense 🤔 (ignore if this is the purpose)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure, but agree that maybe we have too many. I'll leave it in for now since the metrics were specifically requested by @slimsag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve rate limit instrumentation
4 participants