internal/telemetry: modify *Subscriber to take timeAt

Modifies the various Subscriber signatures to take in
an "at" time.Time field, which captures the time that
a measurement was made. This field will then be used
when exporting points as their EndTime.

Fixes #34490.

Change-Id: I9e87b65e374876ae3d4df0abedb64bb7dcb221b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/199577
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/telemetry/metric/metric.go b/internal/telemetry/metric/metric.go
index 64aa572..0333450 100644
--- a/internal/telemetry/metric/metric.go
+++ b/internal/telemetry/metric/metric.go
@@ -8,6 +8,7 @@
 import (
 	"context"
 	"sort"
+	"time"
 
 	"golang.org/x/tools/internal/telemetry"
 	"golang.org/x/tools/internal/telemetry/export"
@@ -230,19 +231,23 @@
 	export.Metric(ctx, &frozen)
 }
 
-func (data *Int64Data) countInt64(ctx context.Context, measure *stats.Int64Measure, value int64) {
+func (data *Int64Data) countInt64(ctx context.Context, measure *stats.Int64Measure, value int64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v int64) int64 { return v + 1 })
 }
 
-func (data *Int64Data) countFloat64(ctx context.Context, measure *stats.Float64Measure, value float64) {
+func (data *Int64Data) countFloat64(ctx context.Context, measure *stats.Float64Measure, value float64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v int64) int64 { return v + 1 })
 }
 
-func (data *Int64Data) sum(ctx context.Context, measure *stats.Int64Measure, value int64) {
+func (data *Int64Data) sum(ctx context.Context, measure *stats.Int64Measure, value int64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v int64) int64 { return v + value })
 }
 
-func (data *Int64Data) latest(ctx context.Context, measure *stats.Int64Measure, value int64) {
+func (data *Int64Data) latest(ctx context.Context, measure *stats.Int64Measure, value int64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v int64) int64 { return value })
 }
 
@@ -265,11 +270,12 @@
 	export.Metric(ctx, &frozen)
 }
 
-func (data *Float64Data) sum(ctx context.Context, measure *stats.Float64Measure, value float64) {
+func (data *Float64Data) sum(ctx context.Context, measure *stats.Float64Measure, value float64, at time.Time) {
 	data.modify(ctx, func(v float64) float64 { return v + value })
 }
 
-func (data *Float64Data) latest(ctx context.Context, measure *stats.Float64Measure, value float64) {
+func (data *Float64Data) latest(ctx context.Context, measure *stats.Float64Measure, value float64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v float64) float64 { return value })
 }
 
@@ -298,7 +304,8 @@
 	export.Metric(ctx, &frozen)
 }
 
-func (data *HistogramInt64Data) record(ctx context.Context, measure *stats.Int64Measure, value int64) {
+func (data *HistogramInt64Data) record(ctx context.Context, measure *stats.Int64Measure, value int64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v *HistogramInt64Row) {
 		v.Sum += value
 		if v.Min > value || v.Count == 0 {
@@ -341,7 +348,8 @@
 	export.Metric(ctx, &frozen)
 }
 
-func (data *HistogramFloat64Data) record(ctx context.Context, measure *stats.Float64Measure, value float64) {
+func (data *HistogramFloat64Data) record(ctx context.Context, measure *stats.Float64Measure, value float64, at time.Time) {
+	// TODO: Use at.
 	data.modify(ctx, func(v *HistogramFloat64Row) {
 		v.Sum += value
 		if v.Min > value || v.Count == 0 {
diff --git a/internal/telemetry/stats/stats.go b/internal/telemetry/stats/stats.go
index a2b97d5..e6eb364 100644
--- a/internal/telemetry/stats/stats.go
+++ b/internal/telemetry/stats/stats.go
@@ -9,6 +9,7 @@
 
 import (
 	"context"
+	"time"
 
 	"golang.org/x/tools/internal/telemetry/unit"
 )
@@ -31,11 +32,11 @@
 
 // Int64Subscriber is the type for functions that want to listen to
 // integer statistic events.
-type Int64Subscriber func(context.Context, *Int64Measure, int64)
+type Int64Subscriber func(ctx context.Context, im *Int64Measure, value int64, at time.Time)
 
 // Float64Subscriber is the type for functions that want to listen to
 // floating point statistic events.
-type Float64Subscriber func(context.Context, *Float64Measure, float64)
+type Float64Subscriber func(ctx context.Context, fm *Float64Measure, value float64, at time.Time)
 
 // Int64 creates a new Int64Measure and prepares it for use.
 func Int64(name string, description string, unit unit.Unit) *Int64Measure {
@@ -69,9 +70,10 @@
 
 // Record delivers a new value to the subscribers of this measure.
 func (m *Int64Measure) Record(ctx context.Context, value int64) {
+	at := time.Now()
 	do(func() {
 		for _, s := range m.subscribers {
-			s(ctx, m, value)
+			s(ctx, m, value, at)
 		}
 	})
 }
@@ -90,9 +92,10 @@
 
 // Record delivers a new value to the subscribers of this measure.
 func (m *Float64Measure) Record(ctx context.Context, value float64) {
+	at := time.Now()
 	do(func() {
 		for _, s := range m.subscribers {
-			s(ctx, m, value)
+			s(ctx, m, value, at)
 		}
 	})
 }