From d6b08945cf52841d9a33fe7b689fc0c62c41f2d5 Mon Sep 17 00:00:00 2001 From: Suleyman Akbas Date: Mon, 18 Sep 2023 11:04:00 +0200 Subject: [PATCH] chore: remove unused metrics-exporter Signed-off-by: Suleyman Akbas --- Dockerfile | 3 - .../lvms-node-metrics_v1_service.yaml | 18 - ...nitoring.coreos.com_v1_servicemonitor.yaml | 4 +- ...s-operator-metrics-service_v1_service.yaml | 1 + .../lvms-operator.clusterserviceversion.yaml | 9 - cmd/metricsexporter/main.go | 97 ----- config/manager/manager.yaml | 9 - config/prometheus/monitor.yaml | 4 +- config/rbac/auth_proxy_service.yaml | 1 + config/rbac/kustomization.yaml | 1 - config/rbac/lvms_metric_service_config.yaml | 16 - docs/design/architecture.md | 1 - go.mod | 2 +- test/performance/operf.go | 10 - .../client_golang/prometheus/promauto/auto.go | 376 ------------------ vendor/modules.txt | 1 - 16 files changed, 7 insertions(+), 546 deletions(-) delete mode 100644 bundle/manifests/lvms-node-metrics_v1_service.yaml delete mode 100644 cmd/metricsexporter/main.go delete mode 100644 config/rbac/lvms_metric_service_config.yaml delete mode 100644 vendor/github.com/prometheus/client_golang/prometheus/promauto/auto.go diff --git a/Dockerfile b/Dockerfile index 07e887506..c881db82d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,6 @@ COPY pkg/ pkg/ # Build RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build --ldflags "-s -w" -a -o manager main.go RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build --ldflags "-s -w" -a -o vgmanager cmd/vgmanager/main.go -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build --ldflags "-s -w" -a -o metricsexporter cmd/metricsexporter/main.go # vgmanager needs 'nsenter' and other basic linux utils to correctly function FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/ubi-minimal:9.2 @@ -37,8 +36,6 @@ RUN microdnf update -y && \ WORKDIR / COPY --from=builder /workspace/manager . COPY --from=builder /workspace/vgmanager . -COPY --from=builder /workspace/metricsexporter . -EXPOSE 23532 USER 65532:65532 # '/manager' is lvm-operator entrypoint diff --git a/bundle/manifests/lvms-node-metrics_v1_service.yaml b/bundle/manifests/lvms-node-metrics_v1_service.yaml deleted file mode 100644 index 68be38378..000000000 --- a/bundle/manifests/lvms-node-metrics_v1_service.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - creationTimestamp: null - labels: - app.kubernetes.io/compose: metrics - app.kubernetes.io/part-of: lvms-provisioner - name: lvms-node-metrics -spec: - ports: - - name: lvms-metrics - port: 23532 - protocol: TCP - targetPort: 23532 - selector: - exporter: lvms-operator -status: - loadBalancer: {} diff --git a/bundle/manifests/lvms-operator-metrics-monitor_monitoring.coreos.com_v1_servicemonitor.yaml b/bundle/manifests/lvms-operator-metrics-monitor_monitoring.coreos.com_v1_servicemonitor.yaml index 4a632c7d9..3c3aeef17 100644 --- a/bundle/manifests/lvms-operator-metrics-monitor_monitoring.coreos.com_v1_servicemonitor.yaml +++ b/bundle/manifests/lvms-operator-metrics-monitor_monitoring.coreos.com_v1_servicemonitor.yaml @@ -15,8 +15,8 @@ spec: insecureSkipVerify: true - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token path: /metrics - port: lvms-metrics - scheme: http + port: https + scheme: https tlsConfig: insecureSkipVerify: true selector: diff --git a/bundle/manifests/lvms-operator-metrics-service_v1_service.yaml b/bundle/manifests/lvms-operator-metrics-service_v1_service.yaml index 0664cb619..5a4d7a1d5 100644 --- a/bundle/manifests/lvms-operator-metrics-service_v1_service.yaml +++ b/bundle/manifests/lvms-operator-metrics-service_v1_service.yaml @@ -3,6 +3,7 @@ kind: Service metadata: creationTimestamp: null labels: + app.kubernetes.io/compose: metrics app.kubernetes.io/name: lvms-operator name: lvms-operator-metrics-service spec: diff --git a/bundle/manifests/lvms-operator.clusterserviceversion.yaml b/bundle/manifests/lvms-operator.clusterserviceversion.yaml index ceda1a10a..e9e98ee3f 100644 --- a/bundle/manifests/lvms-operator.clusterserviceversion.yaml +++ b/bundle/manifests/lvms-operator.clusterserviceversion.yaml @@ -586,7 +586,6 @@ spec: app.kubernetes.io/component: lvms-operator app.kubernetes.io/name: lvms-operator app.kubernetes.io/part-of: lvms-provisioner - exporter: lvms-operator spec: containers: - args: @@ -659,14 +658,6 @@ spec: requests: cpu: 1m memory: 20Mi - - command: - - /metricsexporter - image: quay.io/lvms_dev/lvms-operator:latest - name: metricsexporter - resources: - requests: - cpu: 1m - memory: 20Mi securityContext: runAsNonRoot: true serviceAccountName: lvms-operator diff --git a/cmd/metricsexporter/main.go b/cmd/metricsexporter/main.go deleted file mode 100644 index 9dbda7bc4..000000000 --- a/cmd/metricsexporter/main.go +++ /dev/null @@ -1,97 +0,0 @@ -/* -Copyright © 2023 Red Hat, Inc. - -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 main - -import ( - "flag" - "net/http" - "os" - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/prometheus/client_golang/prometheus/promhttp" - "sigs.k8s.io/controller-runtime/pkg/log/zap" -) - -var ( - exporterNamespace string - exporterAddress string - kubeconfigPath string - kubeAPIServerURL string -) - -type lvmCollector struct{} - -func (lc *lvmCollector) Describe(c chan<- *prometheus.Desc) {} -func (lc *lvmCollector) Collect(c chan<- prometheus.Metric) {} - -func main() { - lvmExpFlags := flag.NewFlagSet("lvm-metrics-exporter", flag.ExitOnError) - lvmExpFlags.StringVar(&exporterNamespace, "namespace", "lvm-exporter", - "set the namespace of the lvm metric exporter") - lvmExpFlags.StringVar(&exporterAddress, "address", ":23532", - "address on which the metrics exporter should run") - lvmExpFlags.StringVar(&kubeconfigPath, "kubeconfig", "", "Path to kubeconfig file") - lvmExpFlags.StringVar(&kubeAPIServerURL, "apiserver", "", "API server URL") - - zapOptions := &zap.Options{} - zapOptions.BindFlags(lvmExpFlags) - - _ = lvmExpFlags.Parse(os.Args[1:]) - - zapOpts := zap.UseFlagOptions(zapOptions) - newLogger := zap.New(zapOpts).WithName("lvm-metric-exporter") - newLogger.Info("Commandline: ", "args", os.Args[1:]) - newLogger.Info("Exporter set values: ", "namespace", exporterNamespace, "address", exporterAddress) - - prometheus.MustRegister(&lvmCollector{}) - - // prometheus http handler - http.Handle("/metrics", promhttp.Handler()) - http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { - _, err := rw.Write([]byte(` - LVM Metric Exporter - -

LVM Metric Exporter

-

Metrics

- - `)) - if err != nil { - newLogger.Error(err, "error while writing into http.ResponseWriter") - return - } - }) - - // prometheus metrics - _ = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "lvmoptest", - Help: "this is a test gauge metrics", - }) - - // runtime loop - newLogger.Info("Starting lvm metric exporter at ", "address", exporterAddress) - server := &http.Server{ - Addr: exporterAddress, - ReadHeaderTimeout: 5 * time.Second, - } - - err := server.ListenAndServe() - if err != nil { - newLogger.Error(err, "Error while serving requests") - } -} diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 13360dc51..be78177ad 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -34,7 +34,6 @@ spec: app.kubernetes.io/name: lvms-operator app.kubernetes.io/part-of: lvms-provisioner app.kubernetes.io/component: lvms-operator - exporter: lvms-operator spec: securityContext: runAsNonRoot: true @@ -74,13 +73,5 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name - - command: - - /metricsexporter - image: controller:latest - name: metricsexporter - resources: - requests: - cpu: 1m - memory: 20Mi serviceAccountName: lvms-operator terminationGracePeriodSeconds: 10 diff --git a/config/prometheus/monitor.yaml b/config/prometheus/monitor.yaml index 3e172ddf1..45f411b36 100644 --- a/config/prometheus/monitor.yaml +++ b/config/prometheus/monitor.yaml @@ -17,8 +17,8 @@ spec: tlsConfig: insecureSkipVerify: true - path: /metrics - port: lvms-metrics - scheme: http + port: https + scheme: https bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token tlsConfig: insecureSkipVerify: true diff --git a/config/rbac/auth_proxy_service.yaml b/config/rbac/auth_proxy_service.yaml index 1fb8fe82b..7e8f6c807 100644 --- a/config/rbac/auth_proxy_service.yaml +++ b/config/rbac/auth_proxy_service.yaml @@ -3,6 +3,7 @@ kind: Service metadata: labels: app.kubernetes.io/name: lvms-operator + app.kubernetes.io/compose: metrics name: lvms-operator-metrics-service namespace: system spec: diff --git a/config/rbac/kustomization.yaml b/config/rbac/kustomization.yaml index 844ba95c2..f3e336f50 100644 --- a/config/rbac/kustomization.yaml +++ b/config/rbac/kustomization.yaml @@ -14,7 +14,6 @@ resources: - topolvm_controller_role.yaml - topolvm_controller_role_bindings.yaml # lvm-node metric rbac -- lvms_metric_service_config.yaml - lvms_node_role_n_rolebindings.yaml # topolvm-node metric rbac - topolvm_metric_service_config.yaml diff --git a/config/rbac/lvms_metric_service_config.yaml b/config/rbac/lvms_metric_service_config.yaml deleted file mode 100644 index b343d222f..000000000 --- a/config/rbac/lvms_metric_service_config.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: lvms-node-metrics - namespace: system - labels: - app.kubernetes.io/compose: metrics - app.kubernetes.io/part-of: lvms-provisioner -spec: - selector: - exporter: lvms-operator - ports: - - name: lvms-metrics - protocol: TCP - port: 23532 - targetPort: 23532 diff --git a/docs/design/architecture.md b/docs/design/architecture.md index 3bc0abd5d..142333922 100644 --- a/docs/design/architecture.md +++ b/docs/design/architecture.md @@ -8,7 +8,6 @@ The following table provides a view of the containers in these components: |----------------------|------------|-----------------------------------------------------------------------------------------------------| | LVM Operator | Deployment | [manager](lvm-operator-manager.md) | | | | [kube-rbac-proxy](https://github.com/brancz/kube-rbac-proxy#kube-rbac-proxy) | -| | | [metricsexporter](../../README.md#metrics) | | Volume Group Manager | DaemonSet | [vg-manager](vg-manager.md) | | TopoLVM Controller | Deployment | [topolvm-controller](https://github.com/topolvm/topolvm/blob/main/docs/topolvm-controller.md) | | | | [csi-provisioner](https://github.com/kubernetes-csi/external-provisioner/blob/master/doc/design.md) | diff --git a/go.mod b/go.mod index 9d75cd528..291408585 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/openshift/library-go v0.0.0-20230908101047-d058c695f677 github.com/operator-framework/api v0.17.7 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.16.0 github.com/stretchr/testify v1.8.4 github.com/topolvm/topolvm v0.20.0 go.uber.org/zap v1.25.0 @@ -69,6 +68,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml v1.9.4 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect diff --git a/test/performance/operf.go b/test/performance/operf.go index 44a6ed177..29e314ed6 100644 --- a/test/performance/operf.go +++ b/test/performance/operf.go @@ -422,16 +422,6 @@ func (unit *LvmUnitMetrics) parseMetrics(metricsResult string) map[string]Metric [1654680112, "0.005354719799999981"] ] }, - { - "metric": { - "container": "metricsexporter" - }, - "values": [ - [1654680100, "9.652999999998358e-07"], - [1654680106, "0"], - [1654680112, "0"] - ] - } ] } } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promauto/auto.go b/vendor/github.com/prometheus/client_golang/prometheus/promauto/auto.go deleted file mode 100644 index fa9011592..000000000 --- a/vendor/github.com/prometheus/client_golang/prometheus/promauto/auto.go +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright 2018 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 promauto provides alternative constructors for the fundamental -// Prometheus metric types and their …Vec and …Func variants. The difference to -// their counterparts in the prometheus package is that the promauto -// constructors register the Collectors with a registry before returning them. -// There are two sets of constructors. The constructors in the first set are -// top-level functions, while the constructors in the other set are methods of -// the Factory type. The top-level function return Collectors registered with -// the global registry (prometheus.DefaultRegisterer), while the methods return -// Collectors registered with the registry the Factory was constructed with. All -// constructors panic if the registration fails. -// -// The following example is a complete program to create a histogram of normally -// distributed random numbers from the math/rand package: -// -// package main -// -// import ( -// "math/rand" -// "net/http" -// -// "github.com/prometheus/client_golang/prometheus" -// "github.com/prometheus/client_golang/prometheus/promauto" -// "github.com/prometheus/client_golang/prometheus/promhttp" -// ) -// -// var histogram = promauto.NewHistogram(prometheus.HistogramOpts{ -// Name: "random_numbers", -// Help: "A histogram of normally distributed random numbers.", -// Buckets: prometheus.LinearBuckets(-3, .1, 61), -// }) -// -// func Random() { -// for { -// histogram.Observe(rand.NormFloat64()) -// } -// } -// -// func main() { -// go Random() -// http.Handle("/metrics", promhttp.Handler()) -// http.ListenAndServe(":1971", nil) -// } -// -// Prometheus's version of a minimal hello-world program: -// -// package main -// -// import ( -// "fmt" -// "net/http" -// -// "github.com/prometheus/client_golang/prometheus" -// "github.com/prometheus/client_golang/prometheus/promauto" -// "github.com/prometheus/client_golang/prometheus/promhttp" -// ) -// -// func main() { -// http.Handle("/", promhttp.InstrumentHandlerCounter( -// promauto.NewCounterVec( -// prometheus.CounterOpts{ -// Name: "hello_requests_total", -// Help: "Total number of hello-world requests by HTTP code.", -// }, -// []string{"code"}, -// ), -// http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -// fmt.Fprint(w, "Hello, world!") -// }), -// )) -// http.Handle("/metrics", promhttp.Handler()) -// http.ListenAndServe(":1971", nil) -// } -// -// A Factory is created with the With(prometheus.Registerer) function, which -// enables two usage pattern. With(prometheus.Registerer) can be called once per -// line: -// -// var ( -// reg = prometheus.NewRegistry() -// randomNumbers = promauto.With(reg).NewHistogram(prometheus.HistogramOpts{ -// Name: "random_numbers", -// Help: "A histogram of normally distributed random numbers.", -// Buckets: prometheus.LinearBuckets(-3, .1, 61), -// }) -// requestCount = promauto.With(reg).NewCounterVec( -// prometheus.CounterOpts{ -// Name: "http_requests_total", -// Help: "Total number of HTTP requests by status code and method.", -// }, -// []string{"code", "method"}, -// ) -// ) -// -// Or it can be used to create a Factory once to be used multiple times: -// -// var ( -// reg = prometheus.NewRegistry() -// factory = promauto.With(reg) -// randomNumbers = factory.NewHistogram(prometheus.HistogramOpts{ -// Name: "random_numbers", -// Help: "A histogram of normally distributed random numbers.", -// Buckets: prometheus.LinearBuckets(-3, .1, 61), -// }) -// requestCount = factory.NewCounterVec( -// prometheus.CounterOpts{ -// Name: "http_requests_total", -// Help: "Total number of HTTP requests by status code and method.", -// }, -// []string{"code", "method"}, -// ) -// ) -// -// This appears very handy. So why are these constructors locked away in a -// separate package? -// -// The main problem is that registration may fail, e.g. if a metric inconsistent -// with or equal to the newly to be registered one is already registered. -// Therefore, the Register method in the prometheus.Registerer interface returns -// an error, and the same is the case for the top-level prometheus.Register -// function that registers with the global registry. The prometheus package also -// provides MustRegister versions for both. They panic if the registration -// fails, and they clearly call this out by using the Must… idiom. Panicking is -// problematic in this case because it doesn't just happen on input provided by -// the caller that is invalid on its own. Things are a bit more subtle here: -// Metric creation and registration tend to be spread widely over the -// codebase. It can easily happen that an incompatible metric is added to an -// unrelated part of the code, and suddenly code that used to work perfectly -// fine starts to panic (provided that the registration of the newly added -// metric happens before the registration of the previously existing -// metric). This may come as an even bigger surprise with the global registry, -// where simply importing another package can trigger a panic (if the newly -// imported package registers metrics in its init function). At least, in the -// prometheus package, creation of metrics and other collectors is separate from -// registration. You first create the metric, and then you decide explicitly if -// you want to register it with a local or the global registry, and if you want -// to handle the error or risk a panic. With the constructors in the promauto -// package, registration is automatic, and if it fails, it will always -// panic. Furthermore, the constructors will often be called in the var section -// of a file, which means that panicking will happen as a side effect of merely -// importing a package. -// -// A separate package allows conservative users to entirely ignore it. And -// whoever wants to use it, will do so explicitly, with an opportunity to read -// this warning. -// -// Enjoy promauto responsibly! -package promauto - -import "github.com/prometheus/client_golang/prometheus" - -// NewCounter works like the function of the same name in the prometheus package -// but it automatically registers the Counter with the -// prometheus.DefaultRegisterer. If the registration fails, NewCounter panics. -func NewCounter(opts prometheus.CounterOpts) prometheus.Counter { - return With(prometheus.DefaultRegisterer).NewCounter(opts) -} - -// NewCounterVec works like the function of the same name in the prometheus -// package but it automatically registers the CounterVec with the -// prometheus.DefaultRegisterer. If the registration fails, NewCounterVec -// panics. -func NewCounterVec(opts prometheus.CounterOpts, labelNames []string) *prometheus.CounterVec { - return With(prometheus.DefaultRegisterer).NewCounterVec(opts, labelNames) -} - -// NewCounterFunc works like the function of the same name in the prometheus -// package but it automatically registers the CounterFunc with the -// prometheus.DefaultRegisterer. If the registration fails, NewCounterFunc -// panics. -func NewCounterFunc(opts prometheus.CounterOpts, function func() float64) prometheus.CounterFunc { - return With(prometheus.DefaultRegisterer).NewCounterFunc(opts, function) -} - -// NewGauge works like the function of the same name in the prometheus package -// but it automatically registers the Gauge with the -// prometheus.DefaultRegisterer. If the registration fails, NewGauge panics. -func NewGauge(opts prometheus.GaugeOpts) prometheus.Gauge { - return With(prometheus.DefaultRegisterer).NewGauge(opts) -} - -// NewGaugeVec works like the function of the same name in the prometheus -// package but it automatically registers the GaugeVec with the -// prometheus.DefaultRegisterer. If the registration fails, NewGaugeVec panics. -func NewGaugeVec(opts prometheus.GaugeOpts, labelNames []string) *prometheus.GaugeVec { - return With(prometheus.DefaultRegisterer).NewGaugeVec(opts, labelNames) -} - -// NewGaugeFunc works like the function of the same name in the prometheus -// package but it automatically registers the GaugeFunc with the -// prometheus.DefaultRegisterer. If the registration fails, NewGaugeFunc panics. -func NewGaugeFunc(opts prometheus.GaugeOpts, function func() float64) prometheus.GaugeFunc { - return With(prometheus.DefaultRegisterer).NewGaugeFunc(opts, function) -} - -// NewSummary works like the function of the same name in the prometheus package -// but it automatically registers the Summary with the -// prometheus.DefaultRegisterer. If the registration fails, NewSummary panics. -func NewSummary(opts prometheus.SummaryOpts) prometheus.Summary { - return With(prometheus.DefaultRegisterer).NewSummary(opts) -} - -// NewSummaryVec works like the function of the same name in the prometheus -// package but it automatically registers the SummaryVec with the -// prometheus.DefaultRegisterer. If the registration fails, NewSummaryVec -// panics. -func NewSummaryVec(opts prometheus.SummaryOpts, labelNames []string) *prometheus.SummaryVec { - return With(prometheus.DefaultRegisterer).NewSummaryVec(opts, labelNames) -} - -// NewHistogram works like the function of the same name in the prometheus -// package but it automatically registers the Histogram with the -// prometheus.DefaultRegisterer. If the registration fails, NewHistogram panics. -func NewHistogram(opts prometheus.HistogramOpts) prometheus.Histogram { - return With(prometheus.DefaultRegisterer).NewHistogram(opts) -} - -// NewHistogramVec works like the function of the same name in the prometheus -// package but it automatically registers the HistogramVec with the -// prometheus.DefaultRegisterer. If the registration fails, NewHistogramVec -// panics. -func NewHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *prometheus.HistogramVec { - return With(prometheus.DefaultRegisterer).NewHistogramVec(opts, labelNames) -} - -// NewUntypedFunc works like the function of the same name in the prometheus -// package but it automatically registers the UntypedFunc with the -// prometheus.DefaultRegisterer. If the registration fails, NewUntypedFunc -// panics. -func NewUntypedFunc(opts prometheus.UntypedOpts, function func() float64) prometheus.UntypedFunc { - return With(prometheus.DefaultRegisterer).NewUntypedFunc(opts, function) -} - -// Factory provides factory methods to create Collectors that are automatically -// registered with a Registerer. Create a Factory with the With function, -// providing a Registerer to auto-register created Collectors with. The zero -// value of a Factory creates Collectors that are not registered with any -// Registerer. All methods of the Factory panic if the registration fails. -type Factory struct { - r prometheus.Registerer -} - -// With creates a Factory using the provided Registerer for registration of the -// created Collectors. If the provided Registerer is nil, the returned Factory -// creates Collectors that are not registered with any Registerer. -func With(r prometheus.Registerer) Factory { return Factory{r} } - -// NewCounter works like the function of the same name in the prometheus package -// but it automatically registers the Counter with the Factory's Registerer. -func (f Factory) NewCounter(opts prometheus.CounterOpts) prometheus.Counter { - c := prometheus.NewCounter(opts) - if f.r != nil { - f.r.MustRegister(c) - } - return c -} - -// NewCounterVec works like the function of the same name in the prometheus -// package but it automatically registers the CounterVec with the Factory's -// Registerer. -func (f Factory) NewCounterVec(opts prometheus.CounterOpts, labelNames []string) *prometheus.CounterVec { - c := prometheus.NewCounterVec(opts, labelNames) - if f.r != nil { - f.r.MustRegister(c) - } - return c -} - -// NewCounterFunc works like the function of the same name in the prometheus -// package but it automatically registers the CounterFunc with the Factory's -// Registerer. -func (f Factory) NewCounterFunc(opts prometheus.CounterOpts, function func() float64) prometheus.CounterFunc { - c := prometheus.NewCounterFunc(opts, function) - if f.r != nil { - f.r.MustRegister(c) - } - return c -} - -// NewGauge works like the function of the same name in the prometheus package -// but it automatically registers the Gauge with the Factory's Registerer. -func (f Factory) NewGauge(opts prometheus.GaugeOpts) prometheus.Gauge { - g := prometheus.NewGauge(opts) - if f.r != nil { - f.r.MustRegister(g) - } - return g -} - -// NewGaugeVec works like the function of the same name in the prometheus -// package but it automatically registers the GaugeVec with the Factory's -// Registerer. -func (f Factory) NewGaugeVec(opts prometheus.GaugeOpts, labelNames []string) *prometheus.GaugeVec { - g := prometheus.NewGaugeVec(opts, labelNames) - if f.r != nil { - f.r.MustRegister(g) - } - return g -} - -// NewGaugeFunc works like the function of the same name in the prometheus -// package but it automatically registers the GaugeFunc with the Factory's -// Registerer. -func (f Factory) NewGaugeFunc(opts prometheus.GaugeOpts, function func() float64) prometheus.GaugeFunc { - g := prometheus.NewGaugeFunc(opts, function) - if f.r != nil { - f.r.MustRegister(g) - } - return g -} - -// NewSummary works like the function of the same name in the prometheus package -// but it automatically registers the Summary with the Factory's Registerer. -func (f Factory) NewSummary(opts prometheus.SummaryOpts) prometheus.Summary { - s := prometheus.NewSummary(opts) - if f.r != nil { - f.r.MustRegister(s) - } - return s -} - -// NewSummaryVec works like the function of the same name in the prometheus -// package but it automatically registers the SummaryVec with the Factory's -// Registerer. -func (f Factory) NewSummaryVec(opts prometheus.SummaryOpts, labelNames []string) *prometheus.SummaryVec { - s := prometheus.NewSummaryVec(opts, labelNames) - if f.r != nil { - f.r.MustRegister(s) - } - return s -} - -// NewHistogram works like the function of the same name in the prometheus -// package but it automatically registers the Histogram with the Factory's -// Registerer. -func (f Factory) NewHistogram(opts prometheus.HistogramOpts) prometheus.Histogram { - h := prometheus.NewHistogram(opts) - if f.r != nil { - f.r.MustRegister(h) - } - return h -} - -// NewHistogramVec works like the function of the same name in the prometheus -// package but it automatically registers the HistogramVec with the Factory's -// Registerer. -func (f Factory) NewHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *prometheus.HistogramVec { - h := prometheus.NewHistogramVec(opts, labelNames) - if f.r != nil { - f.r.MustRegister(h) - } - return h -} - -// NewUntypedFunc works like the function of the same name in the prometheus -// package but it automatically registers the UntypedFunc with the Factory's -// Registerer. -func (f Factory) NewUntypedFunc(opts prometheus.UntypedOpts, function func() float64) prometheus.UntypedFunc { - u := prometheus.NewUntypedFunc(opts, function) - if f.r != nil { - f.r.MustRegister(u) - } - return u -} diff --git a/vendor/modules.txt b/vendor/modules.txt index a7b78b116..b9afb02aa 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -258,7 +258,6 @@ github.com/pmezard/go-difflib/difflib github.com/prometheus/client_golang/prometheus github.com/prometheus/client_golang/prometheus/collectors github.com/prometheus/client_golang/prometheus/internal -github.com/prometheus/client_golang/prometheus/promauto github.com/prometheus/client_golang/prometheus/promhttp # github.com/prometheus/client_model v0.4.0 ## explicit; go 1.18