Test and support 1.19 (#1160)

* Add new Go 1.19 metrics

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

* Format files with the latest formatter

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
This commit is contained in:
Kemal Akkoyun 2022-11-08 00:14:19 +01:00 committed by GitHub
parent b785d0c828
commit 870469ecf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 181 additions and 165 deletions

View File

@ -54,6 +54,10 @@ workflows:
name: go-1-18 name: go-1-18
go_version: "1.18" go_version: "1.18"
run_lint: true run_lint: true
- test:
name: go-1-19
go_version: "1.19"
run_lint: true
# Style and unused/missing packages are only checked against # Style and unused/missing packages are only checked against
# the latest supported Go version. # the latest supported Go version.
run_style_and_unused: true run_style_and_unused: true

View File

@ -335,6 +335,7 @@ type RuleGroup struct {
// that rules are returned in by the API. // that rules are returned in by the API.
// //
// Rule types can be determined using a type switch: // Rule types can be determined using a type switch:
//
// switch v := rule.(type) { // switch v := rule.(type) {
// case RecordingRule: // case RecordingRule:
// fmt.Print("got a recording rule") // fmt.Print("got a recording rule")

View File

@ -246,6 +246,7 @@ func (v *CounterVec) GetMetricWith(labels Labels) (Counter, error) {
// WithLabelValues works as GetMetricWithLabelValues, but panics where // WithLabelValues works as GetMetricWithLabelValues, but panics where
// GetMetricWithLabelValues would have returned an error. Not returning an // GetMetricWithLabelValues would have returned an error. Not returning an
// error allows shortcuts like // error allows shortcuts like
//
// myVec.WithLabelValues("404", "GET").Add(42) // myVec.WithLabelValues("404", "GET").Add(42)
func (v *CounterVec) WithLabelValues(lvs ...string) Counter { func (v *CounterVec) WithLabelValues(lvs ...string) Counter {
c, err := v.GetMetricWithLabelValues(lvs...) c, err := v.GetMetricWithLabelValues(lvs...)
@ -257,6 +258,7 @@ func (v *CounterVec) WithLabelValues(lvs ...string) Counter {
// With works as GetMetricWith, but panics where GetMetricWithLabels would have // With works as GetMetricWith, but panics where GetMetricWithLabels would have
// returned an error. Not returning an error allows shortcuts like // returned an error. Not returning an error allows shortcuts like
//
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42) // myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42)
func (v *CounterVec) With(labels Labels) Counter { func (v *CounterVec) With(labels Labels) Counter {
c, err := v.GetMetricWith(labels) c, err := v.GetMetricWith(labels)

View File

@ -21,7 +21,7 @@
// All exported functions and methods are safe to be used concurrently unless // All exported functions and methods are safe to be used concurrently unless
// specified otherwise. // specified otherwise.
// //
// A Basic Example // # A Basic Example
// //
// As a starting point, a very basic usage example: // As a starting point, a very basic usage example:
// //
@ -75,13 +75,12 @@
// log.Fatal(http.ListenAndServe(":8080", nil)) // log.Fatal(http.ListenAndServe(":8080", nil))
// } // }
// //
//
// This is a complete program that exports two metrics, a Gauge and a Counter, // This is a complete program that exports two metrics, a Gauge and a Counter,
// the latter with a label attached to turn it into a (one-dimensional) vector. // the latter with a label attached to turn it into a (one-dimensional) vector.
// It register the metrics using a custom registry and exposes them via an HTTP server // It register the metrics using a custom registry and exposes them via an HTTP server
// on the /metrics endpoint. // on the /metrics endpoint.
// //
// Metrics // # Metrics
// //
// The number of exported identifiers in this package might appear a bit // The number of exported identifiers in this package might appear a bit
// overwhelming. However, in addition to the basic plumbing shown in the example // overwhelming. However, in addition to the basic plumbing shown in the example
@ -112,7 +111,7 @@
// To create instances of Metrics and their vector versions, you need a suitable // To create instances of Metrics and their vector versions, you need a suitable
// …Opts struct, i.e. GaugeOpts, CounterOpts, SummaryOpts, or HistogramOpts. // …Opts struct, i.e. GaugeOpts, CounterOpts, SummaryOpts, or HistogramOpts.
// //
// Custom Collectors and constant Metrics // # Custom Collectors and constant Metrics
// //
// While you could create your own implementations of Metric, most likely you // While you could create your own implementations of Metric, most likely you
// will only ever implement the Collector interface on your own. At a first // will only ever implement the Collector interface on your own. At a first
@ -153,7 +152,7 @@
// a metric, GaugeFunc, CounterFunc, or UntypedFunc might be interesting // a metric, GaugeFunc, CounterFunc, or UntypedFunc might be interesting
// shortcuts. // shortcuts.
// //
// Advanced Uses of the Registry // # Advanced Uses of the Registry
// //
// While MustRegister is the by far most common way of registering a Collector, // While MustRegister is the by far most common way of registering a Collector,
// sometimes you might want to handle the errors the registration might cause. // sometimes you might want to handle the errors the registration might cause.
@ -188,23 +187,23 @@
// NewProcessCollector). With a custom registry, you are in control and decide // NewProcessCollector). With a custom registry, you are in control and decide
// yourself about the Collectors to register. // yourself about the Collectors to register.
// //
// HTTP Exposition // # HTTP Exposition
// //
// The Registry implements the Gatherer interface. The caller of the Gather // The Registry implements the Gatherer interface. The caller of the Gather
// method can then expose the gathered metrics in some way. Usually, the metrics // method can then expose the gathered metrics in some way. Usually, the metrics
// are served via HTTP on the /metrics endpoint. That's happening in the example // are served via HTTP on the /metrics endpoint. That's happening in the example
// above. The tools to expose metrics via HTTP are in the promhttp sub-package. // above. The tools to expose metrics via HTTP are in the promhttp sub-package.
// //
// Pushing to the Pushgateway // # Pushing to the Pushgateway
// //
// Function for pushing to the Pushgateway can be found in the push sub-package. // Function for pushing to the Pushgateway can be found in the push sub-package.
// //
// Graphite Bridge // # Graphite Bridge
// //
// Functions and examples to push metrics from a Gatherer to Graphite can be // Functions and examples to push metrics from a Gatherer to Graphite can be
// found in the graphite sub-package. // found in the graphite sub-package.
// //
// Other Means of Exposition // # Other Means of Exposition
// //
// More ways of exposing metrics can easily be added by following the approaches // More ways of exposing metrics can easily be added by following the approaches
// of the existing implementations. // of the existing implementations.

View File

@ -210,6 +210,7 @@ func (v *GaugeVec) GetMetricWith(labels Labels) (Gauge, error) {
// WithLabelValues works as GetMetricWithLabelValues, but panics where // WithLabelValues works as GetMetricWithLabelValues, but panics where
// GetMetricWithLabelValues would have returned an error. Not returning an // GetMetricWithLabelValues would have returned an error. Not returning an
// error allows shortcuts like // error allows shortcuts like
//
// myVec.WithLabelValues("404", "GET").Add(42) // myVec.WithLabelValues("404", "GET").Add(42)
func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge { func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge {
g, err := v.GetMetricWithLabelValues(lvs...) g, err := v.GetMetricWithLabelValues(lvs...)
@ -221,6 +222,7 @@ func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge {
// With works as GetMetricWith, but panics where GetMetricWithLabels would have // With works as GetMetricWith, but panics where GetMetricWithLabels would have
// returned an error. Not returning an error allows shortcuts like // returned an error. Not returning an error allows shortcuts like
//
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42) // myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42)
func (v *GaugeVec) With(labels Labels) Gauge { func (v *GaugeVec) With(labels Labels) Gauge {
g, err := v.GetMetricWith(labels) g, err := v.GetMetricWith(labels)

View File

@ -201,9 +201,12 @@ func (m *SequenceMatcher) isBJunk(s string) bool {
// If IsJunk is not defined: // If IsJunk is not defined:
// //
// Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where // Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
//
// alo <= i <= i+k <= ahi // alo <= i <= i+k <= ahi
// blo <= j <= j+k <= bhi // blo <= j <= j+k <= bhi
//
// and for all (i',j',k') meeting those conditions, // and for all (i',j',k') meeting those conditions,
//
// k >= k' // k >= k'
// i <= i' // i <= i'
// and if i == i', j <= j' // and if i == i', j <= j'

View File

@ -25,6 +25,7 @@ import (
// Labels represents a collection of label name -> value mappings. This type is // Labels represents a collection of label name -> value mappings. This type is
// commonly used with the With(Labels) and GetMetricWith(Labels) methods of // commonly used with the With(Labels) and GetMetricWith(Labels) methods of
// metric vector Collectors, e.g.: // metric vector Collectors, e.g.:
//
// myVec.With(Labels{"code": "404", "method": "GET"}).Add(42) // myVec.With(Labels{"code": "404", "method": "GET"}).Add(42)
// //
// The other use-case is the specification of constant label pairs in Opts or to // The other use-case is the specification of constant label pairs in Opts or to

View File

@ -603,6 +603,7 @@ func (v *SummaryVec) GetMetricWith(labels Labels) (Observer, error) {
// WithLabelValues works as GetMetricWithLabelValues, but panics where // WithLabelValues works as GetMetricWithLabelValues, but panics where
// GetMetricWithLabelValues would have returned an error. Not returning an // GetMetricWithLabelValues would have returned an error. Not returning an
// error allows shortcuts like // error allows shortcuts like
//
// myVec.WithLabelValues("404", "GET").Observe(42.21) // myVec.WithLabelValues("404", "GET").Observe(42.21)
func (v *SummaryVec) WithLabelValues(lvs ...string) Observer { func (v *SummaryVec) WithLabelValues(lvs ...string) Observer {
s, err := v.GetMetricWithLabelValues(lvs...) s, err := v.GetMetricWithLabelValues(lvs...)
@ -614,6 +615,7 @@ func (v *SummaryVec) WithLabelValues(lvs ...string) Observer {
// With works as GetMetricWith, but panics where GetMetricWithLabels would have // With works as GetMetricWith, but panics where GetMetricWithLabels would have
// returned an error. Not returning an error allows shortcuts like // returned an error. Not returning an error allows shortcuts like
//
// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Observe(42.21) // myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Observe(42.21)
func (v *SummaryVec) With(labels Labels) Observer { func (v *SummaryVec) With(labels Labels) Observer {
s, err := v.GetMetricWith(labels) s, err := v.GetMetricWith(labels)
@ -701,6 +703,7 @@ func (s *constSummary) Write(out *dto.Metric) error {
// //
// quantiles maps ranks to quantile values. For example, a median latency of // quantiles maps ranks to quantile values. For example, a median latency of
// 0.23s and a 99th percentile latency of 0.56s would be expressed as: // 0.23s and a 99th percentile latency of 0.56s would be expressed as:
//
// map[float64]float64{0.5: 0.23, 0.99: 0.56} // map[float64]float64{0.5: 0.23, 0.99: 0.56}
// //
// NewConstSummary returns an error if the length of labelValues is not // NewConstSummary returns an error if the length of labelValues is not

View File

@ -25,6 +25,7 @@ type Timer struct {
// NewTimer creates a new Timer. The provided Observer is used to observe a // NewTimer creates a new Timer. The provided Observer is used to observe a
// duration in seconds. Timer is usually used to time a function call in the // duration in seconds. Timer is usually used to time a function call in the
// following way: // following way:
//
// func TimeMe() { // func TimeMe() {
// timer := NewTimer(myHistogram) // timer := NewTimer(myHistogram)
// defer timer.ObserveDuration() // defer timer.ObserveDuration()