From 7b6bba40d25c33a7b6edd0c485c3385edf3e6349 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 1 Jan 2024 20:40:24 +0100 Subject: [PATCH] Update build (#291) * Update Go to 1.21. * Update Prometheus Go libraries. * Remove unused test_matchers package. The `test_matchers` package seems to be a variation of `github.com/prometheus/client_golang/testutil`. It doesn't appear to be used in any code and is now broken due to the created timestamp functionality in the string matching. Signed-off-by: SuperQ --- .circleci/config.yml | 2 +- .golangci.yml | 3 - .promu.yml | 3 +- go.mod | 13 +- go.sum | 27 ++- .../prometheus_metric_matcher.go | 65 ------ .../prometheus_metric_matcher_test.go | 200 ------------------ .../test_matchers/test_matchers_suite_test.go | 26 --- 8 files changed, 20 insertions(+), 319 deletions(-) delete mode 100644 utils/test_matchers/prometheus_metric_matcher.go delete mode 100644 utils/test_matchers/prometheus_metric_matcher_test.go delete mode 100644 utils/test_matchers/test_matchers_suite_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index a6895375..b6c792b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ executors: # This must match .promu.yml. golang: docker: - - image: cimg/go:1.20 + - image: cimg/go:1.21 jobs: test: executor: golang diff --git a/.golangci.yml b/.golangci.yml index 627ad042..1e676f3f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,9 +10,6 @@ issues: - path: _test.go linters: - errcheck - - path: utils/test_matchers - linters: - - errcheck linters-settings: errcheck: diff --git a/.promu.yml b/.promu.yml index d9ae74e7..0d73ba19 100644 --- a/.promu.yml +++ b/.promu.yml @@ -1,12 +1,11 @@ go: # This must match .circle/config.yml. - version: 1.20 + version: 1.21 repository: path: github.com/prometheus-community/stackdriver_exporter build: binaries: - name: stackdriver_exporter - flags: -a -tags 'netgo static_build' ldflags: | -X github.com/prometheus/common/version.Version={{.Version}} -X github.com/prometheus/common/version.Revision={{.Revision}} diff --git a/go.mod b/go.mod index 74e5cc80..02a198f4 100644 --- a/go.mod +++ b/go.mod @@ -9,10 +9,9 @@ require ( github.com/go-kit/log v0.2.1 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.30.0 - github.com/prometheus/client_golang v1.16.0 - github.com/prometheus/client_model v0.4.0 - github.com/prometheus/common v0.44.0 - github.com/prometheus/exporter-toolkit v0.10.0 + github.com/prometheus/client_golang v1.18.0 + github.com/prometheus/common v0.45.0 + github.com/prometheus/exporter-toolkit v0.11.0 golang.org/x/net v0.19.0 golang.org/x/oauth2 v0.15.0 google.golang.org/api v0.152.0 @@ -35,11 +34,11 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect - github.com/kr/text v0.2.0 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/nxadm/tail v1.4.8 // indirect - github.com/prometheus/procfs v0.10.1 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/xhit/go-str2duration/v2 v2.1.0 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.17.0 // indirect diff --git a/go.sum b/go.sum index d941cb37..89c5c78f 100644 --- a/go.sum +++ b/go.sum @@ -23,7 +23,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -88,9 +87,8 @@ github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2E github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -107,17 +105,17 @@ github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -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_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= -github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= -github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= -github.com/prometheus/exporter-toolkit v0.10.0 h1:yOAzZTi4M22ZzVxD+fhy1URTuNRj/36uQJJ5S8IPza8= -github.com/prometheus/exporter-toolkit v0.10.0/go.mod h1:+sVFzuvV5JDyw+Ih6p3zFxZNVnKQa3x5qPmDSiPu4ZY= -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/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= +github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g= +github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -163,7 +161,6 @@ golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ= golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= diff --git a/utils/test_matchers/prometheus_metric_matcher.go b/utils/test_matchers/prometheus_metric_matcher.go deleted file mode 100644 index 201b737c..00000000 --- a/utils/test_matchers/prometheus_metric_matcher.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2020 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package test_matchers - -import ( - "fmt" - "reflect" - - "github.com/onsi/gomega/format" - "github.com/onsi/gomega/types" - - "github.com/prometheus/client_golang/prometheus" - dto "github.com/prometheus/client_model/go" -) - -func PrometheusMetric(expected prometheus.Metric) types.GomegaMatcher { - expectedMetric := &dto.Metric{} - expected.Write(expectedMetric) - - return &PrometheusMetricMatcher{ - Expected: expectedMetric, - } -} - -type PrometheusMetricMatcher struct { - Expected *dto.Metric -} - -func (matcher *PrometheusMetricMatcher) Match(actual interface{}) (success bool, err error) { - metric, ok := actual.(prometheus.Metric) - if !ok { - return false, fmt.Errorf("PrometheusMetric matcher expects a prometheus.Metric") - } - - actualMetric := &dto.Metric{} - metric.Write(actualMetric) - - return reflect.DeepEqual(actualMetric.String(), matcher.Expected.String()), nil -} - -func (matcher *PrometheusMetricMatcher) FailureMessage(actual interface{}) (message string) { - metric, ok := actual.(prometheus.Metric) - if ok { - actualMetric := &dto.Metric{} - metric.Write(actualMetric) - return format.Message(actualMetric.String(), "to equal", matcher.Expected.String()) - } - - return format.Message(actual, "to equal", matcher.Expected) -} - -func (matcher *PrometheusMetricMatcher) NegatedFailureMessage(actual interface{}) (message string) { - return format.Message(actual, "not to equal", matcher.Expected) -} diff --git a/utils/test_matchers/prometheus_metric_matcher_test.go b/utils/test_matchers/prometheus_metric_matcher_test.go deleted file mode 100644 index 3a2451b0..00000000 --- a/utils/test_matchers/prometheus_metric_matcher_test.go +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright 2020 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package test_matchers_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "github.com/prometheus/client_golang/prometheus" - - . "github.com/prometheus-community/stackdriver_exporter/utils/test_matchers" -) - -var _ = Describe("PrometheusMetric", func() { - var ( - metricNamespace = "fake_namespace" - metricSubsystem = "fake_sybsystem" - metricName = "fake_name" - metricHelp = "Fake Metric Help" - metricLabelName = "fake_label_name" - metricLabelValue = "fake_label_value" - metricConstLabelName = "fake_constant_label_name" - metricConstLabelValue = "fake_constant_label_value" - ) - - Context("When asserting equality between Counter Metrics", func() { - It("should do the right thing", func() { - expectedMetric := prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - expectedMetric.Inc() - - actualMetric := prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - actualMetric.Inc() - - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) - }) - }) - - Context("When asserting equality between CounterVec Metrics", func() { - It("should do the right thing", func() { - expectedMetric := prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }, - []string{metricLabelName}, - ) - expectedMetric.WithLabelValues(metricLabelValue).Inc() - - actualMetric := prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }, - []string{metricLabelName}, - ) - actualMetric.WithLabelValues(metricLabelValue).Inc() - - Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue))) - }) - }) - - Context("When asserting equality between Gauge Metrics", func() { - It("should do the right thing", func() { - expectedMetric := prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - expectedMetric.Inc() - - actualMetric := prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - actualMetric.Inc() - - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) - }) - }) - - Context("When asserting equality between GaugeVec Metrics", func() { - It("should do the right thing", func() { - expectedMetric := prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }, - []string{metricLabelName}, - ) - expectedMetric.WithLabelValues(metricLabelValue).Inc() - - actualMetric := prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }, - []string{metricLabelName}, - ) - actualMetric.WithLabelValues(metricLabelValue).Inc() - - Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue))) - }) - }) - - Context("When asserting equality between Histogram Metrics", func() { - It("should do the right thing", func() { - expectedMetric := prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - expectedMetric.Observe(float64(1)) - - actualMetric := prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - actualMetric.Observe(float64(1)) - - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) - }) - }) - - Context("When asserting equality between Summary Metrics", func() { - It("should do the right thing", func() { - expectedMetric := prometheus.NewSummary( - prometheus.SummaryOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - expectedMetric.Observe(float64(1)) - - actualMetric := prometheus.NewSummary( - prometheus.SummaryOpts{ - Namespace: metricNamespace, - Subsystem: metricSubsystem, - Name: metricName, - Help: metricHelp, - ConstLabels: prometheus.Labels{metricConstLabelName: metricConstLabelValue}, - }) - actualMetric.Observe(float64(1)) - - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) - }) - }) -}) diff --git a/utils/test_matchers/test_matchers_suite_test.go b/utils/test_matchers/test_matchers_suite_test.go deleted file mode 100644 index d6a94fff..00000000 --- a/utils/test_matchers/test_matchers_suite_test.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package test_matchers_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "testing" -) - -func TestCollectors(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Test Matchers Suite") -}