Skip to content

Commit 160aee1

Browse files
authored
Merge pull request #77 from grafana/syncp
Sync with Prometheus main
2 parents cc9ddf5 + df36efb commit 160aee1

62 files changed

Lines changed: 1613 additions & 696 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 2.32.0-rc.0 / 2021-12-01
2+
3+
This list of changes is relative to [v2.32.0-beta.0](https://github.com/prometheus/prometheus/releases/tag/v2.32.0-beta.0), which was a special 2.32 beta release to pre-publish the Prometheus Agent features.
4+
5+
* [FEATURE] TSDB: Add support for forwarding exemplars in Agent mode. #9664
6+
* [FEATURE] UI: Adapt web UI for Prometheus Agent mode. #9851
7+
* [ENHANCEMENT] Linode SD: Tune API request page sizes. #9779
8+
* [BUGFIX] TSDB: Fix panic when checkpoint directory is empty. #9687
9+
* [BUGFIX] TSDB: Fix panic, out of order chunks, and race warning during WAL replay. #9856
10+
* [BUGFIX] UI: Correctly render links for targets with IPv6 addresses that contain a Zone ID. #9853
11+
* [BUGFIX] Promtool: Fix checking of `authorization.credentials_file` and `bearer_token_file` fields. #9883
12+
113
## 2.32.0-beta.0 / 2021-11-16
214

315
This beta release introduces the Prometheus Agent, a new mode of operation for

NOTICE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ https://github.com/dgryski/go-tsz
9191
Copyright (c) 2015,2016 Damian Gryski <damian@gryski.com>
9292
See https://github.com/dgryski/go-tsz/blob/master/LICENSE for license details.
9393

94+
The Go programming language
95+
https://go.dev/
96+
Copyright (c) 2009 The Go Authors
97+
See https://go.dev/LICENSE for license details.
98+
9499
The Codicon icon font from Microsoft
95100
https://github.com/microsoft/vscode-codicons
96101
Copyright (c) Microsoft Corporation and other contributors

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.32.0-beta.0
1+
2.32.0-rc.0

cmd/promtool/main.go

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func main() {
7373
"config-files",
7474
"The config files to check.",
7575
).Required().ExistingFiles()
76+
checkConfigSyntaxOnly := checkConfigCmd.Flag("syntax-only", "Only check the config file syntax, ignoring file and content validation referenced in the config").Bool()
7677

7778
checkWebConfigCmd := checkCmd.Command("web-config", "Check if the web config files are valid or not.")
7879
webConfigFiles := checkWebConfigCmd.Arg(
@@ -211,7 +212,7 @@ func main() {
211212
os.Exit(CheckSD(*sdConfigFile, *sdJobName, *sdTimeout))
212213

213214
case checkConfigCmd.FullCommand():
214-
os.Exit(CheckConfig(*agentMode, *configFiles...))
215+
os.Exit(CheckConfig(*agentMode, *checkConfigSyntaxOnly, *configFiles...))
215216

216217
case checkWebConfigCmd.FullCommand():
217218
os.Exit(CheckWebConfig(*webConfigFiles...))
@@ -267,16 +268,19 @@ func main() {
267268
}
268269

269270
// CheckConfig validates configuration files.
270-
func CheckConfig(agentMode bool, files ...string) int {
271+
func CheckConfig(agentMode, checkSyntaxOnly bool, files ...string) int {
271272
failed := false
272273

273274
for _, f := range files {
274-
ruleFiles, err := checkConfig(agentMode, f)
275+
ruleFiles, err := checkConfig(agentMode, f, checkSyntaxOnly)
275276
if err != nil {
276277
fmt.Fprintln(os.Stderr, " FAILED:", err)
277278
failed = true
278279
} else {
279-
fmt.Printf(" SUCCESS: %d rule files found\n", len(ruleFiles))
280+
if len(ruleFiles) > 0 {
281+
fmt.Printf(" SUCCESS: %d rule files found\n", len(ruleFiles))
282+
}
283+
fmt.Printf(" SUCCESS: %s is valid prometheus config file syntax\n", f)
280284
}
281285
fmt.Println()
282286

@@ -326,7 +330,7 @@ func checkFileExists(fn string) error {
326330
return err
327331
}
328332

329-
func checkConfig(agentMode bool, filename string) ([]string, error) {
333+
func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]string, error) {
330334
fmt.Println("Checking", filename)
331335

332336
cfg, err := config.LoadFile(filename, agentMode, false, log.NewNopLogger())
@@ -335,39 +339,46 @@ func checkConfig(agentMode bool, filename string) ([]string, error) {
335339
}
336340

337341
var ruleFiles []string
338-
for _, rf := range cfg.RuleFiles {
339-
rfs, err := filepath.Glob(rf)
340-
if err != nil {
341-
return nil, err
342-
}
343-
// If an explicit file was given, error if it is not accessible.
344-
if !strings.Contains(rf, "*") {
345-
if len(rfs) == 0 {
346-
return nil, errors.Errorf("%q does not point to an existing file", rf)
342+
if !checkSyntaxOnly {
343+
for _, rf := range cfg.RuleFiles {
344+
rfs, err := filepath.Glob(rf)
345+
if err != nil {
346+
return nil, err
347347
}
348-
if err := checkFileExists(rfs[0]); err != nil {
349-
return nil, errors.Wrapf(err, "error checking rule file %q", rfs[0])
348+
// If an explicit file was given, error if it is not accessible.
349+
if !strings.Contains(rf, "*") {
350+
if len(rfs) == 0 {
351+
return nil, errors.Errorf("%q does not point to an existing file", rf)
352+
}
353+
if err := checkFileExists(rfs[0]); err != nil {
354+
return nil, errors.Wrapf(err, "error checking rule file %q", rfs[0])
355+
}
350356
}
357+
ruleFiles = append(ruleFiles, rfs...)
351358
}
352-
ruleFiles = append(ruleFiles, rfs...)
353359
}
354360

355361
for _, scfg := range cfg.ScrapeConfigs {
356-
if err := checkFileExists(scfg.HTTPClientConfig.BearerTokenFile); err != nil {
357-
return nil, errors.Wrapf(err, "error checking bearer token file %q", scfg.HTTPClientConfig.BearerTokenFile)
362+
if !checkSyntaxOnly && scfg.HTTPClientConfig.Authorization != nil {
363+
if err := checkFileExists(scfg.HTTPClientConfig.Authorization.CredentialsFile); err != nil {
364+
return nil, errors.Wrapf(err, "error checking authorization credentials or bearer token file %q", scfg.HTTPClientConfig.Authorization.CredentialsFile)
365+
}
358366
}
359367

360-
if err := checkTLSConfig(scfg.HTTPClientConfig.TLSConfig); err != nil {
368+
if err := checkTLSConfig(scfg.HTTPClientConfig.TLSConfig, checkSyntaxOnly); err != nil {
361369
return nil, err
362370
}
363371

364372
for _, c := range scfg.ServiceDiscoveryConfigs {
365373
switch c := c.(type) {
366374
case *kubernetes.SDConfig:
367-
if err := checkTLSConfig(c.HTTPClientConfig.TLSConfig); err != nil {
375+
if err := checkTLSConfig(c.HTTPClientConfig.TLSConfig, checkSyntaxOnly); err != nil {
368376
return nil, err
369377
}
370378
case *file.SDConfig:
379+
if checkSyntaxOnly {
380+
break
381+
}
371382
for _, file := range c.Files {
372383
files, err := filepath.Glob(file)
373384
if err != nil {
@@ -401,6 +412,9 @@ func checkConfig(agentMode bool, filename string) ([]string, error) {
401412
for _, c := range amcfg.ServiceDiscoveryConfigs {
402413
switch c := c.(type) {
403414
case *file.SDConfig:
415+
if checkSyntaxOnly {
416+
break
417+
}
404418
for _, file := range c.Files {
405419
files, err := filepath.Glob(file)
406420
if err != nil {
@@ -432,21 +446,25 @@ func checkConfig(agentMode bool, filename string) ([]string, error) {
432446
return ruleFiles, nil
433447
}
434448

435-
func checkTLSConfig(tlsConfig config_util.TLSConfig) error {
436-
if err := checkFileExists(tlsConfig.CertFile); err != nil {
437-
return errors.Wrapf(err, "error checking client cert file %q", tlsConfig.CertFile)
438-
}
439-
if err := checkFileExists(tlsConfig.KeyFile); err != nil {
440-
return errors.Wrapf(err, "error checking client key file %q", tlsConfig.KeyFile)
441-
}
442-
449+
func checkTLSConfig(tlsConfig config_util.TLSConfig, checkSyntaxOnly bool) error {
443450
if len(tlsConfig.CertFile) > 0 && len(tlsConfig.KeyFile) == 0 {
444451
return errors.Errorf("client cert file %q specified without client key file", tlsConfig.CertFile)
445452
}
446453
if len(tlsConfig.KeyFile) > 0 && len(tlsConfig.CertFile) == 0 {
447454
return errors.Errorf("client key file %q specified without client cert file", tlsConfig.KeyFile)
448455
}
449456

457+
if checkSyntaxOnly {
458+
return nil
459+
}
460+
461+
if err := checkFileExists(tlsConfig.CertFile); err != nil {
462+
return errors.Wrapf(err, "error checking client cert file %q", tlsConfig.CertFile)
463+
}
464+
if err := checkFileExists(tlsConfig.KeyFile); err != nil {
465+
return errors.Wrapf(err, "error checking client key file %q", tlsConfig.KeyFile)
466+
}
467+
450468
return nil
451469
}
452470

cmd/promtool/main_test.go

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"net/http"
1919
"net/http/httptest"
2020
"net/url"
21+
"runtime"
22+
"strings"
2123
"testing"
2224
"time"
2325

@@ -194,7 +196,7 @@ func TestCheckTargetConfig(t *testing.T) {
194196
}
195197
for _, test := range cases {
196198
t.Run(test.name, func(t *testing.T) {
197-
_, err := checkConfig(false, "testdata/"+test.file)
199+
_, err := checkConfig(false, "testdata/"+test.file, false)
198200
if test.err != "" {
199201
require.Equalf(t, test.err, err.Error(), "Expected error %q, got %q", test.err, err.Error())
200202
return
@@ -203,3 +205,120 @@ func TestCheckTargetConfig(t *testing.T) {
203205
})
204206
}
205207
}
208+
209+
func TestCheckConfigSyntax(t *testing.T) {
210+
cases := []struct {
211+
name string
212+
file string
213+
syntaxOnly bool
214+
err string
215+
errWindows string
216+
}{
217+
{
218+
name: "check with syntax only succeeds with nonexistent rule files",
219+
file: "config_with_rule_files.yml",
220+
syntaxOnly: true,
221+
err: "",
222+
errWindows: "",
223+
},
224+
{
225+
name: "check without syntax only fails with nonexistent rule files",
226+
file: "config_with_rule_files.yml",
227+
syntaxOnly: false,
228+
err: "\"testdata/non-existent-file.yml\" does not point to an existing file",
229+
errWindows: "\"testdata\\\\non-existent-file.yml\" does not point to an existing file",
230+
},
231+
{
232+
name: "check with syntax only succeeds with nonexistent service discovery files",
233+
file: "config_with_service_discovery_files.yml",
234+
syntaxOnly: true,
235+
err: "",
236+
errWindows: "",
237+
},
238+
// The test below doesn't fail because the file verification for ServiceDiscoveryConfigs doesn't fail the check if
239+
// file isn't found; it only outputs a warning message.
240+
{
241+
name: "check without syntax only succeeds with nonexistent service discovery files",
242+
file: "config_with_service_discovery_files.yml",
243+
syntaxOnly: false,
244+
err: "",
245+
errWindows: "",
246+
},
247+
{
248+
name: "check with syntax only succeeds with nonexistent TLS files",
249+
file: "config_with_tls_files.yml",
250+
syntaxOnly: true,
251+
err: "",
252+
errWindows: "",
253+
},
254+
{
255+
name: "check without syntax only fails with nonexistent TLS files",
256+
file: "config_with_tls_files.yml",
257+
syntaxOnly: false,
258+
err: "error checking client cert file \"testdata/nonexistent_cert_file.yml\": " +
259+
"stat testdata/nonexistent_cert_file.yml: no such file or directory",
260+
errWindows: "error checking client cert file \"testdata\\\\nonexistent_cert_file.yml\": " +
261+
"CreateFile testdata\\nonexistent_cert_file.yml: The system cannot find the file specified.",
262+
},
263+
{
264+
name: "check with syntax only succeeds with nonexistent credentials file",
265+
file: "authorization_credentials_file.bad.yml",
266+
syntaxOnly: true,
267+
err: "",
268+
errWindows: "",
269+
},
270+
{
271+
name: "check without syntax only fails with nonexistent credentials file",
272+
file: "authorization_credentials_file.bad.yml",
273+
syntaxOnly: false,
274+
err: "error checking authorization credentials or bearer token file \"/random/file/which/does/not/exist.yml\": " +
275+
"stat /random/file/which/does/not/exist.yml: no such file or directory",
276+
errWindows: "error checking authorization credentials or bearer token file \"testdata\\\\random\\\\file\\\\which\\\\does\\\\not\\\\exist.yml\": " +
277+
"CreateFile testdata\\random\\file\\which\\does\\not\\exist.yml: The system cannot find the path specified.",
278+
},
279+
}
280+
for _, test := range cases {
281+
t.Run(test.name, func(t *testing.T) {
282+
_, err := checkConfig(false, "testdata/"+test.file, test.syntaxOnly)
283+
expectedErrMsg := test.err
284+
if strings.Contains(runtime.GOOS, "windows") {
285+
expectedErrMsg = test.errWindows
286+
}
287+
if expectedErrMsg != "" {
288+
require.Equalf(t, expectedErrMsg, err.Error(), "Expected error %q, got %q", test.err, err.Error())
289+
return
290+
}
291+
require.NoError(t, err)
292+
})
293+
}
294+
}
295+
296+
func TestAuthorizationConfig(t *testing.T) {
297+
cases := []struct {
298+
name string
299+
file string
300+
err string
301+
}{
302+
{
303+
name: "authorization_credentials_file.bad",
304+
file: "authorization_credentials_file.bad.yml",
305+
err: "error checking authorization credentials or bearer token file",
306+
},
307+
{
308+
name: "authorization_credentials_file.good",
309+
file: "authorization_credentials_file.good.yml",
310+
err: "",
311+
},
312+
}
313+
314+
for _, test := range cases {
315+
t.Run(test.name, func(t *testing.T) {
316+
_, err := checkConfig(false, "testdata/"+test.file, false)
317+
if test.err != "" {
318+
require.Contains(t, err.Error(), test.err, "Expected error to contain %q, got %q", test.err, err.Error())
319+
return
320+
}
321+
require.NoError(t, err)
322+
})
323+
}
324+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scrape_configs:
2+
- job_name: test
3+
authorization:
4+
credentials_file: "/random/file/which/does/not/exist.yml"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scrape_configs:
2+
- job_name: test
3+
authorization:
4+
credentials_file: "."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rule_files:
2+
- non-existent-file.yml
3+
- /etc/non/existent/file.yml
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
scrape_configs:
2+
- job_name: prometheus
3+
file_sd_configs:
4+
- files:
5+
- nonexistent_file.yml
6+
alerting:
7+
alertmanagers:
8+
- scheme: http
9+
api_version: v1
10+
file_sd_configs:
11+
- files:
12+
- nonexistent_file.yml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scrape_configs:
2+
- job_name: "some job"
3+
tls_config:
4+
cert_file: nonexistent_cert_file.yml
5+
key_file: nonexistent_key_file.yml

0 commit comments

Comments
 (0)