Skip to content

Commit

Permalink
feat: exporting first byte read latency
Browse files Browse the repository at this point in the history
  • Loading branch information
raj-prince committed Nov 2, 2024
1 parent 5716613 commit 3d44fb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func ReadObject(ctx context.Context, workerID int, bucketHandle *storage.BucketH
if err != nil {
return fmt.Errorf("while creating reader object: %v", err)
}
firstByteTime := time.Since(start)
stats.Record(ctx, firstByteReadLatency.M(float64(firstByteTime.Milliseconds())))

// Calls Reader.WriteTo implicitly.
_, err = io.Copy(io.Discard, rc)
Expand Down Expand Up @@ -234,6 +236,7 @@ func main() {

// Enable stack-driver exporter.
registerLatencyView()
registerFirstByteLatencyView()

err = enableSDExporter()
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
var (
// The restaurant rating in number of stars.
readLatency = stats.Float64("readLatency", "Complete read latency", stats.UnitMilliseconds)
firstByteReadLatency = stats.Float64("firstByteReadLatency", "First byte read latency", stats.UnitMilliseconds)
)

var sdExporter *stackdriver.Exporter
Expand All @@ -32,6 +33,19 @@ func registerLatencyView() {
log.Fatalf("Failed to register the readLatency view: %v", err)
}
}
func registerFirstByteLatencyView() {
v := &view.View{
Name: "princer_go_client_first_byte_read_latency",
Measure: firstByteReadLatency,
Description: "First byte read latency for a given go-client",
TagKeys: []tag.Key{tag.MustNewKey("princer_first_byte_read_latency")},
Aggregation: ochttp.DefaultLatencyDistribution,
}

if err := view.Register(v); err != nil {
log.Fatalf("Failed to register the readLatency view: %v", err)
}
}

func enableSDExporter() (err error) {
sdExporter, err := stackdriver.NewExporter(stackdriver.Options{
Expand Down

0 comments on commit 3d44fb9

Please sign in to comment.