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

Add gateway request latency Prometheus metric. #429

Merged
merged 30 commits into from
May 30, 2020

Conversation

MichaelRybak
Copy link
Contributor

Another metric per request #357.

)

func (this *Signer) fetchURLAndMeasure(fetch *url.URL, serveHTTPReq *http.Request) (*http.Request, *http.Response, *util.HTTPError) {
now := time.Now()
Copy link
Collaborator

Choose a reason for hiding this comment

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

you might want to stub out 'now' so it's easier to inject your own now in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot, this is a very cool idea! I didn't do this for top level
requests because latencies are measured by a third-party (Prometheus :),
but it can be done here.

Done.

@MichaelRybak
Copy link
Contributor Author

MichaelRybak commented May 28, 2020 via email

@@ -142,14 +143,14 @@ func noRedirects(req *http.Request, via []*http.Request) error {

func New(certHandler certcache.CertHandler, key crypto.PrivateKey, urlSets []util.URLSet,
rtvCache *rtv.RTVCache, shouldPackage func() error, overrideBaseURL *url.URL,
requireHeaders bool, forwardedRequestHeaders []string) (*Signer, error) {
requireHeaders bool, forwardedRequestHeaders []string, timeNowFunc func() time.Time) (*Signer, error) {
Copy link
Member

Choose a reason for hiding this comment

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

The list of constructor args is getting pretty long. We should (passively) start thinking of ways to split up responsibility of this class. I don't have any ideas; this is just me creating entropy. :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG!

@@ -134,6 +134,7 @@ type Signer struct {
overrideBaseURL *url.URL
requireHeaders bool
forwardedRequestHeaders []string
timeNowFunc func() time.Time
Copy link
Member

Choose a reason for hiding this comment

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

(opt) Maybe remove "Func" from the name? It's kind of implied, as a non-func Time couldn't be "now".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@MichaelRybak MichaelRybak merged commit a974227 into ampproject:master May 30, 2020
@MichaelRybak MichaelRybak deleted the flat branch June 1, 2020 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants