Skip to content

Commit f2aba4a

Browse files
authored
Merge pull request #258 from grafana/update-prometheus
Update prometheus
2 parents 06f1d3c + cf7aeb5 commit f2aba4a

41 files changed

Lines changed: 5356 additions & 4903 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.36.1 / 2022-06-09
4+
5+
* [BUGFIX] promtool: Add --lint-fatal option #10840
6+
37
## 2.36.0 / 2022-05-30
48

59
* [FEATURE] Add lowercase and uppercase relabel action. #10641

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ui-install:
4545

4646
.PHONY: ui-build
4747
ui-build:
48-
cd $(UI_PATH) && npm run build
48+
cd $(UI_PATH) && CI="" npm run build
4949

5050
.PHONY: ui-build-module
5151
ui-build-module:

Makefile.common

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,6 @@ GO_VERSION ?= $(shell $(GO) version)
3636
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
3737
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
3838

39-
GOVENDOR :=
40-
GO111MODULE :=
41-
ifeq (, $(PRE_GO_111))
42-
ifneq (,$(wildcard go.mod))
43-
# Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
44-
GO111MODULE := on
45-
46-
ifneq (,$(wildcard vendor))
47-
# Always use the local vendor/ directory to satisfy the dependencies.
48-
GOOPTS := $(GOOPTS) -mod=vendor
49-
endif
50-
endif
51-
else
52-
ifneq (,$(wildcard go.mod))
53-
ifneq (,$(wildcard vendor))
54-
$(warning This repository requires Go >= 1.11 because of Go modules)
55-
$(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
56-
endif
57-
else
58-
# This repository isn't using Go modules (yet).
59-
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
60-
endif
61-
endif
6239
PROMU := $(FIRST_GOPATH)/bin/promu
6340
pkgs = ./...
6441

@@ -152,58 +129,47 @@ common-check_license:
152129
.PHONY: common-deps
153130
common-deps:
154131
@echo ">> getting dependencies"
155-
ifdef GO111MODULE
156-
GO111MODULE=$(GO111MODULE) $(GO) mod download
157-
else
158-
$(GO) get $(GOOPTS) -t ./...
159-
endif
132+
$(GO) mod download
160133

161134
.PHONY: update-go-deps
162135
update-go-deps:
163136
@echo ">> updating Go dependencies"
164137
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
165138
$(GO) get -d $$m; \
166139
done
167-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
168-
ifneq (,$(wildcard vendor))
169-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
170-
endif
140+
$(GO) mod tidy
171141

172142
.PHONY: common-test-short
173143
common-test-short: $(GOTEST_DIR)
174144
@echo ">> running short tests"
175-
GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
145+
$(GOTEST) -short $(GOOPTS) $(pkgs)
176146

177147
.PHONY: common-test
178148
common-test: $(GOTEST_DIR)
179149
@echo ">> running all tests"
180-
GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
150+
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
181151

182152
$(GOTEST_DIR):
183153
@mkdir -p $@
184154

185155
.PHONY: common-format
186156
common-format:
187157
@echo ">> formatting code"
188-
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
158+
$(GO) fmt $(pkgs)
189159

190160
.PHONY: common-vet
191161
common-vet:
192162
@echo ">> vetting code"
193-
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
163+
$(GO) vet $(GOOPTS) $(pkgs)
194164

195165
.PHONY: common-lint
196166
common-lint: $(GOLANGCI_LINT)
197167
ifdef GOLANGCI_LINT
198168
@echo ">> running golangci-lint"
199-
ifdef GO111MODULE
200169
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
201170
# Otherwise staticcheck might fail randomly for some reason not yet explained.
202-
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
203-
GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
204-
else
205-
$(GOLANGCI_LINT) run $(pkgs)
206-
endif
171+
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
172+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
207173
endif
208174

209175
.PHONY: common-yamllint
@@ -220,28 +186,15 @@ endif
220186
common-staticcheck: lint
221187

222188
.PHONY: common-unused
223-
common-unused: $(GOVENDOR)
224-
ifdef GOVENDOR
225-
@echo ">> running check for unused packages"
226-
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
227-
else
228-
ifdef GO111MODULE
189+
common-unused:
229190
@echo ">> running check for unused/missing packages in go.mod"
230-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
231-
ifeq (,$(wildcard vendor))
191+
$(GO) mod tidy
232192
@git diff --exit-code -- go.sum go.mod
233-
else
234-
@echo ">> running check for unused packages in vendor/"
235-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
236-
@git diff --exit-code -- go.sum go.mod vendor/
237-
endif
238-
endif
239-
endif
240193

241194
.PHONY: common-build
242195
common-build: promu
243196
@echo ">> building binaries"
244-
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
197+
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
245198

246199
.PHONY: common-tarball
247200
common-tarball: promu
@@ -297,12 +250,6 @@ $(GOLANGCI_LINT):
297250
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
298251
endif
299252

300-
ifdef GOVENDOR
301-
.PHONY: $(GOVENDOR)
302-
$(GOVENDOR):
303-
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
304-
endif
305-
306253
.PHONY: precheck
307254
precheck::
308255

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ To build Prometheus from source code, You need:
6363
* NodeJS [version 16 or greater](https://nodejs.org/).
6464
* npm [version 7 or greater](https://www.npmjs.com/).
6565

66-
You can directly use the `go` tool to download and install the `prometheus`
66+
Start by cloning the repository:
67+
68+
```bash
69+
git clone https://github.com/prometheus/prometheus.git
70+
cd prometheus
71+
```
72+
73+
You can use the `go` tool to build and install the `prometheus`
6774
and `promtool` binaries into your `GOPATH`:
6875

6976
```bash
@@ -79,14 +86,10 @@ React UI unless it has been built explicitly using `make assets` or `make build`
7986

8087
An example of the above configuration file can be found [here.](https://github.com/prometheus/prometheus/blob/main/documentation/examples/prometheus.yml)
8188

82-
You can also clone the repository yourself and build using `make build`, which will compile in
83-
the web assets so that Prometheus can be run from anywhere:
89+
You can also build using `make build`, which will compile in the web assets so that
90+
Prometheus can be run from anywhere:
8491

8592
```bash
86-
mkdir -p $GOPATH/src/github.com/prometheus
87-
cd $GOPATH/src/github.com/prometheus
88-
git clone https://github.com/prometheus/prometheus.git
89-
cd prometheus
9093
make build
9194
./prometheus --config.file=your_config.yml
9295
```

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.36.0
1+
2.36.1

discovery/http/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ func NewDiscovery(conf *SDConfig, logger log.Logger, clientOpts []config.HTTPCli
136136
logger,
137137
"http",
138138
time.Duration(conf.RefreshInterval),
139-
d.refresh,
139+
d.Refresh,
140140
)
141141
return d, nil
142142
}
143143

144-
func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
144+
func (d *Discovery) Refresh(ctx context.Context) ([]*targetgroup.Group, error) {
145145
req, err := http.NewRequest("GET", d.url, nil)
146146
if err != nil {
147147
return nil, err

discovery/http/http_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestHTTPValidRefresh(t *testing.T) {
4545
require.NoError(t, err)
4646

4747
ctx := context.Background()
48-
tgs, err := d.refresh(ctx)
48+
tgs, err := d.Refresh(ctx)
4949
require.NoError(t, err)
5050

5151
expectedTargets := []*targetgroup.Group{
@@ -83,7 +83,7 @@ func TestHTTPInvalidCode(t *testing.T) {
8383
require.NoError(t, err)
8484

8585
ctx := context.Background()
86-
_, err = d.refresh(ctx)
86+
_, err = d.Refresh(ctx)
8787
require.EqualError(t, err, "server returned HTTP status 400 Bad Request")
8888
require.Equal(t, 1.0, getFailureCount())
8989
}
@@ -105,7 +105,7 @@ func TestHTTPInvalidFormat(t *testing.T) {
105105
require.NoError(t, err)
106106

107107
ctx := context.Background()
108-
_, err = d.refresh(ctx)
108+
_, err = d.Refresh(ctx)
109109
require.EqualError(t, err, `unsupported content type "text/plain; charset=utf-8"`)
110110
require.Equal(t, 1.0, getFailureCount())
111111
}
@@ -423,7 +423,7 @@ func TestSourceDisappeared(t *testing.T) {
423423
ctx := context.Background()
424424
for i, res := range test.responses {
425425
stubResponse = res
426-
tgs, err := d.refresh(ctx)
426+
tgs, err := d.Refresh(ctx)
427427
require.NoError(t, err)
428428
require.Equal(t, test.expectedTargets[i], tgs)
429429
}

discovery/manager.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ type poolKey struct {
7575
provider string
7676
}
7777

78-
// provider holds a Discoverer instance, its configuration, cancel func and its subscribers.
79-
type provider struct {
78+
// Provider holds a Discoverer instance, its configuration, cancel func and its subscribers.
79+
type Provider struct {
8080
name string
8181
d Discoverer
8282
config interface{}
@@ -92,11 +92,20 @@ type provider struct {
9292
newSubs map[string]struct{}
9393
}
9494

95+
// Discoverer return the Discoverer of the provider
96+
func (p *Provider) Discoverer() Discoverer {
97+
return p.d
98+
}
99+
95100
// IsStarted return true if Discoverer is started.
96-
func (p *provider) IsStarted() bool {
101+
func (p *Provider) IsStarted() bool {
97102
return p.cancel != nil
98103
}
99104

105+
func (p *Provider) Config() interface{} {
106+
return p.config
107+
}
108+
100109
// NewManager is the Discovery Manager constructor.
101110
func NewManager(ctx context.Context, logger log.Logger, options ...func(*Manager)) *Manager {
102111
if logger == nil {
@@ -148,7 +157,7 @@ type Manager struct {
148157
targetsMtx sync.Mutex
149158

150159
// providers keeps track of SD providers.
151-
providers []*provider
160+
providers []*Provider
152161
// The sync channel sends the updates as a map where the key is the job value from the scrape config.
153162
syncCh chan map[string][]*targetgroup.Group
154163

@@ -163,6 +172,11 @@ type Manager struct {
163172
lastProvider uint
164173
}
165174

175+
// Providers returns the currently configured SD providers.
176+
func (m *Manager) Providers() []*Provider {
177+
return m.providers
178+
}
179+
166180
// Run starts the background processing.
167181
func (m *Manager) Run() error {
168182
go m.sender()
@@ -194,7 +208,7 @@ func (m *Manager) ApplyConfig(cfg map[string]Configs) error {
194208
wg sync.WaitGroup
195209
// keep shows if we keep any providers after reload.
196210
keep bool
197-
newProviders []*provider
211+
newProviders []*Provider
198212
)
199213
for _, prov := range m.providers {
200214
// Cancel obsolete providers.
@@ -260,7 +274,7 @@ func (m *Manager) ApplyConfig(cfg map[string]Configs) error {
260274

261275
// StartCustomProvider is used for sdtool. Only use this if you know what you're doing.
262276
func (m *Manager) StartCustomProvider(ctx context.Context, name string, worker Discoverer) {
263-
p := &provider{
277+
p := &Provider{
264278
name: name,
265279
d: worker,
266280
subs: map[string]struct{}{
@@ -271,7 +285,7 @@ func (m *Manager) StartCustomProvider(ctx context.Context, name string, worker D
271285
m.startProvider(ctx, p)
272286
}
273287

274-
func (m *Manager) startProvider(ctx context.Context, p *provider) {
288+
func (m *Manager) startProvider(ctx context.Context, p *Provider) {
275289
level.Debug(m.logger).Log("msg", "Starting provider", "provider", p.name, "subs", fmt.Sprintf("%v", p.subs))
276290
ctx, cancel := context.WithCancel(ctx)
277291
updates := make(chan []*targetgroup.Group)
@@ -283,7 +297,7 @@ func (m *Manager) startProvider(ctx context.Context, p *provider) {
283297
}
284298

285299
// cleaner cleans resources associated with provider.
286-
func (m *Manager) cleaner(p *provider) {
300+
func (m *Manager) cleaner(p *Provider) {
287301
m.targetsMtx.Lock()
288302
p.mu.RLock()
289303
for s := range p.subs {
@@ -296,7 +310,7 @@ func (m *Manager) cleaner(p *provider) {
296310
}
297311
}
298312

299-
func (m *Manager) updater(ctx context.Context, p *provider, updates chan []*targetgroup.Group) {
313+
func (m *Manager) updater(ctx context.Context, p *Provider, updates chan []*targetgroup.Group) {
300314
// Ensure targets from this provider are cleaned up.
301315
defer m.cleaner(p)
302316
for {
@@ -422,7 +436,7 @@ func (m *Manager) registerProviders(cfgs Configs, setName string) int {
422436
failed++
423437
return
424438
}
425-
m.providers = append(m.providers, &provider{
439+
m.providers = append(m.providers, &Provider{
426440
name: fmt.Sprintf("%s/%d", typ, m.lastProvider),
427441
d: d,
428442
config: cfg,

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ require (
4747
github.com/prometheus/exporter-toolkit v0.7.1
4848
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9
4949
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
50-
github.com/stretchr/testify v1.7.1
50+
github.com/stretchr/testify v1.7.2
5151
github.com/vultr/govultr/v2 v2.17.1
5252
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0
5353
go.opentelemetry.io/otel v1.7.0
@@ -74,7 +74,7 @@ require (
7474
gopkg.in/yaml.v3 v3.0.1
7575
k8s.io/api v0.24.1
7676
k8s.io/apimachinery v0.24.1
77-
k8s.io/client-go v0.24.0
77+
k8s.io/client-go v0.24.1
7878
k8s.io/klog v1.0.0
7979
k8s.io/klog/v2 v2.60.1
8080
)

0 commit comments

Comments
 (0)