2020-02-23 12:35:47 +01:00
|
|
|
package promscrape
|
|
|
|
|
|
|
|
import (
|
2021-11-05 13:41:14 +01:00
|
|
|
"bytes"
|
2020-02-23 12:35:47 +01:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2021-03-01 11:29:09 +01:00
|
|
|
"strconv"
|
2020-02-23 12:35:47 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-04-13 11:59:05 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
2020-02-23 12:35:47 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
2021-03-12 02:35:49 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
|
2020-02-23 12:35:47 +01:00
|
|
|
)
|
|
|
|
|
2021-03-04 09:20:15 +01:00
|
|
|
func TestNeedSkipScrapeWork(t *testing.T) {
|
|
|
|
f := func(key string, membersCount, replicationFactor, memberNum int, needSkipExpected bool) {
|
|
|
|
t.Helper()
|
|
|
|
needSkip := needSkipScrapeWork(key, membersCount, replicationFactor, memberNum)
|
|
|
|
if needSkip != needSkipExpected {
|
2021-03-05 08:05:52 +01:00
|
|
|
t.Fatalf("unexpected needSkipScrapeWork(key=%q, membersCount=%d, replicationFactor=%d, memberNum=%d); got %v; want %v",
|
|
|
|
key, membersCount, replicationFactor, memberNum, needSkip, needSkipExpected)
|
2021-03-04 09:20:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Disabled clustering
|
|
|
|
f("foo", 0, 0, 0, false)
|
|
|
|
|
|
|
|
// A cluster with 2 nodes with disabled replication
|
|
|
|
f("foo", 2, 0, 0, true)
|
|
|
|
f("foo", 2, 0, 1, false)
|
|
|
|
|
|
|
|
// A cluster with 2 nodes with replicationFactor=2
|
|
|
|
f("foo", 2, 2, 0, false)
|
|
|
|
f("foo", 2, 2, 1, false)
|
|
|
|
|
|
|
|
// A cluster with 3 nodes with replicationFactor=2
|
|
|
|
f("foo", 3, 2, 0, false)
|
|
|
|
f("foo", 3, 2, 1, true)
|
|
|
|
f("foo", 3, 2, 2, false)
|
|
|
|
}
|
|
|
|
|
2020-02-23 12:35:47 +01:00
|
|
|
func TestLoadStaticConfigs(t *testing.T) {
|
|
|
|
scs, err := loadStaticConfigs("testdata/file_sd.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
if len(scs) == 0 {
|
|
|
|
t.Fatalf("expecting non-zero static configs")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try loading non-existing file
|
|
|
|
scs, err = loadStaticConfigs("testdata/non-exsiting-file")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
|
|
|
}
|
|
|
|
if scs != nil {
|
|
|
|
t.Fatalf("unexpected non-nil static configs: %#v", scs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try loading invalid file
|
|
|
|
scs, err = loadStaticConfigs("testdata/prometheus.yml")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
|
|
|
}
|
|
|
|
if scs != nil {
|
|
|
|
t.Fatalf("unexpected non-nil static configs: %#v", scs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
2021-11-05 13:41:14 +01:00
|
|
|
cfg, data, err := loadConfig("testdata/prometheus.yml")
|
2021-08-26 07:51:14 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
if cfg == nil {
|
|
|
|
t.Fatalf("expecting non-nil config")
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if data == nil {
|
|
|
|
t.Fatalf("expecting non-nil data")
|
|
|
|
}
|
2021-08-26 07:51:14 +02:00
|
|
|
|
2021-11-05 13:41:14 +01:00
|
|
|
cfg, data, err = loadConfig("testdata/prometheus-with-scrape-config-files.yml")
|
2020-02-23 12:35:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
}
|
2020-05-03 11:41:13 +02:00
|
|
|
if cfg == nil {
|
|
|
|
t.Fatalf("expecting non-nil config")
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if data == nil {
|
|
|
|
t.Fatalf("expecting non-nil data")
|
|
|
|
}
|
2020-02-23 12:35:47 +01:00
|
|
|
|
|
|
|
// Try loading non-existing file
|
2021-11-05 13:41:14 +01:00
|
|
|
cfg, data, err = loadConfig("testdata/non-existing-file")
|
2020-02-23 12:35:47 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
|
|
|
}
|
|
|
|
if cfg != nil {
|
|
|
|
t.Fatalf("unexpected non-nil config: %#v", cfg)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if data != nil {
|
|
|
|
t.Fatalf("unexpected data wit length=%d: %q", len(data), data)
|
|
|
|
}
|
2020-02-23 12:35:47 +01:00
|
|
|
|
|
|
|
// Try loading invalid file
|
2021-11-05 13:41:14 +01:00
|
|
|
cfg, data, err = loadConfig("testdata/file_sd_1.yml")
|
2020-02-23 12:35:47 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
|
|
|
}
|
|
|
|
if cfg != nil {
|
|
|
|
t.Fatalf("unexpected non-nil config: %#v", cfg)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if data != nil {
|
|
|
|
t.Fatalf("unexpected data wit length=%d: %q", len(data), data)
|
|
|
|
}
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
|
2020-08-09 11:02:32 +02:00
|
|
|
func TestBlackboxExporter(t *testing.T) {
|
|
|
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/684
|
|
|
|
data := `
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: 'blackbox'
|
|
|
|
metrics_path: /probe
|
|
|
|
params:
|
|
|
|
module: [dns_udp_example] # Look for dns response
|
|
|
|
static_configs:
|
|
|
|
- targets:
|
|
|
|
- 8.8.8.8
|
|
|
|
relabel_configs:
|
|
|
|
- source_labels: [__address__]
|
|
|
|
target_label: __param_target
|
|
|
|
- source_labels: [__param_target]
|
|
|
|
target_label: instance
|
|
|
|
- target_label: __address__
|
|
|
|
replacement: black:9115 # The blackbox exporter's real hostname:port.%
|
|
|
|
`
|
|
|
|
var cfg Config
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err := cfg.parseData([]byte(data), "sss")
|
|
|
|
if err != nil {
|
2020-08-09 11:02:32 +02:00
|
|
|
t.Fatalf("cannot parase data: %s", err)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if string(allData) != data {
|
|
|
|
t.Fatalf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, data)
|
|
|
|
}
|
2020-08-09 11:02:32 +02:00
|
|
|
sws := cfg.getStaticScrapeWork()
|
2020-10-08 18:32:28 +02:00
|
|
|
resetNonEssentialFields(sws)
|
2020-12-08 16:50:03 +01:00
|
|
|
swsExpected := []*ScrapeWork{{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://black:9115/probe?module=dns_udp_example&target=8.8.8.8",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-08-09 11:02:32 +02:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "black:9115",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/probe",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_module",
|
|
|
|
Value: "dns_udp_example",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_target",
|
|
|
|
Value: "8.8.8.8",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-08-09 11:02:32 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "8.8.8.8",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "blackbox",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-08-09 11:02:32 +02:00
|
|
|
jobNameOriginal: "blackbox",
|
|
|
|
}}
|
|
|
|
if !reflect.DeepEqual(sws, swsExpected) {
|
|
|
|
t.Fatalf("unexpected scrapeWork;\ngot\n%+v\nwant\n%+v", sws, swsExpected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 12:35:47 +01:00
|
|
|
func TestGetFileSDScrapeWork(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
file_sd_configs:
|
|
|
|
- files: [testdata/file_sd.json]
|
|
|
|
`
|
|
|
|
var cfg Config
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err := cfg.parseData([]byte(data), "sss")
|
|
|
|
if err != nil {
|
2020-02-23 12:35:47 +01:00
|
|
|
t.Fatalf("cannot parase data: %s", err)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if string(allData) != data {
|
|
|
|
t.Fatalf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, data)
|
|
|
|
}
|
2020-04-13 11:59:05 +02:00
|
|
|
sws := cfg.getFileSDScrapeWork(nil)
|
2020-02-23 12:35:47 +01:00
|
|
|
if !equalStaticConfigForScrapeWorks(sws, sws) {
|
|
|
|
t.Fatalf("unexpected non-equal static configs;\nsws:\n%#v", sws)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load another static config
|
|
|
|
dataNew := `
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
file_sd_configs:
|
|
|
|
- files: [testdata/file_sd_1.yml]
|
|
|
|
`
|
|
|
|
var cfgNew Config
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err = cfgNew.parseData([]byte(dataNew), "sss")
|
|
|
|
if err != nil {
|
2020-02-23 12:35:47 +01:00
|
|
|
t.Fatalf("cannot parse data: %s", err)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if string(allData) != dataNew {
|
|
|
|
t.Fatalf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, dataNew)
|
|
|
|
}
|
2020-04-13 11:59:05 +02:00
|
|
|
swsNew := cfgNew.getFileSDScrapeWork(sws)
|
2020-02-23 12:35:47 +01:00
|
|
|
if equalStaticConfigForScrapeWorks(swsNew, sws) {
|
|
|
|
t.Fatalf("unexpected equal static configs;\nswsNew:\n%#v\nsws:\n%#v", swsNew, sws)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try loading invalid static config
|
|
|
|
data = `
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
file_sd_configs:
|
|
|
|
- files: [testdata/prometheus.yml]
|
|
|
|
`
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err = cfg.parseData([]byte(data), "sss")
|
|
|
|
if err != nil {
|
2020-02-23 12:35:47 +01:00
|
|
|
t.Fatalf("cannot parse data: %s", err)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if string(allData) != data {
|
|
|
|
t.Fatalf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, data)
|
|
|
|
}
|
2020-04-13 11:59:05 +02:00
|
|
|
sws = cfg.getFileSDScrapeWork(swsNew)
|
2020-02-23 12:35:47 +01:00
|
|
|
if len(sws) != 0 {
|
|
|
|
t.Fatalf("unexpected non-empty sws:\n%#v", sws)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty target in static config
|
|
|
|
data = `
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
file_sd_configs:
|
|
|
|
- files: [testdata/empty_target_file_sd.yml]
|
|
|
|
`
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err = cfg.parseData([]byte(data), "sss")
|
|
|
|
if err != nil {
|
2020-02-23 12:35:47 +01:00
|
|
|
t.Fatalf("cannot parse data: %s", err)
|
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if string(allData) != data {
|
|
|
|
t.Fatalf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, data)
|
|
|
|
}
|
2020-04-13 11:59:05 +02:00
|
|
|
sws = cfg.getFileSDScrapeWork(swsNew)
|
2020-02-23 12:35:47 +01:00
|
|
|
if len(sws) != 0 {
|
|
|
|
t.Fatalf("unexpected non-empty sws:\n%#v", sws)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 16:50:03 +01:00
|
|
|
func getFileSDScrapeWork(data []byte, path string) ([]*ScrapeWork, error) {
|
2020-02-23 12:35:47 +01:00
|
|
|
var cfg Config
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err := cfg.parseData(data, path)
|
|
|
|
if err != nil {
|
2020-06-30 21:58:18 +02:00
|
|
|
return nil, fmt.Errorf("cannot parse data: %w", err)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if !bytes.Equal(allData, data) {
|
|
|
|
return nil, fmt.Errorf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, data)
|
|
|
|
}
|
2020-04-13 11:59:05 +02:00
|
|
|
return cfg.getFileSDScrapeWork(nil), nil
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 16:50:03 +01:00
|
|
|
func getStaticScrapeWork(data []byte, path string) ([]*ScrapeWork, error) {
|
2020-02-23 12:35:47 +01:00
|
|
|
var cfg Config
|
2021-11-05 13:41:14 +01:00
|
|
|
allData, err := cfg.parseData(data, path)
|
|
|
|
if err != nil {
|
2020-06-30 21:58:18 +02:00
|
|
|
return nil, fmt.Errorf("cannot parse data: %w", err)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
2021-11-05 13:41:14 +01:00
|
|
|
if !bytes.Equal(allData, data) {
|
|
|
|
return nil, fmt.Errorf("invalid data returned from parseData;\ngot\n%s\nwant\n%s", allData, data)
|
|
|
|
}
|
2020-04-13 11:59:05 +02:00
|
|
|
return cfg.getStaticScrapeWork(), nil
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetStaticScrapeWorkFailure(t *testing.T) {
|
|
|
|
f := func(data string) {
|
|
|
|
t.Helper()
|
|
|
|
sws, err := getStaticScrapeWork([]byte(data), "non-existing-file")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
|
|
|
}
|
|
|
|
if sws != nil {
|
|
|
|
t.Fatalf("expecting nil sws")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// incorrect yaml
|
|
|
|
f(`foo bar baz`)
|
|
|
|
|
|
|
|
// Missing job_name
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- static_configs:
|
|
|
|
- targets: ["foo"]
|
|
|
|
`)
|
|
|
|
|
2021-08-26 07:51:14 +02:00
|
|
|
// Duplicate job_name
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
targets: ["foo"]
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
targets: ["bar"]
|
|
|
|
`)
|
|
|
|
|
2020-02-23 12:35:47 +01:00
|
|
|
// Invalid scheme
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
scheme: asdf
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing username in `basic_auth`
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
basic_auth:
|
|
|
|
password: sss
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Both password and password_file set in `basic_auth`
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
basic_auth:
|
|
|
|
username: foobar
|
|
|
|
password: sss
|
|
|
|
password_file: sdfdf
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Invalid password_file set in `basic_auth`
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
basic_auth:
|
|
|
|
username: foobar
|
2021-05-14 19:00:05 +02:00
|
|
|
password_file: ['foobar']
|
2020-02-23 12:35:47 +01:00
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Both `bearer_token` and `bearer_token_file` are set
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
bearer_token: foo
|
|
|
|
bearer_token_file: bar
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Both `basic_auth` and `bearer_token` are set
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
bearer_token: foo
|
|
|
|
basic_auth:
|
|
|
|
username: foo
|
|
|
|
password: bar
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
2021-04-03 21:13:22 +02:00
|
|
|
// Both `authorization` and `basic_auth` are set
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
authorization:
|
|
|
|
credentials: foobar
|
|
|
|
basic_auth:
|
|
|
|
username: foobar
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Both `authorization` and `bearer_token` are set
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
|
|
|
authorization:
|
|
|
|
credentials: foobar
|
|
|
|
bearer_token: foo
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
2020-02-23 12:35:47 +01:00
|
|
|
// Invalid `bearer_token_file`
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: x
|
2021-05-14 19:00:05 +02:00
|
|
|
bearer_token_file: [foobar]
|
2020-02-23 12:35:47 +01:00
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// non-existing ca_file
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
tls_config:
|
|
|
|
ca_file: non/extising/file
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// invalid ca_file
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
tls_config:
|
|
|
|
ca_file: testdata/prometheus.yml
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// non-existing cert_file
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
tls_config:
|
|
|
|
cert_file: non/extising/file
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// non-existing key_file
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
tls_config:
|
|
|
|
key_file: non/extising/file
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Invalid regex in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- regex: "("
|
|
|
|
source_labels: [foo]
|
|
|
|
target_label: bar
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing target_label for action=replace in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: replace
|
|
|
|
source_labels: [foo]
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing source_labels for action=keep in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: keep
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing source_labels for action=drop in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: drop
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing source_labels for action=hashmod in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: hashmod
|
|
|
|
target_label: bar
|
|
|
|
modulus: 123
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing target for action=hashmod in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: hashmod
|
|
|
|
source_labels: [foo]
|
|
|
|
modulus: 123
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Missing modulus for action=hashmod in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: hashmod
|
|
|
|
source_labels: [foo]
|
|
|
|
target_label: bar
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Invalid action in relabel_configs
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aa
|
|
|
|
relabel_configs:
|
|
|
|
- action: foobar
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
2021-08-26 07:51:14 +02:00
|
|
|
|
|
|
|
// Invalid scrape_config_files contents
|
|
|
|
f(`
|
|
|
|
scrape_config_files:
|
|
|
|
- job_name: aa
|
|
|
|
static_configs:
|
|
|
|
- targets: ["s"]
|
|
|
|
`)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 16:50:03 +01:00
|
|
|
func resetNonEssentialFields(sws []*ScrapeWork) {
|
2020-04-14 12:31:23 +02:00
|
|
|
for i := range sws {
|
2020-10-08 18:32:28 +02:00
|
|
|
sws[i].OriginalLabels = nil
|
2020-04-14 12:31:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-01 11:29:09 +01:00
|
|
|
// String returns human-readable representation for sw.
|
|
|
|
func (sw *ScrapeWork) String() string {
|
|
|
|
return strconv.Quote(sw.key())
|
|
|
|
}
|
|
|
|
|
2020-02-23 12:35:47 +01:00
|
|
|
func TestGetFileSDScrapeWorkSuccess(t *testing.T) {
|
2020-12-08 16:50:03 +01:00
|
|
|
f := func(data string, expectedSws []*ScrapeWork) {
|
2020-02-23 12:35:47 +01:00
|
|
|
t.Helper()
|
|
|
|
sws, err := getFileSDScrapeWork([]byte(data), "non-existing-file")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
}
|
2020-10-08 18:32:28 +02:00
|
|
|
resetNonEssentialFields(sws)
|
2020-05-03 13:28:16 +02:00
|
|
|
|
|
|
|
// Remove `__vm_filepath` label, since its value depends on the current working dir.
|
2020-12-08 16:50:03 +01:00
|
|
|
for _, sw := range sws {
|
2020-05-03 13:28:16 +02:00
|
|
|
for j := range sw.Labels {
|
|
|
|
label := &sw.Labels[j]
|
|
|
|
if label.Name == "__vm_filepath" {
|
|
|
|
label.Value = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 12:35:47 +01:00
|
|
|
if !reflect.DeepEqual(sws, expectedSws) {
|
2021-03-01 11:29:09 +01:00
|
|
|
t.Fatalf("unexpected scrapeWork; got\n%+v\nwant\n%+v", sws, expectedSws)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
- targets: ["xxx"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{})
|
2020-02-23 12:35:47 +01:00
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
metrics_path: /abc/de
|
|
|
|
file_sd_configs:
|
|
|
|
- files: ["testdata/file_sd.json", "testdata/file_sd*.yml"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
ScrapeURL: "http://host1:80/abc/de",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "host1",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/abc/de",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-04-14 11:21:10 +02:00
|
|
|
{
|
|
|
|
Name: "__vm_filepath",
|
2020-05-03 13:28:16 +02:00
|
|
|
Value: "",
|
2020-04-14 11:21:10 +02:00
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "host1:80",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "qwe",
|
|
|
|
Value: "rty",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ScrapeURL: "http://host2:80/abc/de",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "host2",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/abc/de",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-04-14 11:21:10 +02:00
|
|
|
{
|
|
|
|
Name: "__vm_filepath",
|
2020-05-03 13:28:16 +02:00
|
|
|
Value: "",
|
2020-04-14 11:21:10 +02:00
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "host2:80",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "qwe",
|
|
|
|
Value: "rty",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ScrapeURL: "http://localhost:9090/abc/de",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "localhost:9090",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/abc/de",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-04-14 11:21:10 +02:00
|
|
|
{
|
|
|
|
Name: "__vm_filepath",
|
2020-05-03 13:28:16 +02:00
|
|
|
Value: "",
|
2020-04-14 11:21:10 +02:00
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "localhost:9090",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "yml",
|
|
|
|
Value: "test",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetStaticScrapeWorkSuccess(t *testing.T) {
|
2020-12-08 16:50:03 +01:00
|
|
|
f := func(data string, expectedSws []*ScrapeWork) {
|
2020-02-23 12:35:47 +01:00
|
|
|
t.Helper()
|
|
|
|
sws, err := getStaticScrapeWork([]byte(data), "non-exsiting-file")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
}
|
2020-10-08 18:32:28 +02:00
|
|
|
resetNonEssentialFields(sws)
|
2020-02-23 12:35:47 +01:00
|
|
|
if !reflect.DeepEqual(sws, expectedSws) {
|
2021-03-01 11:29:09 +01:00
|
|
|
t.Fatalf("unexpected scrapeWork; got\n%+v\nwant\n%+v", sws, expectedSws)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
f(``, nil)
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
|
|
|
global:
|
|
|
|
external_labels:
|
|
|
|
datacenter: foobar
|
|
|
|
jobs: xxx
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "datacenter",
|
|
|
|
Value: "foobar",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "jobs",
|
|
|
|
Value: "xxx",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
|
|
|
global:
|
|
|
|
scrape_interval: 8s
|
|
|
|
scrape_timeout: 34s
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
2021-09-12 12:33:39 +02:00
|
|
|
scrape_interval: 54s
|
2020-02-23 12:35:47 +01:00
|
|
|
scrape_timeout: 12s
|
|
|
|
metrics_path: /foo/bar
|
|
|
|
scheme: https
|
|
|
|
honor_labels: true
|
2021-10-16 19:48:15 +02:00
|
|
|
honor_timestamps: false
|
2021-04-02 18:56:38 +02:00
|
|
|
follow_redirects: false
|
2020-02-23 12:35:47 +01:00
|
|
|
params:
|
|
|
|
p: ["x&y", "="]
|
|
|
|
xaa:
|
2021-03-12 02:35:49 +01:00
|
|
|
proxy_url: http://foo.bar
|
2020-02-23 12:35:47 +01:00
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar", "aaa"]
|
|
|
|
labels:
|
|
|
|
x: y
|
2021-09-12 12:33:39 +02:00
|
|
|
__scrape_timeout__: "5s"
|
2020-02-23 12:35:47 +01:00
|
|
|
- job_name: qwer
|
|
|
|
tls_config:
|
|
|
|
server_name: foobar
|
|
|
|
insecure_skip_verify: true
|
|
|
|
static_configs:
|
|
|
|
- targets: [1.2.3.4]
|
2021-04-03 21:13:22 +02:00
|
|
|
- job_name: asdf
|
|
|
|
static_configs:
|
|
|
|
- targets: [foobar]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
ScrapeURL: "https://foo.bar:443/foo/bar?p=x%26y&p=%3D",
|
2021-09-12 12:33:39 +02:00
|
|
|
ScrapeInterval: 54 * time.Second,
|
|
|
|
ScrapeTimeout: 5 * time.Second,
|
2020-02-23 12:35:47 +01:00
|
|
|
HonorLabels: true,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: false,
|
2021-04-02 18:56:38 +02:00
|
|
|
DenyRedirects: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "foo.bar",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/foo/bar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_p",
|
|
|
|
Value: "x&y",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "https",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "54s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "5s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:443",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "x",
|
|
|
|
Value: "y",
|
|
|
|
},
|
|
|
|
},
|
2021-05-14 19:00:05 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyURL: proxy.MustNewURL("http://foo.bar"),
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ScrapeURL: "https://aaa:443/foo/bar?p=x%26y&p=%3D",
|
2021-09-12 12:33:39 +02:00
|
|
|
ScrapeInterval: 54 * time.Second,
|
|
|
|
ScrapeTimeout: 5 * time.Second,
|
2020-02-23 12:35:47 +01:00
|
|
|
HonorLabels: true,
|
2021-10-16 19:48:15 +02:00
|
|
|
HonorTimestamps: false,
|
2021-04-02 18:56:38 +02:00
|
|
|
DenyRedirects: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "aaa",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/foo/bar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_p",
|
|
|
|
Value: "x&y",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "https",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "54s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "5s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "aaa:443",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "x",
|
|
|
|
Value: "y",
|
|
|
|
},
|
|
|
|
},
|
2021-05-14 19:00:05 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyURL: proxy.MustNewURL("http://foo.bar"),
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://1.2.3.4:80/metrics",
|
|
|
|
ScrapeInterval: 8 * time.Second,
|
|
|
|
ScrapeTimeout: 8 * time.Second,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "1.2.3.4",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "8s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "8s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "1.2.3.4:80",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "qwer",
|
|
|
|
},
|
|
|
|
},
|
2020-04-13 11:59:05 +02:00
|
|
|
AuthConfig: &promauth.Config{
|
|
|
|
TLSServerName: "foobar",
|
|
|
|
TLSInsecureSkipVerify: true,
|
|
|
|
},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "qwer",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
2021-04-03 21:13:22 +02:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foobar:80/metrics",
|
|
|
|
ScrapeInterval: 8 * time.Second,
|
|
|
|
ScrapeTimeout: 8 * time.Second,
|
|
|
|
HonorTimestamps: true,
|
2021-04-03 21:13:22 +02:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foobar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "8s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "8s",
|
|
|
|
},
|
2021-04-03 21:13:22 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foobar:80",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "asdf",
|
|
|
|
},
|
|
|
|
},
|
2021-05-14 19:00:05 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-04-03 21:13:22 +02:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
|
|
|
jobNameOriginal: "asdf",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
})
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
relabel_configs:
|
|
|
|
- source_labels: [__scheme__, __address__]
|
|
|
|
separator: "://"
|
|
|
|
target_label: __tmp_url
|
|
|
|
- source_labels: [__tmp_url, __metrics_path__]
|
|
|
|
separator: ""
|
|
|
|
target_label: url
|
|
|
|
- action: labeldrop
|
|
|
|
regex: "job|__tmp_.+"
|
|
|
|
- action: drop
|
|
|
|
source_labels: [__address__]
|
|
|
|
regex: "drop-.*"
|
|
|
|
- action: keep
|
|
|
|
source_labels: [__param_x]
|
|
|
|
regex: keep_me
|
|
|
|
- action: labelkeep
|
|
|
|
regex: "__.*|url"
|
|
|
|
- action: labelmap
|
|
|
|
regex: "(url)"
|
|
|
|
replacement: "prefix:${1}"
|
|
|
|
- action: hashmod
|
|
|
|
modulus: 123
|
|
|
|
source_labels: [__address__]
|
|
|
|
target_label: hash
|
|
|
|
- action: replace
|
|
|
|
source_labels: [__address__]
|
|
|
|
target_label: foobar
|
|
|
|
replacement: ""
|
|
|
|
params:
|
|
|
|
x: [keep_me]
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234", "drop-this-target"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics?x=keep_me",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_x",
|
|
|
|
Value: "keep_me",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "hash",
|
|
|
|
Value: "82",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "prefix:url",
|
|
|
|
Value: "http://foo.bar:1234/metrics",
|
|
|
|
},
|
2020-10-05 15:19:14 +02:00
|
|
|
{
|
|
|
|
Name: "url",
|
|
|
|
Value: "http://foo.bar:1234/metrics",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
scheme: https
|
|
|
|
relabel_configs:
|
|
|
|
- action: replace
|
|
|
|
source_labels: [non-existing-label]
|
|
|
|
target_label: instance
|
|
|
|
replacement: fake.addr
|
|
|
|
- action: replace
|
|
|
|
source_labels: [__address__]
|
|
|
|
target_label: foobar
|
|
|
|
regex: "missing-regex"
|
|
|
|
replacement: aaabbb
|
|
|
|
- action: replace
|
|
|
|
source_labels: [__scheme__]
|
|
|
|
target_label: job
|
|
|
|
- action: replace
|
|
|
|
source_labels: [__scheme__]
|
|
|
|
target_label: __scheme__
|
|
|
|
replacement: mailto
|
|
|
|
- target_label: __metrics_path__
|
|
|
|
replacement: /abc.de
|
|
|
|
- target_label: __param_a
|
|
|
|
replacement: b
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "mailto://foo.bar:1234/abc.de?a=b",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/abc.de",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_a",
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "mailto",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "fake.addr",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "https",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
scheme: https
|
|
|
|
relabel_configs:
|
|
|
|
- action: keep
|
|
|
|
source_labels: [__address__]
|
|
|
|
regex: "foo\\.bar:.*"
|
|
|
|
- action: hashmod
|
|
|
|
source_labels: [job]
|
|
|
|
modulus: 4
|
|
|
|
target_label: job
|
|
|
|
- action: labeldrop
|
|
|
|
regex: "non-matching-regex"
|
|
|
|
- action: labelkeep
|
|
|
|
regex: "job|__address__"
|
|
|
|
- action: labeldrop
|
|
|
|
regex: ""
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234", "xyz"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "3",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
2020-06-19 01:20:29 +02:00
|
|
|
|
2020-02-23 12:35:47 +01:00
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
metric_relabel_configs:
|
|
|
|
- source_labels: [foo]
|
|
|
|
target_label: abc
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
2021-03-12 02:35:49 +01:00
|
|
|
AuthConfig: &promauth.Config{},
|
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2021-02-22 15:33:55 +01:00
|
|
|
MetricRelabelConfigs: mustParseRelabelConfigs(`
|
|
|
|
- source_labels: [foo]
|
|
|
|
target_label: abc
|
|
|
|
`),
|
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
2021-05-14 19:00:05 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: foo
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foo.bar:1234/metrics",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-23 12:35:47 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
2020-02-23 12:35:47 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
2021-05-14 19:00:05 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "foo",
|
2020-02-23 12:35:47 +01:00
|
|
|
},
|
|
|
|
})
|
2020-02-25 19:49:04 +01:00
|
|
|
f(`
|
2020-03-12 19:17:13 +01:00
|
|
|
global:
|
|
|
|
external_labels:
|
|
|
|
job: foobar
|
|
|
|
foo: xx
|
|
|
|
q: qwe
|
|
|
|
__address__: aaasdf
|
|
|
|
__param_a: jlfd
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: aaa
|
|
|
|
params:
|
|
|
|
a: [b, xy]
|
|
|
|
static_configs:
|
|
|
|
- targets: ["a"]
|
|
|
|
labels:
|
|
|
|
foo: bar
|
|
|
|
__param_a: c
|
|
|
|
__address__: pp
|
|
|
|
job: yyy
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-03-12 19:17:13 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://pp:80/metrics?a=c&a=xy",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-03-12 19:17:13 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "pp",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__param_a",
|
|
|
|
Value: "c",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-03-12 19:17:13 +01:00
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2020-05-03 15:41:33 +02:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "pp:80",
|
|
|
|
},
|
2020-03-12 19:17:13 +01:00
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "yyy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "q",
|
|
|
|
Value: "qwe",
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 14:35:19 +02:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-06-23 14:35:19 +02:00
|
|
|
jobNameOriginal: "aaa",
|
2020-03-12 19:17:13 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
f(`
|
2020-02-25 19:49:04 +01:00
|
|
|
scrape_configs:
|
|
|
|
- job_name: 'snmp'
|
2020-07-02 13:19:11 +02:00
|
|
|
sample_limit: 100
|
|
|
|
disable_keepalive: true
|
|
|
|
disable_compression: true
|
2021-02-18 22:51:29 +01:00
|
|
|
scrape_align_interval: 1s
|
2021-03-08 10:58:25 +01:00
|
|
|
scrape_offset: 0.5s
|
2020-02-25 19:49:04 +01:00
|
|
|
static_configs:
|
|
|
|
- targets:
|
|
|
|
- 192.168.1.2 # SNMP device.
|
|
|
|
metrics_path: /snmp
|
|
|
|
params:
|
|
|
|
module: [if_mib]
|
|
|
|
relabel_configs:
|
|
|
|
- source_labels: [__address__]
|
|
|
|
target_label: __param_target
|
|
|
|
- source_labels: [__param_target]
|
|
|
|
target_label: instance
|
|
|
|
- target_label: __address__
|
|
|
|
replacement: 127.0.0.1:9116 # The SNMP exporter's real hostname:port.
|
2021-09-09 17:49:37 +02:00
|
|
|
- target_label: __series_limit__
|
|
|
|
replacement: 1234
|
|
|
|
- target_label: __stream_parse__
|
|
|
|
replacement: true
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-02-25 19:49:04 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://127.0.0.1:9116/snmp?module=if_mib&target=192.168.1.2",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-02-25 19:49:04 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "127.0.0.1:9116",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "/snmp",
|
|
|
|
},
|
|
|
|
{
|
2020-02-25 19:56:13 +01:00
|
|
|
Name: "__param_module",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "if_mib",
|
|
|
|
},
|
|
|
|
{
|
2020-02-25 19:56:13 +01:00
|
|
|
Name: "__param_target",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "192.168.1.2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2021-09-09 17:49:37 +02:00
|
|
|
{
|
|
|
|
Name: "__series_limit__",
|
|
|
|
Value: "1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__stream_parse__",
|
|
|
|
Value: "true",
|
|
|
|
},
|
2020-02-25 19:49:04 +01:00
|
|
|
{
|
2020-02-25 19:56:13 +01:00
|
|
|
Name: "instance",
|
2020-02-25 19:49:04 +01:00
|
|
|
Value: "192.168.1.2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "snmp",
|
|
|
|
},
|
|
|
|
},
|
2021-02-18 22:51:29 +01:00
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2021-02-18 22:51:29 +01:00
|
|
|
SampleLimit: 100,
|
|
|
|
DisableKeepAlive: true,
|
|
|
|
DisableCompression: true,
|
|
|
|
StreamParse: true,
|
|
|
|
ScrapeAlignInterval: time.Second,
|
2021-03-08 10:58:25 +01:00
|
|
|
ScrapeOffset: 500 * time.Millisecond,
|
2021-09-09 17:49:37 +02:00
|
|
|
SeriesLimit: 1234,
|
2021-02-18 22:51:29 +01:00
|
|
|
jobNameOriginal: "snmp",
|
2020-02-25 19:49:04 +01:00
|
|
|
},
|
|
|
|
})
|
2020-10-29 06:39:42 +01:00
|
|
|
f(`
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: path wo slash
|
|
|
|
static_configs:
|
|
|
|
- targets: ["foo.bar:1234"]
|
|
|
|
relabel_configs:
|
|
|
|
- replacement: metricspath
|
|
|
|
target_label: __metrics_path__
|
2020-12-08 16:50:03 +01:00
|
|
|
`, []*ScrapeWork{
|
2020-10-29 06:39:42 +01:00
|
|
|
{
|
2021-10-16 19:48:15 +02:00
|
|
|
ScrapeURL: "http://foo.bar:1234/metricspath",
|
|
|
|
ScrapeInterval: defaultScrapeInterval,
|
|
|
|
ScrapeTimeout: defaultScrapeTimeout,
|
|
|
|
HonorTimestamps: true,
|
2020-10-29 06:39:42 +01:00
|
|
|
Labels: []prompbmarshal.Label{
|
|
|
|
{
|
|
|
|
Name: "__address__",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__metrics_path__",
|
|
|
|
Value: "metricspath",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "__scheme__",
|
|
|
|
Value: "http",
|
|
|
|
},
|
2021-09-12 12:33:39 +02:00
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_interval__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "1m0s",
|
|
|
|
},
|
|
|
|
{
|
2021-09-12 12:34:15 +02:00
|
|
|
Name: "__scrape_timeout__",
|
2021-09-12 12:33:39 +02:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-10-29 06:39:42 +01:00
|
|
|
{
|
|
|
|
Name: "instance",
|
|
|
|
Value: "foo.bar:1234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "job",
|
|
|
|
Value: "path wo slash",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
jobNameOriginal: "path wo slash",
|
|
|
|
AuthConfig: &promauth.Config{},
|
2021-03-12 02:35:49 +01:00
|
|
|
ProxyAuthConfig: &promauth.Config{},
|
2020-10-29 06:39:42 +01:00
|
|
|
},
|
|
|
|
})
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 16:50:03 +01:00
|
|
|
func equalStaticConfigForScrapeWorks(a, b []*ScrapeWork) bool {
|
2020-05-03 11:41:13 +02:00
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i := range a {
|
|
|
|
keyA := a[i].key()
|
|
|
|
keyB := b[i].key()
|
|
|
|
if keyA != keyB {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|