From 0df4929eaf8494e2e2650aebfe40f9f8f84b2a18 Mon Sep 17 00:00:00 2001 From: Josh Carp Date: Thu, 6 Jul 2023 22:05:22 -0400 Subject: [PATCH] pkg/metrics: use native histograms behind an environment flag. Optionally enable prometheus native histograms. Native histograms are sparse histograms with exponentially spaced buckets that require minimal configuration. They are also represented as a single series, rather than a series per bucket as for conventional histograms. As a result, native histograms typically require less memory and storage and offer higher precision relative to conventional histograms. This patch enables support for native histograms behind the COCKROACH_ENABLE_PROMETHEUS_NATIVE_HISTOGRAMS environment variable flag. We use a flag because native histograms are currently considered experimental in prometheus. To use this feature, set the COCKROACH_ENABLE_PROMETHEUS_NATIVE_HISTOGRAMS environment variable to "true", and enable native histogram support in prometheus by setting --enable-feature=native-histograms in the server arguments. Note that crdb exports both conventional and native histograms when native histogram support is enabled; prometheus can be configured to scrape either or both. Prometheus native histograms currently only support exponentially spaced buckets, so we also limit their use to metrics with an exponential distribution. Note that native histograms currently use the protobuf exposition format, so we add content negotiation to the prometheus exporter. Release note (ops change): Added support for prometheus native histograms behind an environment variable flag. --- DEPS.bzl | 68 ++++++++++++------- build/bazelutil/distdir_files.bzl | 18 ++--- go.mod | 18 ++--- go.sum | 47 ++++--------- pkg/ccl/sqlproxyccl/BUILD.bazel | 1 + pkg/ccl/sqlproxyccl/server.go | 6 +- .../clusterstats/mocks_generated_test.go | 26 ++++--- pkg/cmd/roachtest/tests/drt_generated_test.go | 26 ++++--- pkg/kv/kvserver/BUILD.bazel | 1 + pkg/kv/kvserver/client_tenant_test.go | 3 +- pkg/roachprod/prometheus/prometheus.go | 4 +- pkg/server/BUILD.bazel | 1 + pkg/server/load_endpoint.go | 7 +- pkg/server/load_endpoint_test.go | 6 +- pkg/server/status.go | 8 ++- pkg/server/status/BUILD.bazel | 2 + pkg/server/status/recorder.go | 5 +- pkg/server/status/recorder_test.go | 11 +-- pkg/testutils/metrictestutils/BUILD.bazel | 5 +- pkg/testutils/metrictestutils/metrics_text.go | 3 +- pkg/util/metric/BUILD.bazel | 1 + pkg/util/metric/aggmetric/BUILD.bazel | 1 + pkg/util/metric/aggmetric/agg_metric_test.go | 3 +- pkg/util/metric/metric.go | 27 ++++++++ pkg/util/metric/metric_test.go | 21 ++++++ pkg/util/metric/prometheus_exporter.go | 9 +-- pkg/util/metric/prometheus_exporter_test.go | 38 ++++++++++- 27 files changed, 250 insertions(+), 116 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 50f4a569dbfb..cc655b5a5c57 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -134,6 +134,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/akavel/rsrc/com_github_akavel_rsrc-v0.8.0.zip", ], ) + go_repository( + name = "com_github_alecthomas_kingpin_v2", + build_file_proto_mode = "disable_global", + importpath = "github.com/alecthomas/kingpin/v2", + sha256 = "2a322681d79461dd793c1e8a98adf062f6ef554abcd3ab06981eef94d79c136b", + strip_prefix = "github.com/alecthomas/kingpin/v2@v2.3.1", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/kingpin/v2/com_github_alecthomas_kingpin_v2-v2.3.1.zip", + ], + ) go_repository( name = "com_github_alecthomas_template", build_file_proto_mode = "disable_global", @@ -148,10 +158,10 @@ def go_deps(): name = "com_github_alecthomas_units", build_file_proto_mode = "disable_global", importpath = "github.com/alecthomas/units", - sha256 = "461b05eb19b6023664d6502cb4fbf093a99a9ee2a36c43b4da5ca1287c495ff7", - strip_prefix = "github.com/alecthomas/units@v0.0.0-20210208195552-ff826a37aa15", + sha256 = "b62437d74a523089af46ba0115ece1ce11bca5e321fe1e1d4c976ecca6ee78aa", + strip_prefix = "github.com/alecthomas/units@v0.0.0-20211218093645-b94a6e3cc137", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/units/com_github_alecthomas_units-v0.0.0-20210208195552-ff826a37aa15.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/units/com_github_alecthomas_units-v0.0.0-20211218093645-b94a6e3cc137.zip", ], ) go_repository( @@ -3076,10 +3086,10 @@ def go_deps(): name = "com_github_go_kit_log", build_file_proto_mode = "disable_global", importpath = "github.com/go-kit/log", - sha256 = "e0676df7357654a000008dfad3b6b211cba3595f32d3e220edd63a4c9d0d9254", - strip_prefix = "github.com/go-kit/log@v0.1.0", + sha256 = "52634b502b9d0aa945833d93582cffc1bdd9bfa39810e7c70d0688e330b75198", + strip_prefix = "github.com/go-kit/log@v0.2.1", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-kit/log/com_github_go_kit_log-v0.1.0.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-kit/log/com_github_go_kit_log-v0.2.1.zip", ], ) go_repository( @@ -3744,10 +3754,10 @@ def go_deps(): patches = [ "@com_github_cockroachdb_cockroach//build/patches:com_github_golang_protobuf.patch", ], - sha256 = "5d1c817bebc1202ab3b42a418e584e0008e8027baf212ce69c2ae3e9e7b8c64b", - strip_prefix = "github.com/golang/protobuf@v1.5.2", + sha256 = "93bda6e88d4a0a493a98b481de67a10000a755d15f16a800b49a6b96d1bd6f81", + strip_prefix = "github.com/golang/protobuf@v1.5.3", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/protobuf/com_github_golang_protobuf-v1.5.2.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/protobuf/com_github_golang_protobuf-v1.5.3.zip", ], ) go_repository( @@ -7433,10 +7443,10 @@ def go_deps(): name = "com_github_prometheus_client_golang", build_file_proto_mode = "disable_global", importpath = "github.com/prometheus/client_golang", - sha256 = "d9bbfcdcb5f63812b6766884a0f5ad5b1f9a675375d28e307573f49e2ef96b7b", - strip_prefix = "github.com/prometheus/client_golang@v1.12.1", + sha256 = "0167cee686b836da39815e4a7ea64ecc245f6a3fb9b3c3f729941ed55da7dd4f", + strip_prefix = "github.com/prometheus/client_golang@v1.16.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_golang/com_github_prometheus_client_golang-v1.12.1.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_golang/com_github_prometheus_client_golang-v1.16.0.zip", ], ) go_repository( @@ -7446,20 +7456,20 @@ def go_deps(): ], build_file_proto_mode = "default", importpath = "github.com/prometheus/client_model", - sha256 = "44fc58fe25ed9b122b6755e8d356d5f199592f959af3b87a3b636c6eb82b43c5", - strip_prefix = "github.com/prometheus/client_model@v0.2.1-0.20210607210712-147c58e9608a", + sha256 = "2a1d147754959287fc34a7bb7c333b3d6fe0ca0d7db1606c49e8f48fd0311547", + strip_prefix = "github.com/prometheus/client_model@v0.3.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_model/com_github_prometheus_client_model-v0.2.1-0.20210607210712-147c58e9608a.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_model/com_github_prometheus_client_model-v0.3.0.zip", ], ) go_repository( name = "com_github_prometheus_common", build_file_proto_mode = "disable_global", importpath = "github.com/prometheus/common", - sha256 = "9630b9bbfcf1746a01c8aff0262271c60cf891fa1cd48a8ed9149de557dc98d6", - strip_prefix = "github.com/prometheus/common@v0.32.1", + sha256 = "7a4ef12402a8a153c47c085cadf362bdc2ffe4761e50d6ab2c49e4d64044bc85", + strip_prefix = "github.com/prometheus/common@v0.42.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/common/com_github_prometheus_common-v0.32.1.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/common/com_github_prometheus_common-v0.42.0.zip", ], ) go_repository( @@ -7486,10 +7496,10 @@ def go_deps(): name = "com_github_prometheus_procfs", build_file_proto_mode = "disable_global", importpath = "github.com/prometheus/procfs", - sha256 = "3e37c9f62738a493dd28283179d802749050353df0bca161df7cec4ed43e6f1a", - strip_prefix = "github.com/prometheus/procfs@v0.7.3", + sha256 = "3f7a5c30bbcd2adcc7ec62896b69a3792ca1603cf0998fa06d2b872a74ed13b0", + strip_prefix = "github.com/prometheus/procfs@v0.10.1", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/procfs/com_github_prometheus_procfs-v0.7.3.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/procfs/com_github_prometheus_procfs-v0.10.1.zip", ], ) go_repository( @@ -8776,6 +8786,16 @@ def go_deps(): "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xeipuuv/gojsonschema/com_github_xeipuuv_gojsonschema-v1.2.0.zip", ], ) + go_repository( + name = "com_github_xhit_go_str2duration", + build_file_proto_mode = "disable_global", + importpath = "github.com/xhit/go-str2duration", + sha256 = "87df7da9ed9a48a2da6b3df14d33a567a9e6ed2454e4cbd694baa7ec82ca7ec1", + strip_prefix = "github.com/xhit/go-str2duration@v1.2.0", + urls = [ + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xhit/go-str2duration/com_github_xhit_go_str2duration-v1.2.0.zip", + ], + ) go_repository( name = "com_github_xiang90_probing", build_file_proto_mode = "disable_global", @@ -11260,10 +11280,10 @@ def go_deps(): name = "org_golang_x_sync", build_file_proto_mode = "disable_global", importpath = "golang.org/x/sync", - sha256 = "f510bec6009e19882d19953e7273137d34df86c65949345d72f123a255c2ecd2", - strip_prefix = "golang.org/x/sync@v0.1.0", + sha256 = "ee0df4572dd73665767964ff809b12f0d41e3a0740220d44d418a19989a0363b", + strip_prefix = "golang.org/x/sync@v0.2.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/sync/org_golang_x_sync-v0.1.0.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/sync/org_golang_x_sync-v0.2.0.zip", ], ) go_repository( diff --git a/build/bazelutil/distdir_files.bzl b/build/bazelutil/distdir_files.bzl index f8c5eb265417..da9a2ad03e22 100644 --- a/build/bazelutil/distdir_files.bzl +++ b/build/bazelutil/distdir_files.bzl @@ -206,8 +206,9 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/ajg/form/com_github_ajg_form-v1.5.1.zip": "b063b07639670ce9b6a0065b4dc35ef9e4cebc0c601be27f5494a3e6a87eb78b", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/ajstarks/svgo/com_github_ajstarks_svgo-v0.0.0-20210923152817-c3b6e2f0c527.zip": "d58dcf4f11896cb22cec4db53ca17df342c6da4cc3a084c270f2da9e1eb351a7", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/akavel/rsrc/com_github_akavel_rsrc-v0.8.0.zip": "13954a09edc3a680d633c5ea7b4be902df3a70ca1720b349faadca44dc0c7ecc", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/kingpin/v2/com_github_alecthomas_kingpin_v2-v2.3.1.zip": "2a322681d79461dd793c1e8a98adf062f6ef554abcd3ab06981eef94d79c136b", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/template/com_github_alecthomas_template-v0.0.0-20190718012654-fb15b899a751.zip": "25e3be7192932d130d0af31ce5bcddae887647ba4afcfb32009c3b9b79dbbdb3", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/units/com_github_alecthomas_units-v0.0.0-20210208195552-ff826a37aa15.zip": "461b05eb19b6023664d6502cb4fbf093a99a9ee2a36c43b4da5ca1287c495ff7", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alecthomas/units/com_github_alecthomas_units-v0.0.0-20211218093645-b94a6e3cc137.zip": "b62437d74a523089af46ba0115ece1ce11bca5e321fe1e1d4c976ecca6ee78aa", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alessio/shellescape/com_github_alessio_shellescape-v1.4.1.zip": "e28d444e73b803a15cf83e6179149d34c6c132baa60cb8137e5f0aea50a543bf", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alexbrainman/sspi/com_github_alexbrainman_sspi-v0.0.0-20210105120005-909beea2cc74.zip": "f094ecfc4554a9ca70f0ade41747123f3161a15fb1a6112305b99731befc8648", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/alexflint/go-filemutex/com_github_alexflint_go_filemutex-v0.0.0-20171022225611-72bdc8eae2ae.zip": "f3517f75266ac4651b0b421dd970a68d5645c929062f2d67b9e1e4685562b690", @@ -466,7 +467,7 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-gl/glfw/v3.3/glfw/com_github_go_gl_glfw_v3_3_glfw-v0.0.0-20200222043503-6f7a984d4dc4.zip": "2f6a1963397cb7c3df66257a45d75fae860aa9b9eec17825d8101c1e1313da5b", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-ini/ini/com_github_go_ini_ini-v1.25.4.zip": "2ec52de9f1c96133e9f81b8250fdc99ca0729c0d429e318d7c8836b7a6ba5f60", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-kit/kit/com_github_go_kit_kit-v0.10.0.zip": "dbdc933092b036483ca332f8c7c13e8b7d029192e79354d4f5a581ef3c364816", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-kit/log/com_github_go_kit_log-v0.1.0.zip": "e0676df7357654a000008dfad3b6b211cba3595f32d3e220edd63a4c9d0d9254", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-kit/log/com_github_go_kit_log-v0.2.1.zip": "52634b502b9d0aa945833d93582cffc1bdd9bfa39810e7c70d0688e330b75198", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-latex/latex/com_github_go_latex_latex-v0.0.0-20210823091927-c0d11ff05a81.zip": "c58be686b31679ad0a51a5d70e60df92fb4bb50a16727caa58b4a67b33f16509", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-logfmt/logfmt/com_github_go_logfmt_logfmt-v0.5.1.zip": "9e030cd09b584e59a2f5baaa24cf600520757d732af0f8993cc412dd3086703a", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/go-logr/logr/com_github_go_logr_logr-v1.2.2.zip": "3d8ad5428394dcea7ecd1e9b9750011341e9043412326f53138677f9eac84567", @@ -534,7 +535,7 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/glog/com_github_golang_glog-v1.0.0.zip": "ae8dfead198447a555409e4e942bd4aae2210b18bc90ff8f032ab09a9940e8f8", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/groupcache/com_github_golang_groupcache-v0.0.0-20210331224755-41bb18bfe9da.zip": "b27034e8fc013627543e1ad098cfc65329f2896df3da5cf3266cc9166f93f3a5", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/mock/com_github_golang_mock-v1.6.0.zip": "fa25916b546f90da49418f436e3a61e4c5dae898cf3c82b0007b5a6fab74261b", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/protobuf/com_github_golang_protobuf-v1.5.2.zip": "5d1c817bebc1202ab3b42a418e584e0008e8027baf212ce69c2ae3e9e7b8c64b", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/protobuf/com_github_golang_protobuf-v1.5.3.zip": "93bda6e88d4a0a493a98b481de67a10000a755d15f16a800b49a6b96d1bd6f81", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golang/snappy/com_github_golang_snappy-v0.0.4.zip": "ea4545ca44ee990554094df6de440386a440a5bd99106e048939409d63beb423", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/golangci/lint-1/com_github_golangci_lint_1-v0.0.0-20181222135242-d2cdd8c08219.zip": "2806ffd1a35b26a29b4cea86eb5ae421636b317e33e261fc1c20f9cf8fec2db5", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/gomodule/redigo/com_github_gomodule_redigo-v1.7.1-0.20190724094224-574c33c3df38.zip": "f665942b590c65e87284d681ea2784d0b9873c644756f4716a9972dc0d8e804e", @@ -881,12 +882,12 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prashantv/protectmem/com_github_prashantv_protectmem-v0.0.0-20171002184600-e20412882b3a.zip": "53d930afbb812eb68b665dcbd96ac371ff600c8821cf5e43628ab283457881e9", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/pressly/goose/v3/com_github_pressly_goose_v3-v3.5.3.zip": "0f0c74470d454d3530f6b7da4007a3b27beb38b9b059badd98715dc88f535f6f", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/alertmanager/com_github_prometheus_alertmanager-v0.23.0.zip": "1c51abe35f12ebc11de46e0d888c93fe8e85b146ced1c2ab2a49dd97cf2b1c6a", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_golang/com_github_prometheus_client_golang-v1.12.1.zip": "d9bbfcdcb5f63812b6766884a0f5ad5b1f9a675375d28e307573f49e2ef96b7b", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_model/com_github_prometheus_client_model-v0.2.1-0.20210607210712-147c58e9608a.zip": "44fc58fe25ed9b122b6755e8d356d5f199592f959af3b87a3b636c6eb82b43c5", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/common/com_github_prometheus_common-v0.32.1.zip": "9630b9bbfcf1746a01c8aff0262271c60cf891fa1cd48a8ed9149de557dc98d6", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_golang/com_github_prometheus_client_golang-v1.16.0.zip": "0167cee686b836da39815e4a7ea64ecc245f6a3fb9b3c3f729941ed55da7dd4f", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/client_model/com_github_prometheus_client_model-v0.3.0.zip": "2a1d147754959287fc34a7bb7c333b3d6fe0ca0d7db1606c49e8f48fd0311547", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/common/com_github_prometheus_common-v0.42.0.zip": "7a4ef12402a8a153c47c085cadf362bdc2ffe4761e50d6ab2c49e4d64044bc85", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/common/sigv4/com_github_prometheus_common_sigv4-v0.1.0.zip": "e76ec796837158dc2624343f88da4ba3c5d9d4b45e66b359358eba5db39846dd", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/exporter-toolkit/com_github_prometheus_exporter_toolkit-v0.6.1.zip": "bac6a6c26e51c687abaf14e06b4a99eaa876380d917ff6b9bce38461ee4f95aa", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/procfs/com_github_prometheus_procfs-v0.7.3.zip": "3e37c9f62738a493dd28283179d802749050353df0bca161df7cec4ed43e6f1a", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/procfs/com_github_prometheus_procfs-v0.10.1.zip": "3f7a5c30bbcd2adcc7ec62896b69a3792ca1603cf0998fa06d2b872a74ed13b0", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/prometheus/com_github_prometheus_prometheus-v1.8.2-0.20210914090109-37468d88dce8.zip": "934ceb931a2f3065c3aae015afcb49a9ed52043dfe29ae41a3a3e6299db1448a", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/statsd_exporter/com_github_prometheus_statsd_exporter-v0.21.0.zip": "aa848ade6fb019df4f7992808a1d6aa48d6b8276017970af4aabc1bd337c2dc3", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/prometheus/tsdb/com_github_prometheus_tsdb-v0.7.1.zip": "360ce38297a00439c4bfbbded7b750f6d45582d581cde70572a003bcbc8b0c7b", @@ -1003,6 +1004,7 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xeipuuv/gojsonpointer/com_github_xeipuuv_gojsonpointer-v0.0.0-20190905194746-02993c407bfb.zip": "11b54f0bc358b09261075c3e15cd14d57102f3ab1ba88c345c53eab6aaf228de", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xeipuuv/gojsonreference/com_github_xeipuuv_gojsonreference-v0.0.0-20180127040603-bd5ef7bd5415.zip": "7ec98f4df894413f4dc58c8df330ca8b24ff425b05a8e1074c3028c99f7e45e7", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xeipuuv/gojsonschema/com_github_xeipuuv_gojsonschema-v1.2.0.zip": "55c8ce068257aa0d263aad7470113dafcd50f955ee754fc853c2fdcd31ad096f", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xhit/go-str2duration/com_github_xhit_go_str2duration-v1.2.0.zip": "87df7da9ed9a48a2da6b3df14d33a567a9e6ed2454e4cbd694baa7ec82ca7ec1", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xiang90/probing/com_github_xiang90_probing-v0.0.0-20190116061207-43a291ad63a2.zip": "437bdc666239fda4581b592b068001f08269c68c70699a721bff9334412d4181", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xlab/treeprint/com_github_xlab_treeprint-v1.1.0.zip": "4334f3a6e37e92cdd18688a59710663a0f3bff61b225f236fa1be8875e483152", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/xordataexchange/crypt/com_github_xordataexchange_crypt-v0.0.3-0.20170626215501-b2862e3d0a77.zip": "46dc29ef77d77a2bc3e7bd70c94dbaeec0062dd3bd6fcacbaab785c15dcd625b", @@ -1061,7 +1063,7 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/net/org_golang_x_net-v0.10.0.zip": "f92f9b2655226a6d015af7a76279a11fb55678e410b851b158fc846546f80733", "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/oauth2/org_golang_x_oauth2-v0.5.0.zip": "4d9d9ce8d2f55b7d2ffb3697ed811a54606e881bb7fbbd84d3d9c42fc404ae3c", "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/perf/org_golang_x_perf-v0.0.0-20230113213139-801c7ef9e5c5.zip": "bc1b902e645fdd5d210b7db8f3280833af225b131dab5842d7a6d32a676f80f5", - "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/sync/org_golang_x_sync-v0.1.0.zip": "f510bec6009e19882d19953e7273137d34df86c65949345d72f123a255c2ecd2", + "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/sync/org_golang_x_sync-v0.2.0.zip": "ee0df4572dd73665767964ff809b12f0d41e3a0740220d44d418a19989a0363b", "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/sys/org_golang_x_sys-v0.8.0.zip": "2588b3a645838390e341f1007f8679f5e1117b5d5ac9467ef832d148b2219a38", "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/term/org_golang_x_term-v0.8.0.zip": "1961dfea59ce531e2d6e6a3228781f5958b27c6d9d9c09932f5ffc54c4d9cdf9", "https://storage.googleapis.com/cockroach-godeps/gomod/golang.org/x/text/org_golang_x_text-v0.9.0.zip": "c1cbe684eaf01c053bf1232738697d1040327a5c8ad62dadfc950b585d1b4caa", diff --git a/go.mod b/go.mod index afc1333fe14e..ad6d27e19192 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/gogo/protobuf v1.3.2 github.com/golang/geo v0.0.0-20200319012246-673a6f80352d github.com/golang/mock v1.6.0 - github.com/golang/protobuf v1.5.2 + github.com/golang/protobuf v1.5.3 github.com/golang/snappy v0.0.4 github.com/google/btree v1.0.1 github.com/google/pprof v0.0.0-20210827144239-02619b876842 @@ -22,7 +22,7 @@ require ( golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.10.0 golang.org/x/oauth2 v0.5.0 - golang.org/x/sync v0.1.0 + golang.org/x/sync v0.2.0 golang.org/x/sys v0.8.0 golang.org/x/text v0.9.0 golang.org/x/time v0.1.0 @@ -30,7 +30,7 @@ require ( google.golang.org/api v0.110.0 google.golang.org/genproto v0.0.0-20230227214838-9b19f0bdc514 google.golang.org/grpc v1.53.0 - google.golang.org/protobuf v1.28.1 + google.golang.org/protobuf v1.30.0 ) // If any of the following dependencies get updated as a side-effect @@ -198,9 +198,9 @@ require ( github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 github.com/pressly/goose/v3 v3.5.3 - github.com/prometheus/client_golang v1.12.1 - github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a - github.com/prometheus/common v0.32.1 + github.com/prometheus/client_golang v1.16.0 + github.com/prometheus/client_model v0.3.0 + github.com/prometheus/common v0.42.0 github.com/prometheus/prometheus v1.8.2-0.20210914090109-37468d88dce8 github.com/pseudomuto/protoc-gen-doc v1.3.2 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 @@ -285,7 +285,7 @@ require ( github.com/fatih/structs v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.1 // indirect github.com/ghodss/yaml v1.0.0 // indirect - github.com/go-kit/log v0.1.0 // indirect + github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-logr/logr v1.2.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -369,7 +369,7 @@ require ( github.com/pkg/profile v1.6.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/pquerna/cachecontrol v0.0.0-20200921180117-858c6e7e6b7e // indirect - github.com/prometheus/procfs v0.7.3 // indirect + github.com/prometheus/procfs v0.10.1 // indirect github.com/pseudomuto/protokit v0.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect @@ -444,3 +444,5 @@ replace gopkg.in/yaml.v2 => github.com/cockroachdb/yaml v0.0.0-20210825132133-2d replace github.com/docker/docker => github.com/moby/moby v20.10.6+incompatible replace golang.org/x/time => github.com/cockroachdb/x-time v0.3.1-0.20230525123634-71747adb5d5c + +replace google.golang.org/protobuf => google.golang.org/protobuf v1.28.1 diff --git a/go.sum b/go.sum index 75c3ac4d0080..46a97c3805f9 100644 --- a/go.sum +++ b/go.sum @@ -264,8 +264,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 h1:AUNCr9CiJuwrRYS3XieqF+Z9B9gNxo/eANAJCF2eiN4= github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= +github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA= @@ -831,8 +831,9 @@ github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3I github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= -github.com/go-kit/log v0.1.0 h1:DGJh0Sm43HbOeYDNnVZFl8BvcYVvjD5bqYJvp0REbwQ= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= +github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U= github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -1096,18 +1097,15 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -1981,8 +1979,8 @@ github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= -github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= +github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= @@ -1990,8 +1988,8 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a h1:CmF68hwI0XsOQ5UwlBopMi2Ow4Pbg32akc4KIVCOm+Y= -github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= +github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/common v0.0.0-20180110214958-89604d197083/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= @@ -2005,8 +2003,8 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8 github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/common v0.30.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= -github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= -github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= +github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4= github.com/prometheus/common/sigv4 v0.1.0/go.mod h1:2Jkxxk9yYvCkE5G1sQT7GuEXm57JrvHu9k5YwTjsNtI= github.com/prometheus/exporter-toolkit v0.6.1/go.mod h1:ZUBIj498ePooX9t/2xtDjeQYwvRpiPP2lh5u4iblj2g= @@ -2025,8 +2023,8 @@ github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4 github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= -github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= +github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/prometheus/prometheus v0.0.0-20200609090129-a6600f564e3c/go.mod h1:S5n0C6tSgdnwWshBUceRx5G1OsjLv/EeZ9t3wIfEtsY= github.com/prometheus/prometheus v1.8.2-0.20210914090109-37468d88dce8 h1:U8ZpFGP11pZi0ZavWWGeAqck3dVT9AY6zbr4fbBftjA= github.com/prometheus/prometheus v1.8.2-0.20210914090109-37468d88dce8/go.mod h1:02eURgmH1YsgJ2TtWNUGMQMCnLxmtHH9nOgvYxIjGAo= @@ -2641,8 +2639,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -2776,7 +2774,6 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -3095,20 +3092,6 @@ google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwS google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/grpc/examples v0.0.0-20210324172016-702608ffae4d h1:CJP00gEaaYNJuaTXEg456rWNC1oUOfiAiUjuwyAhEmM= google.golang.org/grpc/examples v0.0.0-20210324172016-702608ffae4d/go.mod h1:Ly7ZA/ARzg8fnPU9TyZIxoz33sEUuWX7txiqs8lPTgE= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/DataDog/dd-trace-go.v1 v1.17.0/go.mod h1:DVp8HmDh8PuTu2Z0fVVlBsyWaC++fzwVCaGWylTe3tg= diff --git a/pkg/ccl/sqlproxyccl/BUILD.bazel b/pkg/ccl/sqlproxyccl/BUILD.bazel index bde927661aee..cf2f22edc894 100644 --- a/pkg/ccl/sqlproxyccl/BUILD.bazel +++ b/pkg/ccl/sqlproxyccl/BUILD.bazel @@ -49,6 +49,7 @@ go_library( "@com_github_cockroachdb_logtags//:logtags", "@com_github_jackc_pgproto3_v2//:pgproto3", "@com_github_pires_go_proxyproto//:go-proxyproto", + "@com_github_prometheus_common//expfmt", "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//codes", "@org_golang_google_grpc//credentials/insecure", diff --git a/pkg/ccl/sqlproxyccl/server.go b/pkg/ccl/sqlproxyccl/server.go index deec01a6cd95..279635754e83 100644 --- a/pkg/ccl/sqlproxyccl/server.go +++ b/pkg/ccl/sqlproxyccl/server.go @@ -25,6 +25,7 @@ import ( "github.com/cockroachdb/errors" "github.com/cockroachdb/logtags" proxyproto "github.com/pires/go-proxyproto" + "github.com/prometheus/common/expfmt" ) var ( @@ -106,11 +107,12 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) { } func (s *Server) handleVars(w http.ResponseWriter, r *http.Request) { - w.Header().Set(httputil.ContentTypeHeader, httputil.PlaintextContentType) + contentType := expfmt.Negotiate(r.Header) + w.Header().Set(httputil.ContentTypeHeader, string(contentType)) scrape := func(pm *metric.PrometheusExporter) { pm.ScrapeRegistry(s.metricsRegistry, true /* includeChildMetrics*/) } - if err := s.prometheusExporter.ScrapeAndPrintAsText(w, scrape); err != nil { + if err := s.prometheusExporter.ScrapeAndPrintAsText(w, contentType, scrape); err != nil { log.Errorf(r.Context(), "%v", err) http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/pkg/cmd/roachtest/clusterstats/mocks_generated_test.go b/pkg/cmd/roachtest/clusterstats/mocks_generated_test.go index 087a6ea93dbb..ab751cf0f691 100644 --- a/pkg/cmd/roachtest/clusterstats/mocks_generated_test.go +++ b/pkg/cmd/roachtest/clusterstats/mocks_generated_test.go @@ -38,9 +38,13 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { } // Query mocks base method. -func (m *MockClient) Query(arg0 context.Context, arg1 string, arg2 time.Time) (model.Value, v1.Warnings, error) { +func (m *MockClient) Query(arg0 context.Context, arg1 string, arg2 time.Time, arg3 ...v1.Option) (model.Value, v1.Warnings, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Query", arg0, arg1, arg2) + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Query", varargs...) ret0, _ := ret[0].(model.Value) ret1, _ := ret[1].(v1.Warnings) ret2, _ := ret[2].(error) @@ -48,15 +52,20 @@ func (m *MockClient) Query(arg0 context.Context, arg1 string, arg2 time.Time) (m } // Query indicates an expected call of Query. -func (mr *MockClientMockRecorder) Query(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) Query(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockClient)(nil).Query), arg0, arg1, arg2) + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockClient)(nil).Query), varargs...) } // QueryRange mocks base method. -func (m *MockClient) QueryRange(arg0 context.Context, arg1 string, arg2 v1.Range) (model.Value, v1.Warnings, error) { +func (m *MockClient) QueryRange(arg0 context.Context, arg1 string, arg2 v1.Range, arg3 ...v1.Option) (model.Value, v1.Warnings, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryRange", arg0, arg1, arg2) + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "QueryRange", varargs...) ret0, _ := ret[0].(model.Value) ret1, _ := ret[1].(v1.Warnings) ret2, _ := ret[2].(error) @@ -64,7 +73,8 @@ func (m *MockClient) QueryRange(arg0 context.Context, arg1 string, arg2 v1.Range } // QueryRange indicates an expected call of QueryRange. -func (mr *MockClientMockRecorder) QueryRange(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) QueryRange(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRange", reflect.TypeOf((*MockClient)(nil).QueryRange), arg0, arg1, arg2) + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRange", reflect.TypeOf((*MockClient)(nil).QueryRange), varargs...) } diff --git a/pkg/cmd/roachtest/tests/drt_generated_test.go b/pkg/cmd/roachtest/tests/drt_generated_test.go index 1a4ffe1b74c6..68b021e4054a 100644 --- a/pkg/cmd/roachtest/tests/drt_generated_test.go +++ b/pkg/cmd/roachtest/tests/drt_generated_test.go @@ -38,9 +38,13 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { } // Query mocks base method. -func (m *MockClient) Query(arg0 context.Context, arg1 string, arg2 time.Time) (model.Value, v1.Warnings, error) { +func (m *MockClient) Query(arg0 context.Context, arg1 string, arg2 time.Time, arg3 ...v1.Option) (model.Value, v1.Warnings, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Query", arg0, arg1, arg2) + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Query", varargs...) ret0, _ := ret[0].(model.Value) ret1, _ := ret[1].(v1.Warnings) ret2, _ := ret[2].(error) @@ -48,15 +52,20 @@ func (m *MockClient) Query(arg0 context.Context, arg1 string, arg2 time.Time) (m } // Query indicates an expected call of Query. -func (mr *MockClientMockRecorder) Query(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) Query(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockClient)(nil).Query), arg0, arg1, arg2) + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockClient)(nil).Query), varargs...) } // QueryRange mocks base method. -func (m *MockClient) QueryRange(arg0 context.Context, arg1 string, arg2 v1.Range) (model.Value, v1.Warnings, error) { +func (m *MockClient) QueryRange(arg0 context.Context, arg1 string, arg2 v1.Range, arg3 ...v1.Option) (model.Value, v1.Warnings, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryRange", arg0, arg1, arg2) + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "QueryRange", varargs...) ret0, _ := ret[0].(model.Value) ret1, _ := ret[1].(v1.Warnings) ret2, _ := ret[2].(error) @@ -64,7 +73,8 @@ func (m *MockClient) QueryRange(arg0 context.Context, arg1 string, arg2 v1.Range } // QueryRange indicates an expected call of QueryRange. -func (mr *MockClientMockRecorder) QueryRange(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) QueryRange(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRange", reflect.TypeOf((*MockClient)(nil).QueryRange), arg0, arg1, arg2) + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRange", reflect.TypeOf((*MockClient)(nil).QueryRange), varargs...) } diff --git a/pkg/kv/kvserver/BUILD.bazel b/pkg/kv/kvserver/BUILD.bazel index dc9c923f9ba5..3907314e4cb4 100644 --- a/pkg/kv/kvserver/BUILD.bazel +++ b/pkg/kv/kvserver/BUILD.bazel @@ -512,6 +512,7 @@ go_test( "@com_github_kr_pretty//:pretty", "@com_github_lib_pq//:pq", "@com_github_olekukonko_tablewriter//:tablewriter", + "@com_github_prometheus_common//expfmt", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@io_etcd_go_raft_v3//:raft", diff --git a/pkg/kv/kvserver/client_tenant_test.go b/pkg/kv/kvserver/client_tenant_test.go index ff54171735dd..5590679ecb4d 100644 --- a/pkg/kv/kvserver/client_tenant_test.go +++ b/pkg/kv/kvserver/client_tenant_test.go @@ -45,6 +45,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/timeutil" "github.com/cockroachdb/cockroach/pkg/util/uuid" "github.com/cockroachdb/errors" + "github.com/prometheus/common/expfmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -103,7 +104,7 @@ func TestTenantsStorageMetricsOnSplit(t *testing.T) { ex.ScrapeRegistry(store.Registry(), true /* includeChildMetrics */) } var in bytes.Buffer - if err := ex.ScrapeAndPrintAsText(&in, scrape); err != nil { + if err := ex.ScrapeAndPrintAsText(&in, expfmt.FmtText, scrape); err != nil { t.Fatalf("failed to print prometheus data: %v", err) } if seen != 2 { diff --git a/pkg/roachprod/prometheus/prometheus.go b/pkg/roachprod/prometheus/prometheus.go index 22a59af72a24..14b5b4adfcb8 100644 --- a/pkg/roachprod/prometheus/prometheus.go +++ b/pkg/roachprod/prometheus/prometheus.go @@ -31,8 +31,8 @@ const defaultWorkloadPort = 2112 // Client is an interface allowing queries against Prometheus. type Client interface { - Query(ctx context.Context, query string, ts time.Time) (model.Value, promv1.Warnings, error) - QueryRange(ctx context.Context, query string, r promv1.Range) (model.Value, promv1.Warnings, error) + Query(ctx context.Context, query string, ts time.Time, opts ...promv1.Option) (model.Value, promv1.Warnings, error) + QueryRange(ctx context.Context, query string, r promv1.Range, opts ...promv1.Option) (model.Value, promv1.Warnings, error) } // ScrapeNode is a node to scrape from. diff --git a/pkg/server/BUILD.bazel b/pkg/server/BUILD.bazel index 7ffb9cb9e678..c4ee4dc5c8a7 100644 --- a/pkg/server/BUILD.bazel +++ b/pkg/server/BUILD.bazel @@ -361,6 +361,7 @@ go_library( "@com_github_marusama_semaphore//:semaphore", "@com_github_nightlyone_lockfile//:lockfile", "@com_github_nytimes_gziphandler//:gziphandler", + "@com_github_prometheus_common//expfmt", "@in_gopkg_yaml_v2//:yaml_v2", "@io_etcd_go_raft_v3//:raft", "@org_golang_google_grpc//:go_default_library", diff --git a/pkg/server/load_endpoint.go b/pkg/server/load_endpoint.go index 16b410c887c2..df013c862023 100644 --- a/pkg/server/load_endpoint.go +++ b/pkg/server/load_endpoint.go @@ -23,6 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/metric" "github.com/cockroachdb/cockroach/pkg/util/timeutil" "github.com/cockroachdb/errors" + "github.com/prometheus/common/expfmt" ) var ( @@ -112,13 +113,15 @@ func (le *loadEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) { le.cpuNowNanos.Update(timeutil.Now().UnixNano()) le.uptimeSeconds.Update(float64(timeutil.Now().UnixNano()-le.initTimeNanos) / 1e9) - if err := le.exporterLoad.ScrapeAndPrintAsText(w, le.scrapeLoadVarsIntoPrometheus); err != nil { + contentType := expfmt.Negotiate(r.Header) + + if err := le.exporterLoad.ScrapeAndPrintAsText(w, contentType, le.scrapeLoadVarsIntoPrometheus); err != nil { log.Errorf(r.Context(), "%v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } - if err := le.exporterVars.ScrapeAndPrintAsText(w, le.mainMetricSource.ScrapeIntoPrometheus); err != nil { + if err := le.exporterVars.ScrapeAndPrintAsText(w, contentType, le.mainMetricSource.ScrapeIntoPrometheus); err != nil { log.Errorf(r.Context(), "%v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/pkg/server/load_endpoint_test.go b/pkg/server/load_endpoint_test.go index 9a3ebce0671f..4ccafb98b506 100644 --- a/pkg/server/load_endpoint_test.go +++ b/pkg/server/load_endpoint_test.go @@ -29,9 +29,9 @@ import ( type testMetricSource struct{} -func (t testMetricSource) MarshalJSON() ([]byte, error) { return nil, nil } -func (t testMetricSource) PrintAsText(writer io.Writer) error { return nil } -func (t testMetricSource) ScrapeIntoPrometheus(pm *metric.PrometheusExporter) {} +func (t testMetricSource) MarshalJSON() ([]byte, error) { return nil, nil } +func (t testMetricSource) PrintAsText(writer io.Writer, contentType expfmt.Format) error { return nil } +func (t testMetricSource) ScrapeIntoPrometheus(pm *metric.PrometheusExporter) {} func extractPrometheusMetrics( t *testing.T, w *httptest.ResponseRecorder, diff --git a/pkg/server/status.go b/pkg/server/status.go index 184e166aca91..1de257ba7f5d 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -88,6 +88,7 @@ import ( "github.com/cockroachdb/errors" "github.com/google/pprof/profile" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/prometheus/common/expfmt" raft "go.etcd.io/raft/v3" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -115,7 +116,7 @@ var ( type metricMarshaler interface { json.Marshaler - PrintAsText(io.Writer) error + PrintAsText(io.Writer, expfmt.Format) error ScrapeIntoPrometheus(pm *metric.PrometheusExporter) } @@ -2191,8 +2192,9 @@ type varsHandler struct { func (h varsHandler) handleVars(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - w.Header().Set(httputil.ContentTypeHeader, httputil.PlaintextContentType) - err := h.metricSource.PrintAsText(w) + contentType := expfmt.Negotiate(r.Header) + w.Header().Set(httputil.ContentTypeHeader, string(contentType)) + err := h.metricSource.PrintAsText(w, contentType) if err != nil { log.Errorf(ctx, "%v", err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/pkg/server/status/BUILD.bazel b/pkg/server/status/BUILD.bazel index b5fbb8d85187..38642a1bf9f8 100644 --- a/pkg/server/status/BUILD.bazel +++ b/pkg/server/status/BUILD.bazel @@ -75,6 +75,7 @@ go_library( "@com_github_dustin_go_humanize//:go-humanize", "@com_github_elastic_gosigar//:gosigar", "@com_github_prometheus_client_model//go", + "@com_github_prometheus_common//expfmt", "@com_github_shirou_gopsutil_v3//cpu", "@com_github_shirou_gopsutil_v3//net", ] + select({ @@ -161,6 +162,7 @@ go_test( "//pkg/util/timeutil", "@com_github_kr_pretty//:pretty", "@com_github_prometheus_client_model//go", + "@com_github_prometheus_common//expfmt", "@com_github_shirou_gopsutil_v3//net", "@com_github_stretchr_testify//require", ], diff --git a/pkg/server/status/recorder.go b/pkg/server/status/recorder.go index 2cda3c054a98..eb8264e0ce38 100644 --- a/pkg/server/status/recorder.go +++ b/pkg/server/status/recorder.go @@ -56,6 +56,7 @@ import ( "github.com/dustin/go-humanize" "github.com/elastic/gosigar" prometheusgo "github.com/prometheus/client_model/go" + "github.com/prometheus/common/expfmt" ) const ( @@ -323,9 +324,9 @@ func (mr *MetricsRecorder) ScrapeIntoPrometheus(pm *metric.PrometheusExporter) { // PrintAsText writes the current metrics values as plain-text to the writer. // We write metrics to a temporary buffer which is then copied to the writer. // This is to avoid hanging requests from holding the lock. -func (mr *MetricsRecorder) PrintAsText(w io.Writer) error { +func (mr *MetricsRecorder) PrintAsText(w io.Writer, contentType expfmt.Format) error { var buf bytes.Buffer - if err := mr.prometheusExporter.ScrapeAndPrintAsText(&buf, mr.ScrapeIntoPrometheus); err != nil { + if err := mr.prometheusExporter.ScrapeAndPrintAsText(&buf, contentType, mr.ScrapeIntoPrometheus); err != nil { return err } _, err := buf.WriteTo(w) diff --git a/pkg/server/status/recorder_test.go b/pkg/server/status/recorder_test.go index 4dfdd93d9a90..53ff1ff2a515 100644 --- a/pkg/server/status/recorder_test.go +++ b/pkg/server/status/recorder_test.go @@ -37,6 +37,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/timeutil" "github.com/kr/pretty" prometheusgo "github.com/prometheus/client_model/go" + "github.com/prometheus/common/expfmt" "github.com/stretchr/testify/require" ) @@ -159,14 +160,14 @@ func TestMetricsRecorderLabels(t *testing.T) { recorder.AddTenantRegistry(tenantID, regTenant) buf := bytes.NewBuffer([]byte{}) - err = recorder.PrintAsText(buf) + err = recorder.PrintAsText(buf, expfmt.FmtText) require.NoError(t, err) require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="system"} 123`) require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="application"} 456`) bufTenant := bytes.NewBuffer([]byte{}) - err = recorderTenant.PrintAsText(bufTenant) + err = recorderTenant.PrintAsText(bufTenant, expfmt.FmtText) require.NoError(t, err) require.NotContains(t, bufTenant.String(), `some_metric{node_id="7",tenant="system"} 123`) @@ -177,14 +178,14 @@ func TestMetricsRecorderLabels(t *testing.T) { appNameContainer.Set("application2") buf = bytes.NewBuffer([]byte{}) - err = recorder.PrintAsText(buf) + err = recorder.PrintAsText(buf, expfmt.FmtText) require.NoError(t, err) require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="system"} 123`) require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="application2"} 456`) bufTenant = bytes.NewBuffer([]byte{}) - err = recorderTenant.PrintAsText(bufTenant) + err = recorderTenant.PrintAsText(bufTenant, expfmt.FmtText) require.NoError(t, err) require.NotContains(t, bufTenant.String(), `some_metric{node_id="7",tenant="system"} 123`) @@ -694,7 +695,7 @@ func TestMetricsRecorder(t *testing.T) { if _, err := recorder.MarshalJSON(); err != nil { t.Error(err) } - _ = recorder.PrintAsText(io.Discard) + _ = recorder.PrintAsText(io.Discard, expfmt.FmtText) _ = recorder.GetTimeSeriesData() wg.Done() }() diff --git a/pkg/testutils/metrictestutils/BUILD.bazel b/pkg/testutils/metrictestutils/BUILD.bazel index 3070d18c5eff..07f701807a56 100644 --- a/pkg/testutils/metrictestutils/BUILD.bazel +++ b/pkg/testutils/metrictestutils/BUILD.bazel @@ -6,5 +6,8 @@ go_library( srcs = ["metrics_text.go"], importpath = "github.com/cockroachdb/cockroach/pkg/testutils/metrictestutils", visibility = ["//visibility:public"], - deps = ["//pkg/util/metric"], + deps = [ + "//pkg/util/metric", + "@com_github_prometheus_common//expfmt", + ], ) diff --git a/pkg/testutils/metrictestutils/metrics_text.go b/pkg/testutils/metrictestutils/metrics_text.go index baf3718d4c8d..cb45b5166dd5 100644 --- a/pkg/testutils/metrictestutils/metrics_text.go +++ b/pkg/testutils/metrictestutils/metrics_text.go @@ -18,6 +18,7 @@ import ( "strings" "github.com/cockroachdb/cockroach/pkg/util/metric" + "github.com/prometheus/common/expfmt" ) // GetMetricsText scrapes a metrics registry, filters out the metrics according @@ -28,7 +29,7 @@ func GetMetricsText(registry *metric.Registry, re *regexp.Regexp) (string, error ex.ScrapeRegistry(registry, true /* includeChildMetrics */) } var in bytes.Buffer - if err := ex.ScrapeAndPrintAsText(&in, scrape); err != nil { + if err := ex.ScrapeAndPrintAsText(&in, expfmt.FmtText, scrape); err != nil { return "", err } sc := bufio.NewScanner(&in) diff --git a/pkg/util/metric/BUILD.bazel b/pkg/util/metric/BUILD.bazel index 182865a142fd..b46e0d266850 100644 --- a/pkg/util/metric/BUILD.bazel +++ b/pkg/util/metric/BUILD.bazel @@ -62,6 +62,7 @@ go_test( "@com_github_kr_pretty//:pretty", "@com_github_prometheus_client_golang//prometheus", "@com_github_prometheus_client_model//go", + "@com_github_prometheus_common//expfmt", "@com_github_stretchr_testify//require", ], ) diff --git a/pkg/util/metric/aggmetric/BUILD.bazel b/pkg/util/metric/aggmetric/BUILD.bazel index 9e9a82252b2d..4cb9d8695ca7 100644 --- a/pkg/util/metric/aggmetric/BUILD.bazel +++ b/pkg/util/metric/aggmetric/BUILD.bazel @@ -35,6 +35,7 @@ go_test( "//pkg/util/leaktest", "//pkg/util/metric", "@com_github_prometheus_client_model//go", + "@com_github_prometheus_common//expfmt", "@com_github_stretchr_testify//require", ], ) diff --git a/pkg/util/metric/aggmetric/agg_metric_test.go b/pkg/util/metric/aggmetric/agg_metric_test.go index 61b8e9885d9f..7af1612f8af9 100644 --- a/pkg/util/metric/aggmetric/agg_metric_test.go +++ b/pkg/util/metric/aggmetric/agg_metric_test.go @@ -25,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/metric" "github.com/cockroachdb/cockroach/pkg/util/metric/aggmetric" prometheusgo "github.com/prometheus/client_model/go" + "github.com/prometheus/common/expfmt" "github.com/stretchr/testify/require" ) @@ -38,7 +39,7 @@ func TestAggMetric(t *testing.T) { scrape := func(ex *metric.PrometheusExporter) { ex.ScrapeRegistry(r, true /* includeChildMetrics */) } - require.NoError(t, ex.ScrapeAndPrintAsText(&in, scrape)) + require.NoError(t, ex.ScrapeAndPrintAsText(&in, expfmt.FmtText, scrape)) var lines []string for sc := bufio.NewScanner(&in); sc.Scan(); { if !bytes.HasPrefix(sc.Bytes(), []byte{'#'}) { diff --git a/pkg/util/metric/metric.go b/pkg/util/metric/metric.go index 9c62c0cf641f..9c9d291b58c7 100644 --- a/pkg/util/metric/metric.go +++ b/pkg/util/metric/metric.go @@ -206,6 +206,29 @@ func HdrEnabled() bool { return hdrEnabled } +// useNativeHistogramsEnvVar can be used to enable the Prometheus native +// histogram feature, which represents a histogram as a single time series +// rather than a collection of per-bucket counter series. If enabled, both +// conventional and native histograms are exported. +const useNativeHistogramsEnvVar = "COCKROACH_ENABLE_PROMETHEUS_NATIVE_HISTOGRAMS" + +var nativeHistogramsEnabled = envutil.EnvOrDefaultBool(useNativeHistogramsEnvVar, false) + +// nativeHistogramsBucketFactorEnvVar can be used to override the default +// bucket size exponential factor for Prometheus native histograms, if enabled. +// If not set, use the default factor of 1.1. +const nativeHistogramsBucketFactorEnvVar = "COCKROACH_PROMETHEUS_NATIVE_HISTOGRAMS_BUCKET_FACTOR" + +var nativeHistogramsBucketFactor = envutil.EnvOrDefaultFloat64(nativeHistogramsBucketFactorEnvVar, 1.1) + +// nativeHistogramsBucketCountMultiplierEnvVar can be used to override the +// default maximum bucket count for Prometheus native histograms, if enabled. +// The maximum bucket count is set to the number of conventional buckets for +// the histogram metric multiplied by the multiplier, which defaults to 1.0. +const nativeHistogramsBucketCountMultiplierEnvVar = "COCKROACH_PROMETHEUS_NATIVE_HISTOGRAMS_BUCKET_COUNT_MULTIPLIER" + +var nativeHistogramsBucketCountMultiplier = envutil.EnvOrDefaultFloat64(nativeHistogramsBucketCountMultiplierEnvVar, 1) + type HistogramMode byte const ( @@ -283,6 +306,10 @@ func newHistogram( opts := prometheus.HistogramOpts{ Buckets: buckets, } + if bucketConfig.distribution == Exponential && nativeHistogramsEnabled { + opts.NativeHistogramBucketFactor = nativeHistogramsBucketFactor + opts.NativeHistogramMaxBucketNumber = uint32(float64(len(buckets)) * nativeHistogramsBucketCountMultiplier) + } cum := prometheus.NewHistogram(opts) h := &Histogram{ Metadata: meta, diff --git a/pkg/util/metric/metric_test.go b/pkg/util/metric/metric_test.go index c58c5a79fe21..e73e138e35b0 100644 --- a/pkg/util/metric/metric_test.go +++ b/pkg/util/metric/metric_test.go @@ -194,6 +194,27 @@ func TestHistogram(t *testing.T) { require.Equal(t, 17.5, h.ValueAtQuantileWindowed(50)) require.Equal(t, 75.0, h.ValueAtQuantileWindowed(80)) require.Equal(t, 100.0, h.ValueAtQuantileWindowed(99.99)) + + // Assert that native histogram schema is not defined + require.Nil(t, h.ToPrometheusMetric().Histogram.Schema) +} + +func TestNativeHistogram(t *testing.T) { + defer func(enabled bool) { + nativeHistogramsEnabled = enabled + }(nativeHistogramsEnabled) + nativeHistogramsEnabled = true + h := NewHistogram(HistogramOptions{ + Mode: HistogramModePrometheus, + Metadata: Metadata{}, + Duration: time.Hour, + BucketConfig: staticBucketConfig{ + distribution: Exponential, + }, + }) + + // Assert that native histogram schema is defined + require.NotNil(t, h.ToPrometheusMetric().Histogram.Schema) } func TestManualWindowHistogram(t *testing.T) { diff --git a/pkg/util/metric/prometheus_exporter.go b/pkg/util/metric/prometheus_exporter.go index 5468dda217f2..a8e2951e7c04 100644 --- a/pkg/util/metric/prometheus_exporter.go +++ b/pkg/util/metric/prometheus_exporter.go @@ -111,9 +111,10 @@ func (pm *PrometheusExporter) ScrapeRegistry(registry *Registry, includeChildMet // printAsText writes all metrics in the families map to the io.Writer in // prometheus' text format. It removes individual metrics from the families // as it goes, readying the families for another found of registry additions. -func (pm *PrometheusExporter) printAsText(w io.Writer) error { +func (pm *PrometheusExporter) printAsText(w io.Writer, contentType expfmt.Format) error { + enc := expfmt.NewEncoder(w, contentType) for _, family := range pm.families { - if _, err := expfmt.MetricFamilyToText(w, family); err != nil { + if err := enc.Encode(family); err != nil { return err } } @@ -127,12 +128,12 @@ func (pm *PrometheusExporter) printAsText(w io.Writer) error { // as it goes, readying the families for another found of registry additions. // It does this under lock so it is thread safe and can be called concurrently. func (pm *PrometheusExporter) ScrapeAndPrintAsText( - w io.Writer, scrapeFunc func(*PrometheusExporter), + w io.Writer, contentType expfmt.Format, scrapeFunc func(*PrometheusExporter), ) error { pm.muScrapeAndPrint.Lock() defer pm.muScrapeAndPrint.Unlock() scrapeFunc(pm) - return pm.printAsText(w) + return pm.printAsText(w, contentType) } // Verify GraphiteExporter implements Gatherer interface. diff --git a/pkg/util/metric/prometheus_exporter_test.go b/pkg/util/metric/prometheus_exporter_test.go index f65c0e878016..3ce68cdac3cf 100644 --- a/pkg/util/metric/prometheus_exporter_test.go +++ b/pkg/util/metric/prometheus_exporter_test.go @@ -14,7 +14,9 @@ import ( "bytes" "strings" "testing" + "time" + "github.com/prometheus/common/expfmt" "github.com/stretchr/testify/require" ) @@ -122,7 +124,7 @@ func TestPrometheusExporter(t *testing.T) { // Test ScrapeAndPrintAsText var buf bytes.Buffer pe = MakePrometheusExporter() - err = pe.ScrapeAndPrintAsText(&buf, func(exporter *PrometheusExporter) { + err = pe.ScrapeAndPrintAsText(&buf, expfmt.FmtText, func(exporter *PrometheusExporter) { exporter.ScrapeRegistry(r1, true) }) require.NoError(t, err) @@ -131,3 +133,37 @@ func TestPrometheusExporter(t *testing.T) { require.Regexp(t, "shared_counter{counter=\"one\"}", output) require.Len(t, strings.Split(output, "\n"), 7) } + +func TestPrometheusExporterNativeHistogram(t *testing.T) { + defer func(enabled bool) { + nativeHistogramsEnabled = enabled + }(nativeHistogramsEnabled) + nativeHistogramsEnabled = true + r := NewRegistry() + + r.AddMetric(NewHistogram(HistogramOptions{ + Duration: time.Second, + Mode: HistogramModePrometheus, + Metadata: Metadata{ + Name: "histogram", + }, + BucketConfig: staticBucketConfig{ + distribution: Exponential, + min: 10e3, // 10µs + max: 10e9, // 10s + count: 60, + }, + })) + + var buf bytes.Buffer + pe := MakePrometheusExporter() + // Print metrics as proto text, since native histograms aren't yet supported. + // in the prometheus text exposition format. + err := pe.ScrapeAndPrintAsText(&buf, expfmt.FmtProtoText, func(exporter *PrometheusExporter) { + exporter.ScrapeRegistry(r, false) + }) + require.NoError(t, err) + output := buf.String() + // Assert that output contains the native histogram schema. + require.Regexp(t, "schema: 3", output) +}