mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
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>
This commit is contained in:
parent
59731289e9
commit
7667e13ae9
@ -8,6 +8,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/tools/internal/telemetry"
|
"golang.org/x/tools/internal/telemetry"
|
||||||
"golang.org/x/tools/internal/telemetry/export"
|
"golang.org/x/tools/internal/telemetry/export"
|
||||||
@ -230,19 +231,23 @@ func (data *Int64Data) modify(ctx context.Context, f func(v int64) int64) {
|
|||||||
export.Metric(ctx, &frozen)
|
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 })
|
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 })
|
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 })
|
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 })
|
data.modify(ctx, func(v int64) int64 { return value })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,11 +270,12 @@ func (data *Float64Data) modify(ctx context.Context, f func(v float64) float64)
|
|||||||
export.Metric(ctx, &frozen)
|
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 })
|
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 })
|
data.modify(ctx, func(v float64) float64 { return value })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +304,8 @@ func (data *HistogramInt64Data) modify(ctx context.Context, f func(v *HistogramI
|
|||||||
export.Metric(ctx, &frozen)
|
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) {
|
data.modify(ctx, func(v *HistogramInt64Row) {
|
||||||
v.Sum += value
|
v.Sum += value
|
||||||
if v.Min > value || v.Count == 0 {
|
if v.Min > value || v.Count == 0 {
|
||||||
@ -341,7 +348,8 @@ func (data *HistogramFloat64Data) modify(ctx context.Context, f func(v *Histogra
|
|||||||
export.Metric(ctx, &frozen)
|
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) {
|
data.modify(ctx, func(v *HistogramFloat64Row) {
|
||||||
v.Sum += value
|
v.Sum += value
|
||||||
if v.Min > value || v.Count == 0 {
|
if v.Min > value || v.Count == 0 {
|
||||||
|
@ -9,6 +9,7 @@ package stats
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/tools/internal/telemetry/unit"
|
"golang.org/x/tools/internal/telemetry/unit"
|
||||||
)
|
)
|
||||||
@ -31,11 +32,11 @@ type Float64Measure struct {
|
|||||||
|
|
||||||
// Int64Subscriber is the type for functions that want to listen to
|
// Int64Subscriber is the type for functions that want to listen to
|
||||||
// integer statistic events.
|
// 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
|
// Float64Subscriber is the type for functions that want to listen to
|
||||||
// floating point statistic events.
|
// 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.
|
// Int64 creates a new Int64Measure and prepares it for use.
|
||||||
func Int64(name string, description string, unit unit.Unit) *Int64Measure {
|
func Int64(name string, description string, unit unit.Unit) *Int64Measure {
|
||||||
@ -69,9 +70,10 @@ func (m *Int64Measure) Subscribe(s Int64Subscriber) { m.subscribers = append(m.s
|
|||||||
|
|
||||||
// Record delivers a new value to the subscribers of this measure.
|
// Record delivers a new value to the subscribers of this measure.
|
||||||
func (m *Int64Measure) Record(ctx context.Context, value int64) {
|
func (m *Int64Measure) Record(ctx context.Context, value int64) {
|
||||||
|
at := time.Now()
|
||||||
do(func() {
|
do(func() {
|
||||||
for _, s := range m.subscribers {
|
for _, s := range m.subscribers {
|
||||||
s(ctx, m, value)
|
s(ctx, m, value, at)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -90,9 +92,10 @@ func (m *Float64Measure) Subscribe(s Float64Subscriber) { m.subscribers = append
|
|||||||
|
|
||||||
// Record delivers a new value to the subscribers of this measure.
|
// Record delivers a new value to the subscribers of this measure.
|
||||||
func (m *Float64Measure) Record(ctx context.Context, value float64) {
|
func (m *Float64Measure) Record(ctx context.Context, value float64) {
|
||||||
|
at := time.Now()
|
||||||
do(func() {
|
do(func() {
|
||||||
for _, s := range m.subscribers {
|
for _, s := range m.subscribers {
|
||||||
s(ctx, m, value)
|
s(ctx, m, value, at)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user