1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:44:44 -07:00
go/internal/lsp/debug/metrics.go
Ian Cottrell 1249273038 internal/telemetry: make metrics take a strongly typed key
Now that keys are solidly typed, we can use them for the metrics.
This prevents accidentally using the wrong type of key, and
allows us to use the typed accesorrs rather than the raw value.

Change-Id: I553bd8e12128d3f00a3e926dbd3bfd420cd3f135
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225378
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-26 17:45:58 +00:00

59 lines
1.8 KiB
Go

// 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 debug
import (
"golang.org/x/tools/internal/lsp/debug/tag"
"golang.org/x/tools/internal/telemetry/event"
"golang.org/x/tools/internal/telemetry/export/metric"
)
var (
// the distributions we use for histograms
bytesDistribution = []int64{1 << 10, 1 << 11, 1 << 12, 1 << 14, 1 << 16, 1 << 20}
millisecondsDistribution = []float64{0.1, 0.5, 1, 2, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000}
receivedBytes = metric.HistogramInt64{
Name: "received_bytes",
Description: "Distribution of received bytes, by method.",
Keys: []event.Key{tag.RPCDirection, tag.Method},
Buckets: bytesDistribution,
}
sentBytes = metric.HistogramInt64{
Name: "sent_bytes",
Description: "Distribution of sent bytes, by method.",
Keys: []event.Key{tag.RPCDirection, tag.Method},
Buckets: bytesDistribution,
}
latency = metric.HistogramFloat64{
Name: "latency",
Description: "Distribution of latency in milliseconds, by method.",
Keys: []event.Key{tag.RPCDirection, tag.Method},
Buckets: millisecondsDistribution,
}
started = metric.Scalar{
Name: "started",
Description: "Count of RPCs started by method.",
Keys: []event.Key{tag.RPCDirection, tag.Method},
}
completed = metric.Scalar{
Name: "completed",
Description: "Count of RPCs completed by method and status.",
Keys: []event.Key{tag.RPCDirection, tag.Method, tag.StatusCode},
}
)
func registerMetrics(m *metric.Config) {
receivedBytes.Record(m, tag.ReceivedBytes)
sentBytes.Record(m, tag.SentBytes)
latency.Record(m, tag.Latency)
started.Count(m, tag.Started)
completed.Count(m, tag.Latency)
}