mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
internal/telemetry: extract units to their own package
This makes the code read slightly better, and more closely aligns with the open telemetry code. Change-Id: I87eaf7d08b802f7862f896f2654456ee6a7681e3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/190404 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
156eb2ae29
commit
922a4ee32d
@ -9,6 +9,7 @@ package telemetry
|
||||
import (
|
||||
"golang.org/x/tools/internal/telemetry/stats"
|
||||
"golang.org/x/tools/internal/telemetry/tag"
|
||||
"golang.org/x/tools/internal/telemetry/unit"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -24,10 +25,10 @@ const (
|
||||
|
||||
var (
|
||||
// create the stats we measure
|
||||
Started = stats.Int64("started", "Count of started RPCs.", stats.UnitDimensionless)
|
||||
ReceivedBytes = stats.Int64("received_bytes", "Bytes received.", stats.UnitBytes)
|
||||
SentBytes = stats.Int64("sent_bytes", "Bytes sent.", stats.UnitBytes)
|
||||
Latency = stats.Float64("latency_ms", "Elapsed time in milliseconds", stats.UnitMilliseconds)
|
||||
Started = stats.Int64("started", "Count of started RPCs.", unit.Dimensionless)
|
||||
ReceivedBytes = stats.Int64("received_bytes", "Bytes received.", unit.Bytes)
|
||||
SentBytes = stats.Int64("sent_bytes", "Bytes sent.", unit.Bytes)
|
||||
Latency = stats.Float64("latency_ms", "Elapsed time in milliseconds", unit.Milliseconds)
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -9,13 +9,15 @@ package stats
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"golang.org/x/tools/internal/telemetry/unit"
|
||||
)
|
||||
|
||||
// Int64Measure is used to record integer values.
|
||||
type Int64Measure struct {
|
||||
name string
|
||||
description string
|
||||
unit Unit
|
||||
unit unit.Unit
|
||||
subscribers []Int64Subscriber
|
||||
}
|
||||
|
||||
@ -23,7 +25,7 @@ type Int64Measure struct {
|
||||
type Float64Measure struct {
|
||||
name string
|
||||
description string
|
||||
unit Unit
|
||||
unit unit.Unit
|
||||
subscribers []Float64Subscriber
|
||||
}
|
||||
|
||||
@ -35,21 +37,8 @@ type Int64Subscriber func(context.Context, *Int64Measure, int64)
|
||||
// floating point statistic events.
|
||||
type Float64Subscriber func(context.Context, *Float64Measure, float64)
|
||||
|
||||
// Unit is used to specify the units for a given measure.
|
||||
// This is can used for display purposes.
|
||||
type Unit int
|
||||
|
||||
const (
|
||||
// UnitDimensionless indicates that a measure has no specified units.
|
||||
UnitDimensionless = Unit(iota)
|
||||
// UnitBytes indicates that that a measure is recording number of bytes.
|
||||
UnitBytes
|
||||
// UnitMilliseconds indicates that a measure is recording a duration in milliseconds.
|
||||
UnitMilliseconds
|
||||
)
|
||||
|
||||
// Int64 creates a new Int64Measure and prepares it for use.
|
||||
func Int64(name string, description string, unit Unit) *Int64Measure {
|
||||
func Int64(name string, description string, unit unit.Unit) *Int64Measure {
|
||||
return &Int64Measure{
|
||||
name: name,
|
||||
description: description,
|
||||
@ -58,7 +47,7 @@ func Int64(name string, description string, unit Unit) *Int64Measure {
|
||||
}
|
||||
|
||||
// Float64 creates a new Float64Measure and prepares it for use.
|
||||
func Float64(name string, description string, unit Unit) *Float64Measure {
|
||||
func Float64(name string, description string, unit unit.Unit) *Float64Measure {
|
||||
return &Float64Measure{
|
||||
name: name,
|
||||
description: description,
|
||||
@ -73,7 +62,7 @@ func (m *Int64Measure) Name() string { return m.name }
|
||||
func (m *Int64Measure) Description() string { return m.description }
|
||||
|
||||
// Unit returns the units this measure was given on construction.
|
||||
func (m *Int64Measure) Unit() Unit { return m.unit }
|
||||
func (m *Int64Measure) Unit() unit.Unit { return m.unit }
|
||||
|
||||
// Subscribe adds a new subscriber to this measure.
|
||||
func (m *Int64Measure) Subscribe(s Int64Subscriber) { m.subscribers = append(m.subscribers, s) }
|
||||
@ -92,7 +81,7 @@ func (m *Float64Measure) Name() string { return m.name }
|
||||
func (m *Float64Measure) Description() string { return m.description }
|
||||
|
||||
// Unit returns the units this measure was given on construction.
|
||||
func (m *Float64Measure) Unit() Unit { return m.unit }
|
||||
func (m *Float64Measure) Unit() unit.Unit { return m.unit }
|
||||
|
||||
// Subscribe adds a new subscriber to this measure.
|
||||
func (m *Float64Measure) Subscribe(s Float64Subscriber) { m.subscribers = append(m.subscribers, s) }
|
||||
|
19
internal/telemetry/unit/unit.go
Normal file
19
internal/telemetry/unit/unit.go
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package unit holds the definitions for the units you can use in telemetry.
|
||||
package unit
|
||||
|
||||
// Unit is used to specify the units for a given measure.
|
||||
// This is can used for display purposes.
|
||||
type Unit string
|
||||
|
||||
const (
|
||||
// UnitDimensionless indicates that a measure has no specified units.
|
||||
Dimensionless = "1"
|
||||
// UnitBytes indicates that that a measure is recording number of bytes.
|
||||
Bytes = "By"
|
||||
// UnitMilliseconds indicates that a measure is recording a duration in milliseconds.
|
||||
Milliseconds = "ms"
|
||||
)
|
Loading…
Reference in New Issue
Block a user