Skip to content

Commit 5b19c55

Browse files
committed
Merge branch 'master' into sparsehistogram
2 parents dfbcc28 + dc1559e commit 5b19c55

File tree

13 files changed

+172
-54
lines changed

13 files changed

+172
-54
lines changed

.circleci/config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22
orbs:
33
go: circleci/[email protected]
4-
prometheus: prometheus/prometheus@0.11.0
4+
prometheus: prometheus/prometheus@0.15.0
55
jobs:
66
test:
77
parameters:
@@ -63,6 +63,8 @@ workflows:
6363
name: go-1-16
6464
go_version: "1.16"
6565
run_lint: true
66-
# Style and unused/missing packages are only checked against
67-
# the latest supported Go version.
66+
- test:
67+
name: go-1-17
68+
go_version: "1.17"
69+
run_lint: true
6870
run_style_and_unused: true

.github/workflows/golangci-lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
paths:
5+
- "go.sum"
6+
- "go.mod"
7+
- "**.go"
8+
- "scripts/errcheck_excludes.txt"
9+
- ".github/workflows/golangci-lint.yml"
10+
- ".golangci.yml"
11+
pull_request:
12+
paths:
13+
- "go.sum"
14+
- "go.mod"
15+
- "**.go"
16+
- "scripts/errcheck_excludes.txt"
17+
- ".github/workflows/golangci-lint.yml"
18+
- ".golangci.yml"
19+
20+
jobs:
21+
golangci:
22+
name: lint
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v2
27+
28+
- name: Lint
29+
uses: golangci/golangci-lint-action@v2
30+
with:
31+
version: v1.42.0

Makefile.common

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,23 @@ ifneq ($(shell which gotestsum),)
7878
endif
7979
endif
8080

81-
PROMU_VERSION ?= 0.12.0
81+
PROMU_VERSION ?= 0.13.0
8282
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
8383

8484
GOLANGCI_LINT :=
8585
GOLANGCI_LINT_OPTS ?=
86-
GOLANGCI_LINT_VERSION ?= v1.39.0
86+
GOLANGCI_LINT_VERSION ?= v1.42.0
8787
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8888
# windows isn't included here because of the path separator being different.
8989
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
9090
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
91-
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
91+
# If we're in CI and there is an Actions file, that means the linter
92+
# is being run in Actions, so we don't need to run it here.
93+
ifeq (,$(CIRCLE_JOB))
94+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
95+
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
96+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
97+
endif
9298
endif
9399
endif
94100

@@ -154,7 +160,7 @@ endif
154160
update-go-deps:
155161
@echo ">> updating Go dependencies"
156162
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
157-
$(GO) get $$m; \
163+
$(GO) get -d $$m; \
158164
done
159165
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
160166
ifneq (,$(wildcard vendor))

api/prometheus/v1/api.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const (
139139
epBuildinfo = apiPrefix + "/status/buildinfo"
140140
epRuntimeinfo = apiPrefix + "/status/runtimeinfo"
141141
epTSDB = apiPrefix + "/status/tsdb"
142+
epWalReplay = apiPrefix + "/status/walreplay"
142143
)
143144

144145
// AlertState models the state of an alert.
@@ -261,6 +262,8 @@ type API interface {
261262
Metadata(ctx context.Context, metric string, limit string) (map[string][]Metadata, error)
262263
// TSDB returns the cardinality statistics.
263264
TSDB(ctx context.Context) (TSDBResult, error)
265+
// WalReplay returns the current replay status of the wal.
266+
WalReplay(ctx context.Context) (WalReplayStatus, error)
264267
}
265268

266269
// AlertsResult contains the result from querying the alerts endpoint.
@@ -303,8 +306,6 @@ type RuntimeinfoResult struct {
303306
CWD string `json:"CWD"`
304307
ReloadConfigSuccess bool `json:"reloadConfigSuccess"`
305308
LastConfigTime time.Time `json:"lastConfigTime"`
306-
ChunkCount int `json:"chunkCount"`
307-
TimeSeriesCount int `json:"timeSeriesCount"`
308309
CorruptionCount int `json:"corruptionCount"`
309310
GoroutineCount int `json:"goroutineCount"`
310311
GOMAXPROCS int `json:"GOMAXPROCS"`
@@ -431,10 +432,27 @@ type queryResult struct {
431432

432433
// TSDBResult contains the result from querying the tsdb endpoint.
433434
type TSDBResult struct {
434-
SeriesCountByMetricName []Stat `json:"seriesCountByMetricName"`
435-
LabelValueCountByLabelName []Stat `json:"labelValueCountByLabelName"`
436-
MemoryInBytesByLabelName []Stat `json:"memoryInBytesByLabelName"`
437-
SeriesCountByLabelValuePair []Stat `json:"seriesCountByLabelValuePair"`
435+
HeadStats TSDBHeadStats `json:"headStats"`
436+
SeriesCountByMetricName []Stat `json:"seriesCountByMetricName"`
437+
LabelValueCountByLabelName []Stat `json:"labelValueCountByLabelName"`
438+
MemoryInBytesByLabelName []Stat `json:"memoryInBytesByLabelName"`
439+
SeriesCountByLabelValuePair []Stat `json:"seriesCountByLabelValuePair"`
440+
}
441+
442+
// TSDBHeadStats contains TSDB stats
443+
type TSDBHeadStats struct {
444+
NumSeries int `json:"numSeries"`
445+
NumLabelPairs int `json:"numLabelPairs"`
446+
ChunkCount int `json:"chunkCount"`
447+
MinTime int `json:"minTime"`
448+
MaxTime int `json:"maxTime"`
449+
}
450+
451+
// WalReplayStatus represents the wal replay status.
452+
type WalReplayStatus struct {
453+
Min int `json:"min"`
454+
Max int `json:"max"`
455+
Current int `json:"current"`
438456
}
439457

440458
// Stat models information about statistic value.
@@ -984,6 +1002,23 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
9841002
return res, json.Unmarshal(body, &res)
9851003
}
9861004

1005+
func (h *httpAPI) WalReplay(ctx context.Context) (WalReplayStatus, error) {
1006+
u := h.client.URL(epWalReplay, nil)
1007+
1008+
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
1009+
if err != nil {
1010+
return WalReplayStatus{}, err
1011+
}
1012+
1013+
_, body, _, err := h.client.Do(ctx, req)
1014+
if err != nil {
1015+
return WalReplayStatus{}, err
1016+
}
1017+
1018+
var res WalReplayStatus
1019+
return res, json.Unmarshal(body, &res)
1020+
}
1021+
9871022
func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime time.Time, endTime time.Time) ([]ExemplarQueryResult, error) {
9881023
u := h.client.URL(epQueryExemplars, nil)
9891024
q := u.Query()

api/prometheus/v1/api_test.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ func TestAPIs(t *testing.T) {
230230
}
231231
}
232232

233+
doWalReply := func() func() (interface{}, Warnings, error) {
234+
return func() (interface{}, Warnings, error) {
235+
v, err := promAPI.WalReplay(context.Background())
236+
return v, nil, err
237+
}
238+
}
239+
233240
doQueryExemplars := func(query string, startTime time.Time, endTime time.Time) func() (interface{}, Warnings, error) {
234241
return func() (interface{}, Warnings, error) {
235242
v, err := promAPI.QueryExemplars(context.Background(), query, startTime, endTime)
@@ -696,8 +703,6 @@ func TestAPIs(t *testing.T) {
696703
"CWD": "/prometheus",
697704
"reloadConfigSuccess": true,
698705
"lastConfigTime": "2020-05-18T15:52:56Z",
699-
"chunkCount": 72692,
700-
"timeSeriesCount": 18476,
701706
"corruptionCount": 0,
702707
"goroutineCount": 217,
703708
"GOMAXPROCS": 2,
@@ -710,8 +715,6 @@ func TestAPIs(t *testing.T) {
710715
CWD: "/prometheus",
711716
ReloadConfigSuccess: true,
712717
LastConfigTime: time.Date(2020, 5, 18, 15, 52, 56, 0, time.UTC),
713-
ChunkCount: 72692,
714-
TimeSeriesCount: 18476,
715718
CorruptionCount: 0,
716719
GoroutineCount: 217,
717720
GOMAXPROCS: 2,
@@ -1145,6 +1148,13 @@ func TestAPIs(t *testing.T) {
11451148
reqMethod: "GET",
11461149
reqPath: "/api/v1/status/tsdb",
11471150
inRes: map[string]interface{}{
1151+
"headStats": map[string]interface{}{
1152+
"numSeries": 18476,
1153+
"numLabelPairs": 4301,
1154+
"chunkCount": 72692,
1155+
"minTime": 1634644800304,
1156+
"maxTime": 1634650590304,
1157+
},
11481158
"seriesCountByMetricName": []interface{}{
11491159
map[string]interface{}{
11501160
"name": "kubelet_http_requests_duration_seconds_bucket",
@@ -1171,6 +1181,13 @@ func TestAPIs(t *testing.T) {
11711181
},
11721182
},
11731183
res: TSDBResult{
1184+
HeadStats: TSDBHeadStats{
1185+
NumSeries: 18476,
1186+
NumLabelPairs: 4301,
1187+
ChunkCount: 72692,
1188+
MinTime: 1634644800304,
1189+
MaxTime: 1634650590304,
1190+
},
11741191
SeriesCountByMetricName: []Stat{
11751192
{
11761193
Name: "kubelet_http_requests_duration_seconds_bucket",
@@ -1198,6 +1215,30 @@ func TestAPIs(t *testing.T) {
11981215
},
11991216
},
12001217

1218+
{
1219+
do: doWalReply(),
1220+
reqMethod: "GET",
1221+
reqPath: "/api/v1/status/walreplay",
1222+
inErr: fmt.Errorf("some error"),
1223+
err: fmt.Errorf("some error"),
1224+
},
1225+
1226+
{
1227+
do: doWalReply(),
1228+
reqMethod: "GET",
1229+
reqPath: "/api/v1/status/walreplay",
1230+
inRes: map[string]interface{}{
1231+
"min": 2,
1232+
"max": 5,
1233+
"current": 40,
1234+
},
1235+
res: WalReplayStatus{
1236+
Min: 2,
1237+
Max: 5,
1238+
Current: 40,
1239+
},
1240+
},
1241+
12011242
{
12021243
do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime),
12031244
reqMethod: "GET",

examples/random/main.go

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,46 @@ import (
2929
"github.com/prometheus/client_golang/prometheus/promhttp"
3030
)
3131

32-
var (
33-
addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
34-
uniformDomain = flag.Float64("uniform.domain", 0.0002, "The domain for the uniform distribution.")
35-
normDomain = flag.Float64("normal.domain", 0.0002, "The domain for the normal distribution.")
36-
normMean = flag.Float64("normal.mean", 0.00001, "The mean for the normal distribution.")
37-
oscillationPeriod = flag.Duration("oscillation-period", 10*time.Minute, "The duration of the rate oscillation period.")
38-
)
32+
func main() {
33+
var (
34+
addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
35+
uniformDomain = flag.Float64("uniform.domain", 0.0002, "The domain for the uniform distribution.")
36+
normDomain = flag.Float64("normal.domain", 0.0002, "The domain for the normal distribution.")
37+
normMean = flag.Float64("normal.mean", 0.00001, "The mean for the normal distribution.")
38+
oscillationPeriod = flag.Duration("oscillation-period", 10*time.Minute, "The duration of the rate oscillation period.")
39+
)
3940

40-
var (
41-
// Create a summary to track fictional interservice RPC latencies for three
42-
// distinct services with different latency distributions. These services are
43-
// differentiated via a "service" label.
44-
rpcDurations = prometheus.NewSummaryVec(
45-
prometheus.SummaryOpts{
46-
Name: "rpc_durations_seconds",
47-
Help: "RPC latency distributions.",
48-
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
49-
},
50-
[]string{"service"},
41+
flag.Parse()
42+
43+
var (
44+
// Create a summary to track fictional interservice RPC latencies for three
45+
// distinct services with different latency distributions. These services are
46+
// differentiated via a "service" label.
47+
rpcDurations = prometheus.NewSummaryVec(
48+
prometheus.SummaryOpts{
49+
Name: "rpc_durations_seconds",
50+
Help: "RPC latency distributions.",
51+
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
52+
},
53+
[]string{"service"},
54+
)
55+
// The same as above, but now as a histogram, and only for the normal
56+
// distribution. The buckets are targeted to the parameters of the
57+
// normal distribution, with 20 buckets centered on the mean, each
58+
// half-sigma wide.
59+
rpcDurationsHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
60+
Name: "rpc_durations_histogram_seconds",
61+
Help: "RPC latency distributions.",
62+
Buckets: prometheus.LinearBuckets(*normMean-5**normDomain, .5**normDomain, 20),
63+
SparseBucketsFactor: 1.1,
64+
})
5165
)
52-
// The same as above, but now as a histogram, and only for the normal
53-
// distribution. The buckets are targeted to the parameters of the
54-
// normal distribution, with 20 buckets centered on the mean, each
55-
// half-sigma wide.
56-
rpcDurationsHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
57-
Name: "rpc_durations_histogram_seconds",
58-
Help: "RPC latency distributions.",
59-
Buckets: prometheus.LinearBuckets(*normMean-5**normDomain, .5**normDomain, 20),
60-
SparseBucketsFactor: 1.1,
61-
})
62-
)
6366

64-
func init() {
6567
// Register the summary and the histogram with Prometheus's default registry.
6668
prometheus.MustRegister(rpcDurations)
6769
prometheus.MustRegister(rpcDurationsHistogram)
6870
// Add Go module build info.
6971
prometheus.MustRegister(prometheus.NewBuildInfoCollector())
70-
}
71-
72-
func main() {
73-
flag.Parse()
7472

7573
start := time.Now()
7674

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/prometheus/client_golang
22

33
require (
44
github.com/beorn7/perks v1.0.1
5-
github.com/cespare/xxhash/v2 v2.1.1
5+
github.com/cespare/xxhash/v2 v2.1.2
66
github.com/golang/protobuf v1.4.3
77
github.com/json-iterator/go v1.1.11
88
github.com/prometheus/client_model v0.2.1-0.20210624201024-61b6c1aac064

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
4343
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
4444
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
4545
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
46-
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
4746
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
47+
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
48+
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
4849
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
4950
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5051
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=

prometheus/collectors/dbstats_collector_go115.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14+
//go:build go1.15
1415
// +build go1.15
1516

1617
package collectors

prometheus/collectors/dbstats_collector_pre_go115.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14+
//go:build !go1.15
1415
// +build !go1.15
1516

1617
package collectors

0 commit comments

Comments
 (0)