Bumps the aws-sdk-go-v2 group with 3 updates in the / directory: [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2), [github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue](https://github.com/aws/aws-sdk-go-v2) and [github.com/aws/aws-sdk-go-v2/service/kinesis](https://github.com/aws/aws-sdk-go-v2). Updates `github.com/aws/aws-sdk-go-v2/config` from 1.27.39 to 1.27.43 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.27.39...config/v1.27.43) Updates `github.com/aws/aws-sdk-go-v2/credentials` from 1.17.37 to 1.17.41 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.17.37...credentials/v1.17.41) Updates `github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue` from 1.15.8 to 1.15.12 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.15.8...config/v1.15.12) Updates `github.com/aws/aws-sdk-go-v2/service/dynamodb` from 1.35.3 to 1.36.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/iot/v1.35.3...service/iam/v1.36.2) Updates `github.com/aws/aws-sdk-go-v2/service/kinesis` from 1.29.8 to 1.32.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/sns/v1.29.8...v1.32.2) Updates `github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream` from 1.6.5 to 1.6.6 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.6.5...service/tnb/v1.6.6) Updates `github.com/aws/aws-sdk-go-v2/feature/ec2/imds` from 1.16.14 to 1.16.17 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.16.14...service/ram/v1.16.17) Updates `github.com/aws/aws-sdk-go-v2/internal/configsources` from 1.3.18 to 1.3.21 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/internal/ini/v1.3.18...internal/ini/v1.3.21) Updates `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from 2.6.18 to 2.6.21 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/internal/endpoints/v2.6.18...internal/endpoints/v2.6.21) Updates `github.com/aws/aws-sdk-go-v2/service/dynamodbstreams` from 1.23.3 to 1.24.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.23.3...service/pi/v1.24.2) Updates `github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding` from 1.11.5 to 1.12.0 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/v1.12.0/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/dlm/v1.11.5...v1.12.0) Updates `github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery` from 1.9.19 to 1.10.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/memorydb/v1.9.19...config/v1.10.2) Updates `github.com/aws/aws-sdk-go-v2/service/internal/presigned-url` from 1.11.20 to 1.12.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/dax/v1.11.20...service/m2/v1.12.2) Updates `github.com/aws/aws-sdk-go-v2/service/sso` from 1.23.3 to 1.24.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.23.3...service/pi/v1.24.2) Updates `github.com/aws/aws-sdk-go-v2/service/ssooidc` from 1.27.3 to 1.28.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.27.3...service/pi/v1.28.2) Updates `github.com/aws/aws-sdk-go-v2/service/sts` from 1.31.3 to 1.32.2 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/s3/v1.31.3...v1.32.2) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go-v2/config dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/credentials dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodb dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/kinesis dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/feature/ec2/imds dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/internal/configsources dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodbstreams dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/presigned-url dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/sso dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/ssooidc dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/sts dependency-type: indirect update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 ... Signed-off-by: dependabot[bot] <support@github.com>
184 lines
5.4 KiB
Go
184 lines
5.4 KiB
Go
package http
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net/http"
|
|
"net/http/httptrace"
|
|
"time"
|
|
|
|
"github.com/aws/smithy-go/metrics"
|
|
)
|
|
|
|
var now = time.Now
|
|
|
|
// withMetrics instruments an HTTP client and context to collect HTTP metrics.
|
|
func withMetrics(parent context.Context, client ClientDo, meter metrics.Meter) (
|
|
context.Context, ClientDo, error,
|
|
) {
|
|
hm, err := newHTTPMetrics(meter)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
ctx := httptrace.WithClientTrace(parent, &httptrace.ClientTrace{
|
|
DNSStart: hm.DNSStart,
|
|
ConnectStart: hm.ConnectStart,
|
|
TLSHandshakeStart: hm.TLSHandshakeStart,
|
|
|
|
GotConn: hm.GotConn(parent),
|
|
PutIdleConn: hm.PutIdleConn(parent),
|
|
ConnectDone: hm.ConnectDone(parent),
|
|
DNSDone: hm.DNSDone(parent),
|
|
TLSHandshakeDone: hm.TLSHandshakeDone(parent),
|
|
GotFirstResponseByte: hm.GotFirstResponseByte(parent),
|
|
})
|
|
return ctx, &timedClientDo{client, hm}, nil
|
|
}
|
|
|
|
type timedClientDo struct {
|
|
ClientDo
|
|
hm *httpMetrics
|
|
}
|
|
|
|
func (c *timedClientDo) Do(r *http.Request) (*http.Response, error) {
|
|
c.hm.doStart = now()
|
|
resp, err := c.ClientDo.Do(r)
|
|
|
|
c.hm.DoRequestDuration.Record(r.Context(), elapsed(c.hm.doStart))
|
|
return resp, err
|
|
}
|
|
|
|
type httpMetrics struct {
|
|
DNSLookupDuration metrics.Float64Histogram // client.http.connections.dns_lookup_duration
|
|
ConnectDuration metrics.Float64Histogram // client.http.connections.acquire_duration
|
|
TLSHandshakeDuration metrics.Float64Histogram // client.http.connections.tls_handshake_duration
|
|
ConnectionUsage metrics.Int64UpDownCounter // client.http.connections.usage
|
|
|
|
DoRequestDuration metrics.Float64Histogram // client.http.do_request_duration
|
|
TimeToFirstByte metrics.Float64Histogram // client.http.time_to_first_byte
|
|
|
|
doStart time.Time
|
|
dnsStart time.Time
|
|
connectStart time.Time
|
|
tlsStart time.Time
|
|
}
|
|
|
|
func newHTTPMetrics(meter metrics.Meter) (*httpMetrics, error) {
|
|
hm := &httpMetrics{}
|
|
|
|
var err error
|
|
hm.DNSLookupDuration, err = meter.Float64Histogram("client.http.connections.dns_lookup_duration", func(o *metrics.InstrumentOptions) {
|
|
o.UnitLabel = "s"
|
|
o.Description = "The time it takes a request to perform DNS lookup."
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
hm.ConnectDuration, err = meter.Float64Histogram("client.http.connections.acquire_duration", func(o *metrics.InstrumentOptions) {
|
|
o.UnitLabel = "s"
|
|
o.Description = "The time it takes a request to acquire a connection."
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
hm.TLSHandshakeDuration, err = meter.Float64Histogram("client.http.connections.tls_handshake_duration", func(o *metrics.InstrumentOptions) {
|
|
o.UnitLabel = "s"
|
|
o.Description = "The time it takes an HTTP request to perform the TLS handshake."
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
hm.ConnectionUsage, err = meter.Int64UpDownCounter("client.http.connections.usage", func(o *metrics.InstrumentOptions) {
|
|
o.UnitLabel = "{connection}"
|
|
o.Description = "Current state of connections pool."
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
hm.DoRequestDuration, err = meter.Float64Histogram("client.http.do_request_duration", func(o *metrics.InstrumentOptions) {
|
|
o.UnitLabel = "s"
|
|
o.Description = "Time spent performing an entire HTTP transaction."
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
hm.TimeToFirstByte, err = meter.Float64Histogram("client.http.time_to_first_byte", func(o *metrics.InstrumentOptions) {
|
|
o.UnitLabel = "s"
|
|
o.Description = "Time from start of transaction to when the first response byte is available."
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return hm, nil
|
|
}
|
|
|
|
func (m *httpMetrics) DNSStart(httptrace.DNSStartInfo) {
|
|
m.dnsStart = now()
|
|
}
|
|
|
|
func (m *httpMetrics) ConnectStart(string, string) {
|
|
m.connectStart = now()
|
|
}
|
|
|
|
func (m *httpMetrics) TLSHandshakeStart() {
|
|
m.tlsStart = now()
|
|
}
|
|
|
|
func (m *httpMetrics) GotConn(ctx context.Context) func(httptrace.GotConnInfo) {
|
|
return func(httptrace.GotConnInfo) {
|
|
m.addConnAcquired(ctx, 1)
|
|
}
|
|
}
|
|
|
|
func (m *httpMetrics) PutIdleConn(ctx context.Context) func(error) {
|
|
return func(error) {
|
|
m.addConnAcquired(ctx, -1)
|
|
}
|
|
}
|
|
|
|
func (m *httpMetrics) DNSDone(ctx context.Context) func(httptrace.DNSDoneInfo) {
|
|
return func(httptrace.DNSDoneInfo) {
|
|
m.DNSLookupDuration.Record(ctx, elapsed(m.dnsStart))
|
|
}
|
|
}
|
|
|
|
func (m *httpMetrics) ConnectDone(ctx context.Context) func(string, string, error) {
|
|
return func(string, string, error) {
|
|
m.ConnectDuration.Record(ctx, elapsed(m.connectStart))
|
|
}
|
|
}
|
|
|
|
func (m *httpMetrics) TLSHandshakeDone(ctx context.Context) func(tls.ConnectionState, error) {
|
|
return func(tls.ConnectionState, error) {
|
|
m.TLSHandshakeDuration.Record(ctx, elapsed(m.tlsStart))
|
|
}
|
|
}
|
|
|
|
func (m *httpMetrics) GotFirstResponseByte(ctx context.Context) func() {
|
|
return func() {
|
|
m.TimeToFirstByte.Record(ctx, elapsed(m.doStart))
|
|
}
|
|
}
|
|
|
|
func (m *httpMetrics) addConnAcquired(ctx context.Context, incr int64) {
|
|
m.ConnectionUsage.Add(ctx, incr, func(o *metrics.RecordMetricOptions) {
|
|
o.Properties.Set("state", "acquired")
|
|
})
|
|
}
|
|
|
|
// Not used: it is recommended to track acquired vs idle conn, but we can't
|
|
// determine when something is truly idle with the current HTTP client hooks
|
|
// available to us.
|
|
func (m *httpMetrics) addConnIdle(ctx context.Context, incr int64) {
|
|
m.ConnectionUsage.Add(ctx, incr, func(o *metrics.RecordMetricOptions) {
|
|
o.Properties.Set("state", "idle")
|
|
})
|
|
}
|
|
|
|
func elapsed(start time.Time) float64 {
|
|
end := now()
|
|
elapsed := end.Sub(start)
|
|
return float64(elapsed) / 1e9
|
|
}
|