Skip to content

Commit c271f90

Browse files
committed
pkg/util/log: plumb LogMetricRegistry into log package
This patch plumbs the LogMetricRegistry into the log package as part of the initialization of the package where the implementation lives. With the log metrics plumbed into the log package and made available in the server, we can now add them to the metrics recorder used by the server, as well as begin using metrics within the log package. Release note: none
1 parent 4a3695f commit c271f90

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

pkg/server/status/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ go_library(
6565
"//pkg/util/humanizeutil",
6666
"//pkg/util/log",
6767
"//pkg/util/log/eventpb",
68+
"//pkg/util/log/logmetrics",
6869
"//pkg/util/metric",
6970
"//pkg/util/syncutil",
7071
"//pkg/util/system",

pkg/server/status/recorder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import (
4545
"github.com/cockroachdb/cockroach/pkg/util/hlc"
4646
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
4747
"github.com/cockroachdb/cockroach/pkg/util/log"
48+
// Import the logmetrics package to trigger its own init function, which inits and injects
49+
// metrics functionality into pkg/util/log.
50+
_ "github.com/cockroachdb/cockroach/pkg/util/log/logmetrics"
4851
"github.com/cockroachdb/cockroach/pkg/util/metric"
4952
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
5053
"github.com/cockroachdb/cockroach/pkg/util/system"

pkg/util/log/logmetrics/metrics.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ var (
2828
}
2929
)
3030

31+
// Inject our singleton LogMetricsRegistry into the logging
32+
// package. This ensures that the LogMetrics implementation within the
33+
// log package is always defined. This should only be called once from
34+
// a single init function.
35+
//
36+
// Since the primary user of the eventual metric.Registry's that come
37+
// from LogMetricsRegistry is the MetricsRecorder, we trigger this
38+
// init function via an import in pkg/util/log/logmetrics/metrics.go.
39+
func init() {
40+
log.SetLogMetrics(logMetricsReg)
41+
}
42+
3143
// logMetricsStruct is a struct used to contain all metrics
3244
// tracked by the LogMetricsRegistry. This container is necessary
3345
// to register all the metrics with the Registry internal to the

0 commit comments

Comments
 (0)