|
|
|
@ -17,6 +17,7 @@ import (
|
|
|
|
|
"bytes" |
|
|
|
|
"context" |
|
|
|
|
"encoding/json" |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"math" |
|
|
|
@ -32,7 +33,6 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/go-kit/log" |
|
|
|
|
"github.com/google/pprof/profile" |
|
|
|
|
"github.com/pkg/errors" |
|
|
|
|
"github.com/prometheus/client_golang/api" |
|
|
|
|
v1 "github.com/prometheus/client_golang/api/prometheus/v1" |
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp" |
|
|
|
@ -414,10 +414,10 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
|
|
|
|
|
// If an explicit file was given, error if it is not accessible.
|
|
|
|
|
if !strings.Contains(rf, "*") { |
|
|
|
|
if len(rfs) == 0 { |
|
|
|
|
return nil, errors.Errorf("%q does not point to an existing file", rf) |
|
|
|
|
return nil, fmt.Errorf("%q does not point to an existing file", rf) |
|
|
|
|
} |
|
|
|
|
if err := checkFileExists(rfs[0]); err != nil { |
|
|
|
|
return nil, errors.Wrapf(err, "error checking rule file %q", rfs[0]) |
|
|
|
|
return nil, fmt.Errorf("error checking rule file %q: %w", rfs[0], err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ruleFiles = append(ruleFiles, rfs...) |
|
|
|
@ -427,7 +427,7 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
|
|
|
|
|
for _, scfg := range cfg.ScrapeConfigs { |
|
|
|
|
if !checkSyntaxOnly && scfg.HTTPClientConfig.Authorization != nil { |
|
|
|
|
if err := checkFileExists(scfg.HTTPClientConfig.Authorization.CredentialsFile); err != nil { |
|
|
|
|
return nil, errors.Wrapf(err, "error checking authorization credentials or bearer token file %q", scfg.HTTPClientConfig.Authorization.CredentialsFile) |
|
|
|
|
return nil, fmt.Errorf("error checking authorization credentials or bearer token file %q: %w", scfg.HTTPClientConfig.Authorization.CredentialsFile, err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -455,7 +455,7 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
|
|
|
|
|
var targetGroups []*targetgroup.Group |
|
|
|
|
targetGroups, err = checkSDFile(f) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, errors.Errorf("checking SD file %q: %v", file, err) |
|
|
|
|
return nil, fmt.Errorf("checking SD file %q: %w", file, err) |
|
|
|
|
} |
|
|
|
|
if err := checkTargetGroupsForScrapeConfig(targetGroups, scfg); err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -491,7 +491,7 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
|
|
|
|
|
var targetGroups []*targetgroup.Group |
|
|
|
|
targetGroups, err = checkSDFile(f) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, errors.Errorf("checking SD file %q: %v", file, err) |
|
|
|
|
return nil, fmt.Errorf("checking SD file %q: %w", file, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := checkTargetGroupsForAlertmanager(targetGroups, amcfg); err != nil { |
|
|
|
@ -514,10 +514,10 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
|
|
|
|
|
|
|
|
|
|
func checkTLSConfig(tlsConfig config_util.TLSConfig, checkSyntaxOnly bool) error { |
|
|
|
|
if len(tlsConfig.CertFile) > 0 && len(tlsConfig.KeyFile) == 0 { |
|
|
|
|
return errors.Errorf("client cert file %q specified without client key file", tlsConfig.CertFile) |
|
|
|
|
return fmt.Errorf("client cert file %q specified without client key file", tlsConfig.CertFile) |
|
|
|
|
} |
|
|
|
|
if len(tlsConfig.KeyFile) > 0 && len(tlsConfig.CertFile) == 0 { |
|
|
|
|
return errors.Errorf("client key file %q specified without client cert file", tlsConfig.KeyFile) |
|
|
|
|
return fmt.Errorf("client key file %q specified without client cert file", tlsConfig.KeyFile) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if checkSyntaxOnly { |
|
|
|
@ -525,10 +525,10 @@ func checkTLSConfig(tlsConfig config_util.TLSConfig, checkSyntaxOnly bool) error
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := checkFileExists(tlsConfig.CertFile); err != nil { |
|
|
|
|
return errors.Wrapf(err, "error checking client cert file %q", tlsConfig.CertFile) |
|
|
|
|
return fmt.Errorf("error checking client cert file %q: %w", tlsConfig.CertFile, err) |
|
|
|
|
} |
|
|
|
|
if err := checkFileExists(tlsConfig.KeyFile); err != nil { |
|
|
|
|
return errors.Wrapf(err, "error checking client key file %q", tlsConfig.KeyFile) |
|
|
|
|
return fmt.Errorf("error checking client key file %q: %w", tlsConfig.KeyFile, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
@ -558,12 +558,12 @@ func checkSDFile(filename string) ([]*targetgroup.Group, error) {
|
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
return nil, errors.Errorf("invalid file extension: %q", ext) |
|
|
|
|
return nil, fmt.Errorf("invalid file extension: %q", ext) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for i, tg := range targetGroups { |
|
|
|
|
if tg == nil { |
|
|
|
|
return nil, errors.Errorf("nil target group item found (index %d)", i) |
|
|
|
|
return nil, fmt.Errorf("nil target group item found (index %d)", i) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -992,14 +992,14 @@ func parseStartTimeAndEndTime(start, end string) (time.Time, time.Time, error) {
|
|
|
|
|
if start != "" { |
|
|
|
|
stime, err = parseTime(start) |
|
|
|
|
if err != nil { |
|
|
|
|
return stime, etime, errors.Wrap(err, "error parsing start time") |
|
|
|
|
return stime, etime, fmt.Errorf("error parsing start time: %w", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if end != "" { |
|
|
|
|
etime, err = parseTime(end) |
|
|
|
|
if err != nil { |
|
|
|
|
return stime, etime, errors.Wrap(err, "error parsing end time") |
|
|
|
|
return stime, etime, fmt.Errorf("error parsing end time: %w", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return stime, etime, nil |
|
|
|
@ -1013,7 +1013,7 @@ func parseTime(s string) (time.Time, error) {
|
|
|
|
|
if t, err := time.Parse(time.RFC3339Nano, s); err == nil { |
|
|
|
|
return t, nil |
|
|
|
|
} |
|
|
|
|
return time.Time{}, errors.Errorf("cannot parse %q to a valid timestamp", s) |
|
|
|
|
return time.Time{}, fmt.Errorf("cannot parse %q to a valid timestamp", s) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type endpointsGroup struct { |
|
|
|
@ -1039,7 +1039,7 @@ var (
|
|
|
|
|
} |
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
if err := p.WriteUncompressed(&buf); err != nil { |
|
|
|
|
return nil, errors.Wrap(err, "writing the profile to the buffer") |
|
|
|
|
return nil, fmt.Errorf("writing the profile to the buffer: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return buf.Bytes(), nil |
|
|
|
@ -1149,13 +1149,13 @@ func importRules(url *url.URL, start, end, outputDir string, evalInterval, maxBl
|
|
|
|
|
} else { |
|
|
|
|
etime, err = parseTime(end) |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("error parsing end time: %v", err) |
|
|
|
|
return fmt.Errorf("error parsing end time: %w", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stime, err = parseTime(start) |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("error parsing start time: %v", err) |
|
|
|
|
return fmt.Errorf("error parsing start time: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !stime.Before(etime) { |
|
|
|
@ -1173,14 +1173,14 @@ func importRules(url *url.URL, start, end, outputDir string, evalInterval, maxBl
|
|
|
|
|
Address: url.String(), |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("new api client error: %v", err) |
|
|
|
|
return fmt.Errorf("new api client error: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ruleImporter := newRuleImporter(log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)), cfg, v1.NewAPI(client)) |
|
|
|
|
errs := ruleImporter.loadGroups(ctx, files) |
|
|
|
|
for _, err := range errs { |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("rule importer parse error: %v", err) |
|
|
|
|
return fmt.Errorf("rule importer parse error: %w", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|