Skip to content

Commit 294cca4

Browse files
committed
Merge branch 'main' into sparsehistogram
2 parents 70253f4 + 2e1c481 commit 294cca4

27 files changed

+2108
-434
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 1.12.1 / 2022-01-29
2+
3+
* [BUGFIX] Make the Go 1.17 collector concurrency-safe #969
4+
* Use simpler locking in the Go 1.17 collector #975
5+
* [BUGFIX] Reduce granularity of histogram buckets for Go 1.17 collector #974
6+
* [ENHANCEMENT] API client: make HTTP reads more efficient #976
7+
8+
## 1.12.0 / 2022-01-19
9+
10+
* [CHANGE] example/random: Move flags and metrics into main() #935
11+
* [FEATURE] API client: Support wal replay status api #944
12+
* [FEATURE] Use the runtime/metrics package for the Go collector for 1.17+ #955
13+
* [ENHANCEMENT] API client: Update /api/v1/status/tsdb to include headStats #925
14+
* [ENHANCEMENT] promhttp: Check validity of method and code label values #962
15+
116
## 1.11.0 / 2021-06-07
217

318
* [CHANGE] Add new collectors package. #862

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.0
1+
1.12.1

api/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
package api
1616

1717
import (
18+
"bytes"
1819
"context"
19-
"io/ioutil"
2020
"net"
2121
"net/http"
2222
"net/url"
@@ -111,7 +111,9 @@ func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response,
111111
var body []byte
112112
done := make(chan struct{})
113113
go func() {
114-
body, err = ioutil.ReadAll(resp.Body)
114+
var buf bytes.Buffer
115+
_, err = buf.ReadFrom(resp.Body)
116+
body = buf.Bytes()
115117
close(done)
116118
}()
117119

api/client_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
package api
1515

1616
import (
17+
"bytes"
18+
"context"
19+
"fmt"
1720
"net/http"
21+
"net/http/httptest"
1822
"net/url"
1923
"testing"
2024
)
@@ -111,3 +115,50 @@ func TestClientURL(t *testing.T) {
111115
}
112116
}
113117
}
118+
119+
// Serve any http request with a response of N KB of spaces.
120+
type serveSpaces struct {
121+
sizeKB int
122+
}
123+
124+
func (t serveSpaces) ServeHTTP(w http.ResponseWriter, req *http.Request) {
125+
kb := bytes.Repeat([]byte{' '}, 1024)
126+
for i := 0; i < t.sizeKB; i++ {
127+
w.Write(kb)
128+
}
129+
}
130+
131+
func BenchmarkClient(b *testing.B) {
132+
b.ReportAllocs()
133+
ctx := context.Background()
134+
135+
for _, sizeKB := range []int{4, 50, 1000, 2000} {
136+
b.Run(fmt.Sprintf("%dKB", sizeKB), func(b *testing.B) {
137+
138+
testServer := httptest.NewServer(serveSpaces{sizeKB})
139+
defer testServer.Close()
140+
141+
client, err := NewClient(Config{
142+
Address: testServer.URL,
143+
})
144+
if err != nil {
145+
b.Fatalf("Failed to initialize client: %v", err)
146+
}
147+
url, err := url.Parse(testServer.URL + "/prometheus/api/v1/query?query=up")
148+
if err != nil {
149+
b.Fatalf("Failed to parse url: %v", err)
150+
}
151+
req := &http.Request{
152+
URL: url,
153+
}
154+
b.ResetTimer()
155+
for i := 0; i < b.N; i++ {
156+
_, _, err := client.Do(ctx, req)
157+
if err != nil {
158+
b.Fatalf("Query failed: %v", err)
159+
}
160+
}
161+
b.StopTimer()
162+
})
163+
}
164+
}

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ module github.com/prometheus/client_golang
33
require (
44
github.com/beorn7/perks v1.0.1
55
github.com/cespare/xxhash/v2 v2.1.2
6-
github.com/golang/protobuf v1.4.3
7-
github.com/json-iterator/go v1.1.11
6+
github.com/golang/protobuf v1.5.2
7+
github.com/json-iterator/go v1.1.12
88
github.com/prometheus/client_model v0.2.1-0.20210624201024-61b6c1aac064
9-
github.com/prometheus/common v0.29.0
10-
github.com/prometheus/procfs v0.6.0
11-
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40
9+
github.com/prometheus/common v0.32.1
10+
github.com/prometheus/procfs v0.7.3
11+
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
12+
google.golang.org/protobuf v1.26.0
1213
)
1314

1415
go 1.13

go.sum

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
9393
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
9494
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
9595
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
96-
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
9796
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
97+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
98+
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
99+
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
98100
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
99101
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
100102
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -127,8 +129,9 @@ github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2E
127129
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
128130
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
129131
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
130-
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
131132
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
133+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
134+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
132135
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
133136
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
134137
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
@@ -148,8 +151,9 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
148151
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
149152
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
150153
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
151-
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
152154
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
155+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
156+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
153157
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
154158
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
155159
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -171,13 +175,14 @@ github.com/prometheus/client_model v0.2.1-0.20210624201024-61b6c1aac064/go.mod h
171175
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
172176
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
173177
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
174-
github.com/prometheus/common v0.29.0 h1:3jqPBvKT4OHAbje2Ql7KeaaSicDBCxMYwEJU1zRJceE=
175-
github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
178+
github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4=
179+
github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
176180
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
177181
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
178182
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
179-
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
180183
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
184+
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
185+
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
181186
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
182187
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
183188
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
@@ -312,8 +317,9 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
312317
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
313318
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
314319
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
315-
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q=
316320
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
321+
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
322+
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
317323
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
318324
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
319325
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -444,8 +450,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
444450
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
445451
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
446452
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
447-
google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ=
448453
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
454+
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
455+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
449456
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
450457
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
451458
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

prometheus/build_info_collector.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2021 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package prometheus
15+
16+
import "runtime/debug"
17+
18+
// NewBuildInfoCollector is the obsolete version of collectors.NewBuildInfoCollector.
19+
// See there for documentation.
20+
//
21+
// Deprecated: Use collectors.NewBuildInfoCollector instead.
22+
func NewBuildInfoCollector() Collector {
23+
path, version, sum := "unknown", "unknown", "unknown"
24+
if bi, ok := debug.ReadBuildInfo(); ok {
25+
path = bi.Main.Path
26+
version = bi.Main.Version
27+
sum = bi.Main.Sum
28+
}
29+
c := &selfCollector{MustNewConstMetric(
30+
NewDesc(
31+
"go_build_info",
32+
"Build information about the main Go module.",
33+
nil, Labels{"path": path, "version": version, "checksum": sum},
34+
),
35+
GaugeValue, 1)}
36+
c.init(c.self)
37+
return c
38+
}

prometheus/collector.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,11 @@ func (c *selfCollector) Describe(ch chan<- *Desc) {
118118
func (c *selfCollector) Collect(ch chan<- Metric) {
119119
ch <- c.self
120120
}
121+
122+
// collectorMetric is a metric that is also a collector.
123+
// Because of selfCollector, most (if not all) Metrics in
124+
// this package are also collectors.
125+
type collectorMetric interface {
126+
Metric
127+
Collector
128+
}

prometheus/counter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ func (c *counter) Inc() {
133133
atomic.AddUint64(&c.valInt, 1)
134134
}
135135

136-
func (c *counter) Write(out *dto.Metric) error {
136+
func (c *counter) get() float64 {
137137
fval := math.Float64frombits(atomic.LoadUint64(&c.valBits))
138138
ival := atomic.LoadUint64(&c.valInt)
139-
val := fval + float64(ival)
139+
return fval + float64(ival)
140+
}
141+
142+
func (c *counter) Write(out *dto.Metric) error {
143+
val := c.get()
140144

141145
var exemplar *dto.Exemplar
142146
if e := c.exemplar.Load(); e != nil {

prometheus/counter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
2323
"github.com/golang/protobuf/proto"
24-
"github.com/golang/protobuf/ptypes"
24+
"google.golang.org/protobuf/types/known/timestamppb"
2525

2626
dto "github.com/prometheus/client_model/go"
2727
)
@@ -225,8 +225,8 @@ func TestCounterExemplar(t *testing.T) {
225225
}).(*counter)
226226
counter.now = func() time.Time { return now }
227227

228-
ts, err := ptypes.TimestampProto(now)
229-
if err != nil {
228+
ts := timestamppb.New(now)
229+
if err := ts.CheckValid(); err != nil {
230230
t.Fatal(err)
231231
}
232232
expectedExemplar := &dto.Exemplar{

0 commit comments

Comments
 (0)