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 http client metrics #543

Merged
merged 1 commit into from
Oct 3, 2024
Merged

add http client metrics #543

merged 1 commit into from
Oct 3, 2024

Conversation

lucix-aws
Copy link
Contributor

Final list of metrics:

Metric Name Unit Type Description Attributes (Dimensions)
client.http.connections.acquire_duration s Histogram The time it takes a request to acquire a connection
client.http.connections.dns_lookup_duration s Histogram The time it takes to do DNS lookup
client.http.connections.tls_handshake_duration s Histogram The time it takes to perform a TLS handshake
client.http.connections.usage {connection} UpDownCounter State of the connection pool state: idle/acquired***
client.http.do_request_duration s Histogram Total time spent in Do()
client.http.time_to_first_byte s Histogram Time from Do() to first response byte received

*** We are unable to determine the state of connections right now (more specifically, exactly when a connection is idle isn't known to us). We're adding the dimension of state=acquired for now in case that ever changes.

@lucix-aws lucix-aws requested review from a team as code owners October 2, 2024 20:02
return nil, err
}
hm.ConnectionUsage, err = meter.Int64UpDownCounter("client.http.connections.usage", func(o *metrics.InstrumentOptions) {
o.UnitLabel = "{connection}"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we name this connections?

also, probably outside the scope of this PR but this would be nice if it had been named client.http.connections.total or something like that, usage doesn't make it clear what kind of usage we're talking about (bandwidth, idle or active connections)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comes from the SRA list of suggested metrics (which I copied in here) - I would rather not deviate where naming has been established.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's what I was hinting with "outside the scope of this PR". I didn't know the unit was also described there, my bad.


func (m *httpMetrics) PutIdleConn(ctx context.Context) func(error) {
return func(error) {
m.addConnAcquired(ctx, -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we count a connection set as idle as "not acquired"? I'm curious how this plays with keep-alive connections

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 SRA defined this as having one dimension: state = idle | acquired - acquired meaning "in use right now" and idle meaning "not in use" - might have been better to say be active | acquired but again this comes from external recommended naming.

c.hm.doStart = now()
resp, err := c.ClientDo.Do(r)

c.hm.DoRequestDuration.Record(r.Context(), elapsed(c.hm.doStart))
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we keep track of which request is the one that just ended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow - this is all happening inside Do(), which is one request?

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, then disregard the comment

@lucix-aws lucix-aws merged commit 26886e2 into main Oct 3, 2024
11 checks passed
@lucix-aws lucix-aws deleted the feat-httpmetrics branch October 3, 2024 19:53
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.

2 participants