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

example/aws/request/httptrace: Update example with more metrics #3436

Merged
merged 6 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions example/aws/request/httptrace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ like SNS's `PublishWithContext`.
The `trace.go` file demonstrates how the `httptrace` package's `ClientTrace`
can be created to gather timing information from HTTP requests made.

The `logger.go` file demonstrates how the trace information can be combined to
retrieve timing data for the different stages of the request.

The `config.go` file provides additional configuration settings to control how
the HTTP client and its transport is configured. Such as, timeouts, and
keepalive.
Expand All @@ -36,5 +33,24 @@ Message: My Really cool Message
The example will output the http trace timing information for how long the request took.

```
Latency: 79.863505ms ConnectionReused: false DNSStartAt: 280.452µs DNSDoneAt: 1.526342ms DNSDur: 1.24589ms ConnectStartAt: 1.533484ms ConnectDoneAt: 11.290792ms ConnectDur: 9.757308ms TLSStatAt: 11.331066ms TLSDoneAt: 33.912968ms TLSDur: 22.581902ms RequestWritten 34.951272ms RespFirstByte: 79.534808ms WaitRespFirstByte: 44.583536ms
Message: first message
2020/07/21 14:21:23 Latency: 292.687003ms, Validate: 23.261µs, Build: 92.249µs, Attempts: 1,
Attempt: 0, Latency: 292.541266ms, Sign: 159.755µs, Send: 292.173529ms, Unmarshal: 203.204µs, WillRetry: false,
HTTP: Latency: 292.174168ms, ConnReused: false, GetConn: 238.080409ms, DNS: 22.774015ms, Connect: 22.774015ms, TLS: 200.809752ms, WriteRequest: 424.376µs, WaitResponseFirstByte: 292.058664ms, ReadResponseHeader: 115.196µs,

Message: second message
2020/07/21 14:21:29 Latency: 47.824618ms, Validate: 2.91µs, Build: 110.86µs, Attempts: 1,
Attempt: 0, Latency: 47.68784ms, Sign: 237.076µs, Send: 47.29333ms, Unmarshal: 151.831µs, WillRetry: false,
HTTP: Latency: 47.29391ms, ConnReused: true, WriteRequest: 285.042µs, WaitResponseFirstByte: 47.233202ms, ReadResponseHeader: 60.252µs,

Message: third message
2020/07/21 14:21:33 Latency: 31.435353ms, Validate: 1.603µs, Build: 29.356µs, Attempts: 1,
Attempt: 0, Latency: 31.39293ms, Sign: 63.152µs, Send: 31.245591ms, Unmarshal: 81.123µs, WillRetry: false,
HTTP: Latency: 31.24588ms, ConnReused: true, WriteRequest: 151.738µs, WaitResponseFirstByte: 31.208877ms, ReadResponseHeader: 36.731µs,

Message: last message
2020/07/21 14:21:37 Latency: 42.643276ms, Validate: 1.903µs, Build: 33.829µs, Attempts: 1,
Attempt: 0, Latency: 42.582587ms, Sign: 57.561µs, Send: 42.264062ms, Unmarshal: 246.32µs, WillRetry: false,
HTTP: Latency: 42.265295ms, ConnReused: true, WriteRequest: 178.259µs, WaitResponseFirstByte: 42.142391ms, ReadResponseHeader: 122.393µs,
```

100 changes: 0 additions & 100 deletions example/aws/request/httptrace/logger.go

This file was deleted.

16 changes: 6 additions & 10 deletions example/aws/request/httptrace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"flag"
"fmt"
"log"
"os"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -38,10 +39,6 @@ func main() {
httpClient := NewClient(clientCfg)
sess, err := session.NewSession(&aws.Config{
HTTPClient: httpClient,

// Disable Retries to prevent the httptrace's getting mixed up on
// retries.
MaxRetries: aws.Int(0),
})
if err != nil {
exitErrorf(err, "failed to load config")
Expand All @@ -60,7 +57,7 @@ func main() {
if err != nil {
fmt.Fprintf(os.Stderr, "failed to publish message, %v", err)
}
RecordTrace(os.Stdout, trace)
log.Println(trace)

fmt.Println()
fmt.Printf("Message: ")
Expand All @@ -73,18 +70,17 @@ func main() {
// publishMessage will send the message to the SNS topic returning an request
// trace for metrics.
func publishMessage(ctx context.Context, svc *sns.SNS, topic, msg string) (*RequestTrace, error) {
traceCtx := NewRequestTrace(ctx)
defer traceCtx.RequestDone()
trace := &RequestTrace{}

_, err := svc.PublishWithContext(traceCtx, &sns.PublishInput{
_, err := svc.PublishWithContext(ctx, &sns.PublishInput{
TopicArn: &topic,
Message: &msg,
})
}, trace.TraceRequest)
if err != nil {
return nil, err
}

return traceCtx, nil
return trace, nil
}

func exitErrorf(err error, msg string, args ...interface{}) {
Expand Down
Loading