Skip to content

Commit 870469e

Browse files
authored
Test and support 1.19 (#1160)
* Add new Go 1.19 metrics Signed-off-by: Kemal Akkoyun <[email protected]> * Format files with the latest formatter Signed-off-by: Kemal Akkoyun <[email protected]> Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent b785d0c commit 870469e

File tree

11 files changed

+188
-172
lines changed

11 files changed

+188
-172
lines changed

.circleci/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ workflows:
5454
name: go-1-18
5555
go_version: "1.18"
5656
run_lint: true
57+
- test:
58+
name: go-1-19
59+
go_version: "1.19"
60+
run_lint: true
5761
# Style and unused/missing packages are only checked against
5862
# the latest supported Go version.
5963
run_style_and_unused: true

api/prometheus/v1/api.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,15 @@ type RuleGroup struct {
335335
// that rules are returned in by the API.
336336
//
337337
// Rule types can be determined using a type switch:
338-
// switch v := rule.(type) {
339-
// case RecordingRule:
340-
// fmt.Print("got a recording rule")
341-
// case AlertingRule:
342-
// fmt.Print("got a alerting rule")
343-
// default:
344-
// fmt.Printf("unknown rule type %s", v)
345-
// }
338+
//
339+
// switch v := rule.(type) {
340+
// case RecordingRule:
341+
// fmt.Print("got a recording rule")
342+
// case AlertingRule:
343+
// fmt.Print("got a alerting rule")
344+
// default:
345+
// fmt.Printf("unknown rule type %s", v)
346+
// }
346347
type Rules []interface{}
347348

348349
// AlertingRule models a alerting rule.

prometheus/counter.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ func (v *CounterVec) GetMetricWith(labels Labels) (Counter, error) {
246246
// WithLabelValues works as GetMetricWithLabelValues, but panics where
247247
// GetMetricWithLabelValues would have returned an error. Not returning an
248248
// error allows shortcuts like
249-
// myVec.WithLabelValues("404", "GET").Add(42)
249+
//
250+
// myVec.WithLabelValues("404", "GET").Add(42)
250251
func (v *CounterVec) WithLabelValues(lvs ...string) Counter {
251252
c, err := v.GetMetricWithLabelValues(lvs...)
252253
if err != nil {
@@ -257,7 +258,8 @@ func (v *CounterVec) WithLabelValues(lvs ...string) Counter {
257258

258259
// With works as GetMetricWith, but panics where GetMetricWithLabels would have
259260
// returned an error. Not returning an error allows shortcuts like
260-
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42)
261+
//
262+
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42)
261263
func (v *CounterVec) With(labels Labels) Counter {
262264
c, err := v.GetMetricWith(labels)
263265
if err != nil {

prometheus/doc.go

+57-58
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,66 @@
2121
// All exported functions and methods are safe to be used concurrently unless
2222
// specified otherwise.
2323
//
24-
// A Basic Example
24+
// # A Basic Example
2525
//
2626
// As a starting point, a very basic usage example:
2727
//
28-
// package main
29-
//
30-
// import (
31-
// "log"
32-
// "net/http"
33-
//
34-
// "github.com/prometheus/client_golang/prometheus"
35-
// "github.com/prometheus/client_golang/prometheus/promhttp"
36-
// )
37-
//
38-
// type metrics struct {
39-
// cpuTemp prometheus.Gauge
40-
// hdFailures *prometheus.CounterVec
41-
// }
42-
//
43-
// func NewMetrics(reg prometheus.Registerer) *metrics {
44-
// m := &metrics{
45-
// cpuTemp: prometheus.NewGauge(prometheus.GaugeOpts{
46-
// Name: "cpu_temperature_celsius",
47-
// Help: "Current temperature of the CPU.",
48-
// }),
49-
// hdFailures: prometheus.NewCounterVec(
50-
// prometheus.CounterOpts{
51-
// Name: "hd_errors_total",
52-
// Help: "Number of hard-disk errors.",
53-
// },
54-
// []string{"device"},
55-
// ),
56-
// }
57-
// reg.MustRegister(m.cpuTemp)
58-
// reg.MustRegister(m.hdFailures)
59-
// return m
60-
// }
61-
//
62-
// func main() {
63-
// // Create a non-global registry.
64-
// reg := prometheus.NewRegistry()
65-
//
66-
// // Create new metrics and register them using the custom registry.
67-
// m := NewMetrics(reg)
68-
// // Set values for the new created metrics.
69-
// m.cpuTemp.Set(65.3)
70-
// m.hdFailures.With(prometheus.Labels{"device":"/dev/sda"}).Inc()
71-
//
72-
// // Expose metrics and custom registry via an HTTP server
73-
// // using the HandleFor function. "/metrics" is the usual endpoint for that.
74-
// http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
75-
// log.Fatal(http.ListenAndServe(":8080", nil))
76-
// }
77-
//
28+
// package main
29+
//
30+
// import (
31+
// "log"
32+
// "net/http"
33+
//
34+
// "github.com/prometheus/client_golang/prometheus"
35+
// "github.com/prometheus/client_golang/prometheus/promhttp"
36+
// )
37+
//
38+
// type metrics struct {
39+
// cpuTemp prometheus.Gauge
40+
// hdFailures *prometheus.CounterVec
41+
// }
42+
//
43+
// func NewMetrics(reg prometheus.Registerer) *metrics {
44+
// m := &metrics{
45+
// cpuTemp: prometheus.NewGauge(prometheus.GaugeOpts{
46+
// Name: "cpu_temperature_celsius",
47+
// Help: "Current temperature of the CPU.",
48+
// }),
49+
// hdFailures: prometheus.NewCounterVec(
50+
// prometheus.CounterOpts{
51+
// Name: "hd_errors_total",
52+
// Help: "Number of hard-disk errors.",
53+
// },
54+
// []string{"device"},
55+
// ),
56+
// }
57+
// reg.MustRegister(m.cpuTemp)
58+
// reg.MustRegister(m.hdFailures)
59+
// return m
60+
// }
61+
//
62+
// func main() {
63+
// // Create a non-global registry.
64+
// reg := prometheus.NewRegistry()
65+
//
66+
// // Create new metrics and register them using the custom registry.
67+
// m := NewMetrics(reg)
68+
// // Set values for the new created metrics.
69+
// m.cpuTemp.Set(65.3)
70+
// m.hdFailures.With(prometheus.Labels{"device":"/dev/sda"}).Inc()
71+
//
72+
// // Expose metrics and custom registry via an HTTP server
73+
// // using the HandleFor function. "/metrics" is the usual endpoint for that.
74+
// http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
75+
// log.Fatal(http.ListenAndServe(":8080", nil))
76+
// }
7877
//
7978
// This is a complete program that exports two metrics, a Gauge and a Counter,
8079
// the latter with a label attached to turn it into a (one-dimensional) vector.
8180
// It register the metrics using a custom registry and exposes them via an HTTP server
8281
// on the /metrics endpoint.
8382
//
84-
// Metrics
83+
// # Metrics
8584
//
8685
// The number of exported identifiers in this package might appear a bit
8786
// overwhelming. However, in addition to the basic plumbing shown in the example
@@ -112,7 +111,7 @@
112111
// To create instances of Metrics and their vector versions, you need a suitable
113112
// …Opts struct, i.e. GaugeOpts, CounterOpts, SummaryOpts, or HistogramOpts.
114113
//
115-
// Custom Collectors and constant Metrics
114+
// # Custom Collectors and constant Metrics
116115
//
117116
// While you could create your own implementations of Metric, most likely you
118117
// will only ever implement the Collector interface on your own. At a first
@@ -153,7 +152,7 @@
153152
// a metric, GaugeFunc, CounterFunc, or UntypedFunc might be interesting
154153
// shortcuts.
155154
//
156-
// Advanced Uses of the Registry
155+
// # Advanced Uses of the Registry
157156
//
158157
// While MustRegister is the by far most common way of registering a Collector,
159158
// sometimes you might want to handle the errors the registration might cause.
@@ -188,23 +187,23 @@
188187
// NewProcessCollector). With a custom registry, you are in control and decide
189188
// yourself about the Collectors to register.
190189
//
191-
// HTTP Exposition
190+
// # HTTP Exposition
192191
//
193192
// The Registry implements the Gatherer interface. The caller of the Gather
194193
// method can then expose the gathered metrics in some way. Usually, the metrics
195194
// are served via HTTP on the /metrics endpoint. That's happening in the example
196195
// above. The tools to expose metrics via HTTP are in the promhttp sub-package.
197196
//
198-
// Pushing to the Pushgateway
197+
// # Pushing to the Pushgateway
199198
//
200199
// Function for pushing to the Pushgateway can be found in the push sub-package.
201200
//
202-
// Graphite Bridge
201+
// # Graphite Bridge
203202
//
204203
// Functions and examples to push metrics from a Gatherer to Graphite can be
205204
// found in the graphite sub-package.
206205
//
207-
// Other Means of Exposition
206+
// # Other Means of Exposition
208207
//
209208
// More ways of exposing metrics can easily be added by following the approaches
210209
// of the existing implementations.

prometheus/gauge.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ func (v *GaugeVec) GetMetricWith(labels Labels) (Gauge, error) {
210210
// WithLabelValues works as GetMetricWithLabelValues, but panics where
211211
// GetMetricWithLabelValues would have returned an error. Not returning an
212212
// error allows shortcuts like
213-
// myVec.WithLabelValues("404", "GET").Add(42)
213+
//
214+
// myVec.WithLabelValues("404", "GET").Add(42)
214215
func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge {
215216
g, err := v.GetMetricWithLabelValues(lvs...)
216217
if err != nil {
@@ -221,7 +222,8 @@ func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge {
221222

222223
// With works as GetMetricWith, but panics where GetMetricWithLabels would have
223224
// returned an error. Not returning an error allows shortcuts like
224-
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42)
225+
//
226+
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42)
225227
func (v *GaugeVec) With(labels Labels) Gauge {
226228
g, err := v.GetMetricWith(labels)
227229
if err != nil {

prometheus/internal/difflib.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,15 @@ func (m *SequenceMatcher) isBJunk(s string) bool {
201201
// If IsJunk is not defined:
202202
//
203203
// Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
204-
// alo <= i <= i+k <= ahi
205-
// blo <= j <= j+k <= bhi
204+
//
205+
// alo <= i <= i+k <= ahi
206+
// blo <= j <= j+k <= bhi
207+
//
206208
// and for all (i',j',k') meeting those conditions,
207-
// k >= k'
208-
// i <= i'
209-
// and if i == i', j <= j'
209+
//
210+
// k >= k'
211+
// i <= i'
212+
// and if i == i', j <= j'
210213
//
211214
// In other words, of all maximal matching blocks, return one that
212215
// starts earliest in a, and of all those maximal matching blocks that

prometheus/labels.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import (
2525
// Labels represents a collection of label name -> value mappings. This type is
2626
// commonly used with the With(Labels) and GetMetricWith(Labels) methods of
2727
// metric vector Collectors, e.g.:
28-
// myVec.With(Labels{"code": "404", "method": "GET"}).Add(42)
28+
//
29+
// myVec.With(Labels{"code": "404", "method": "GET"}).Add(42)
2930
//
3031
// The other use-case is the specification of constant label pairs in Opts or to
3132
// create a Desc.

0 commit comments

Comments
 (0)