2015-08-20 11:03:56 +00:00
|
|
|
// Copyright 2015 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2013-02-14 00:04:07 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2015-06-06 07:55:22 +00:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2015-09-03 09:47:09 +00:00
|
|
|
"net/url"
|
2015-05-07 08:55:03 +00:00
|
|
|
"reflect"
|
2017-05-29 11:46:23 +00:00
|
|
|
"regexp"
|
2013-02-14 00:04:07 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2015-05-07 08:55:03 +00:00
|
|
|
"time"
|
|
|
|
|
2015-08-20 15:18:46 +00:00
|
|
|
"github.com/prometheus/common/model"
|
2015-08-22 07:42:45 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2013-02-14 00:04:07 +00:00
|
|
|
)
|
|
|
|
|
2017-02-13 20:43:20 +00:00
|
|
|
func mustParseURL(u string) *URL {
|
|
|
|
parsed, err := url.Parse(u)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return &URL{URL: parsed}
|
|
|
|
}
|
|
|
|
|
2015-06-04 15:03:12 +00:00
|
|
|
var expectedConf = &Config{
|
2015-06-07 15:40:22 +00:00
|
|
|
GlobalConfig: GlobalConfig{
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2015-05-07 08:55:03 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
2016-01-29 14:23:11 +00:00
|
|
|
EvaluationInterval: model.Duration(30 * time.Second),
|
2015-05-07 08:55:03 +00:00
|
|
|
|
2015-09-29 15:51:03 +00:00
|
|
|
ExternalLabels: model.LabelSet{
|
2015-05-07 08:55:03 +00:00
|
|
|
"monitor": "codelab",
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
|
|
|
|
RuleFiles: []string{
|
2015-08-05 16:04:34 +00:00
|
|
|
"testdata/first.rules",
|
|
|
|
"/absolute/second.rules",
|
|
|
|
"testdata/my/*.rules",
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
|
|
|
|
2017-02-13 20:43:20 +00:00
|
|
|
RemoteWriteConfigs: []*RemoteWriteConfig{
|
|
|
|
{
|
|
|
|
URL: mustParseURL("http://remote1/push"),
|
|
|
|
RemoteTimeout: model.Duration(30 * time.Second),
|
|
|
|
WriteRelabelConfigs: []*RelabelConfig{
|
|
|
|
{
|
|
|
|
SourceLabels: model.LabelNames{"__name__"},
|
|
|
|
Separator: ";",
|
|
|
|
Regex: MustNewRegexp("expensive.*"),
|
|
|
|
Replacement: "$1",
|
|
|
|
Action: RelabelDrop,
|
|
|
|
},
|
2016-10-01 15:42:43 +00:00
|
|
|
},
|
|
|
|
},
|
2017-02-13 20:43:20 +00:00
|
|
|
{
|
|
|
|
URL: mustParseURL("http://remote2/push"),
|
|
|
|
RemoteTimeout: model.Duration(30 * time.Second),
|
|
|
|
},
|
2016-10-01 15:42:43 +00:00
|
|
|
},
|
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
ScrapeConfigs: []*ScrapeConfig{
|
2015-06-04 15:03:12 +00:00
|
|
|
{
|
2015-05-07 08:55:03 +00:00
|
|
|
JobName: "prometheus",
|
|
|
|
|
2015-06-22 20:35:19 +00:00
|
|
|
HonorLabels: true,
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2015-05-07 08:55:03 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
HTTPClientConfig: HTTPClientConfig{
|
|
|
|
BearerTokenFile: "testdata/valid_token_file",
|
|
|
|
},
|
2015-08-05 16:04:34 +00:00
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
StaticConfigs: []*TargetGroup{
|
|
|
|
{
|
|
|
|
Targets: []model.LabelSet{
|
|
|
|
{model.AddressLabel: "localhost:9090"},
|
|
|
|
{model.AddressLabel: "localhost:9191"},
|
|
|
|
},
|
|
|
|
Labels: model.LabelSet{
|
|
|
|
"my": "label",
|
|
|
|
"your": "label",
|
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
FileSDConfigs: []*FileSDConfig{
|
|
|
|
{
|
|
|
|
Files: []string{"foo/*.slow.json", "foo/*.slow.yml", "single/file.yml"},
|
|
|
|
RefreshInterval: model.Duration(10 * time.Minute),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Files: []string{"bar/*.yaml"},
|
|
|
|
RefreshInterval: model.Duration(5 * time.Minute),
|
|
|
|
},
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
2015-05-13 09:28:04 +00:00
|
|
|
},
|
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
RelabelConfigs: []*RelabelConfig{
|
2015-06-04 15:03:12 +00:00
|
|
|
{
|
2016-02-14 21:20:39 +00:00
|
|
|
SourceLabels: model.LabelNames{"job", "__meta_dns_name"},
|
2015-05-07 08:55:03 +00:00
|
|
|
TargetLabel: "job",
|
|
|
|
Separator: ";",
|
2015-09-01 13:05:14 +00:00
|
|
|
Regex: MustNewRegexp("(.*)some-[regex]"),
|
2015-05-07 08:55:03 +00:00
|
|
|
Replacement: "foo-${1}",
|
|
|
|
Action: RelabelReplace,
|
2015-11-16 12:16:13 +00:00
|
|
|
}, {
|
|
|
|
SourceLabels: model.LabelNames{"abc"},
|
|
|
|
TargetLabel: "cde",
|
|
|
|
Separator: ";",
|
|
|
|
Regex: DefaultRelabelConfig.Regex,
|
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
|
|
|
Action: RelabelReplace,
|
|
|
|
}, {
|
|
|
|
TargetLabel: "abc",
|
|
|
|
Separator: ";",
|
|
|
|
Regex: DefaultRelabelConfig.Regex,
|
|
|
|
Replacement: "static",
|
|
|
|
Action: RelabelReplace,
|
2016-11-03 13:34:15 +00:00
|
|
|
}, {
|
|
|
|
TargetLabel: "abc",
|
|
|
|
Separator: ";",
|
|
|
|
Regex: MustNewRegexp(""),
|
|
|
|
Replacement: "static",
|
|
|
|
Action: RelabelReplace,
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-29 11:46:23 +00:00
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
JobName: "service-x",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(50 * time.Second),
|
|
|
|
ScrapeTimeout: model.Duration(5 * time.Second),
|
2016-12-16 15:08:50 +00:00
|
|
|
SampleLimit: 1000,
|
2015-05-07 08:55:03 +00:00
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
HTTPClientConfig: HTTPClientConfig{
|
|
|
|
BasicAuth: &BasicAuth{
|
|
|
|
Username: "admin_name",
|
2017-05-29 11:46:23 +00:00
|
|
|
Password: "multiline\nmysecret\ntest",
|
2016-11-23 11:41:19 +00:00
|
|
|
},
|
2015-05-15 10:47:50 +00:00
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
MetricsPath: "/my_path",
|
2015-05-15 10:47:50 +00:00
|
|
|
Scheme: "https",
|
2015-05-07 08:55:03 +00:00
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
DNSSDConfigs: []*DNSSDConfig{
|
|
|
|
{
|
|
|
|
Names: []string{
|
|
|
|
"first.dns.address.domain.com",
|
|
|
|
"second.dns.address.domain.com",
|
|
|
|
},
|
|
|
|
RefreshInterval: model.Duration(15 * time.Second),
|
|
|
|
Type: "SRV",
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
2016-11-23 11:41:19 +00:00
|
|
|
{
|
|
|
|
Names: []string{
|
|
|
|
"first.dns.address.domain.com",
|
|
|
|
},
|
|
|
|
RefreshInterval: model.Duration(30 * time.Second),
|
|
|
|
Type: "SRV",
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
RelabelConfigs: []*RelabelConfig{
|
2015-06-04 15:03:12 +00:00
|
|
|
{
|
2015-08-20 15:18:46 +00:00
|
|
|
SourceLabels: model.LabelNames{"job"},
|
2015-09-01 13:05:14 +00:00
|
|
|
Regex: MustNewRegexp("(.*)some-[regex]"),
|
2015-05-07 08:55:03 +00:00
|
|
|
Separator: ";",
|
2015-11-16 12:16:13 +00:00
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
2015-05-07 08:55:03 +00:00
|
|
|
Action: RelabelDrop,
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
2015-06-24 07:07:17 +00:00
|
|
|
{
|
2015-08-20 15:18:46 +00:00
|
|
|
SourceLabels: model.LabelNames{"__address__"},
|
2015-08-13 09:39:21 +00:00
|
|
|
TargetLabel: "__tmp_hash",
|
2015-11-16 12:16:13 +00:00
|
|
|
Regex: DefaultRelabelConfig.Regex,
|
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
2015-06-24 07:07:17 +00:00
|
|
|
Modulus: 8,
|
|
|
|
Separator: ";",
|
|
|
|
Action: RelabelHashMod,
|
|
|
|
},
|
|
|
|
{
|
2015-08-20 15:18:46 +00:00
|
|
|
SourceLabels: model.LabelNames{"__tmp_hash"},
|
2015-09-01 13:05:14 +00:00
|
|
|
Regex: MustNewRegexp("1"),
|
2015-06-24 07:07:17 +00:00
|
|
|
Separator: ";",
|
2015-11-16 12:16:13 +00:00
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
2015-06-24 07:07:17 +00:00
|
|
|
Action: RelabelKeep,
|
|
|
|
},
|
2015-09-21 19:41:19 +00:00
|
|
|
{
|
2015-11-16 12:16:13 +00:00
|
|
|
Regex: MustNewRegexp("1"),
|
|
|
|
Separator: ";",
|
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
|
|
|
Action: RelabelLabelMap,
|
2015-09-21 19:41:19 +00:00
|
|
|
},
|
2016-12-14 10:17:42 +00:00
|
|
|
{
|
|
|
|
Regex: MustNewRegexp("d"),
|
|
|
|
Separator: ";",
|
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
|
|
|
Action: RelabelLabelDrop,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Regex: MustNewRegexp("k"),
|
|
|
|
Separator: ";",
|
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
|
|
|
Action: RelabelLabelKeep,
|
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
2015-06-12 21:16:13 +00:00
|
|
|
MetricRelabelConfigs: []*RelabelConfig{
|
|
|
|
{
|
2015-08-20 15:18:46 +00:00
|
|
|
SourceLabels: model.LabelNames{"__name__"},
|
2015-09-01 13:05:14 +00:00
|
|
|
Regex: MustNewRegexp("expensive_metric.*"),
|
2015-06-12 21:16:13 +00:00
|
|
|
Separator: ";",
|
2015-11-16 12:16:13 +00:00
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
2015-06-12 21:16:13 +00:00
|
|
|
Action: RelabelDrop,
|
|
|
|
},
|
|
|
|
},
|
2015-06-04 15:03:12 +00:00
|
|
|
},
|
2015-06-12 11:39:12 +00:00
|
|
|
{
|
|
|
|
JobName: "service-y",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2015-06-12 11:39:12 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
ConsulSDConfigs: []*ConsulSDConfig{
|
|
|
|
{
|
|
|
|
Server: "localhost:1234",
|
|
|
|
Services: []string{"nginx", "cache", "mysql"},
|
|
|
|
TagSeparator: DefaultConsulSDConfig.TagSeparator,
|
2017-03-07 14:47:40 +00:00
|
|
|
Scheme: "https",
|
|
|
|
TLSConfig: TLSConfig{
|
|
|
|
CertFile: "testdata/valid_cert_file",
|
|
|
|
KeyFile: "testdata/valid_key_file",
|
|
|
|
CAFile: "testdata/valid_ca_file",
|
|
|
|
InsecureSkipVerify: false,
|
|
|
|
},
|
2016-11-23 11:41:19 +00:00
|
|
|
},
|
2015-06-12 11:39:12 +00:00
|
|
|
},
|
|
|
|
},
|
2016-10-18 22:19:19 +00:00
|
|
|
|
|
|
|
RelabelConfigs: []*RelabelConfig{
|
|
|
|
{
|
|
|
|
SourceLabels: model.LabelNames{"__meta_sd_consul_tags"},
|
|
|
|
Regex: MustNewRegexp("label:([^=]+)=([^,]+)"),
|
|
|
|
Separator: ",",
|
|
|
|
TargetLabel: "${1}",
|
|
|
|
Replacement: "${2}",
|
|
|
|
Action: RelabelReplace,
|
|
|
|
},
|
|
|
|
},
|
2015-06-12 11:39:12 +00:00
|
|
|
},
|
2015-07-22 15:48:22 +00:00
|
|
|
{
|
|
|
|
JobName: "service-z",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
|
|
|
ScrapeTimeout: model.Duration(10 * time.Second),
|
2015-07-22 15:48:22 +00:00
|
|
|
|
|
|
|
MetricsPath: "/metrics",
|
|
|
|
Scheme: "http",
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
HTTPClientConfig: HTTPClientConfig{
|
|
|
|
TLSConfig: TLSConfig{
|
|
|
|
CertFile: "testdata/valid_cert_file",
|
|
|
|
KeyFile: "testdata/valid_key_file",
|
|
|
|
},
|
2015-09-06 23:07:44 +00:00
|
|
|
|
2017-05-29 11:46:23 +00:00
|
|
|
BearerToken: "mysecret",
|
2016-11-23 11:41:19 +00:00
|
|
|
},
|
2015-07-22 15:48:22 +00:00
|
|
|
},
|
2015-07-18 21:23:58 +00:00
|
|
|
{
|
|
|
|
JobName: "service-kubernetes",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2015-07-18 21:23:58 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
KubernetesSDConfigs: []*KubernetesSDConfig{
|
|
|
|
{
|
|
|
|
APIServer: kubernetesSDHostURL(),
|
|
|
|
Role: KubernetesRoleEndpoint,
|
|
|
|
BasicAuth: &BasicAuth{
|
|
|
|
Username: "myusername",
|
2017-05-29 11:46:23 +00:00
|
|
|
Password: "mysecret",
|
2016-11-23 11:41:19 +00:00
|
|
|
},
|
2017-04-19 12:36:34 +00:00
|
|
|
NamespaceDiscovery: KubernetesNamespaceDiscovery{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
JobName: "service-kubernetes-namespaces",
|
|
|
|
|
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
KubernetesSDConfigs: []*KubernetesSDConfig{
|
|
|
|
{
|
|
|
|
APIServer: kubernetesSDHostURL(),
|
|
|
|
Role: KubernetesRoleEndpoint,
|
|
|
|
NamespaceDiscovery: KubernetesNamespaceDiscovery{
|
|
|
|
Names: []string{
|
|
|
|
"default",
|
|
|
|
},
|
|
|
|
},
|
2015-10-23 15:47:10 +00:00
|
|
|
},
|
2015-07-18 21:23:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-02 13:08:37 +00:00
|
|
|
{
|
|
|
|
JobName: "service-marathon",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2015-09-02 13:08:37 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
MarathonSDConfigs: []*MarathonSDConfig{
|
|
|
|
{
|
|
|
|
Servers: []string{
|
|
|
|
"https://marathon.example.com:443",
|
|
|
|
},
|
|
|
|
Timeout: model.Duration(30 * time.Second),
|
|
|
|
RefreshInterval: model.Duration(30 * time.Second),
|
|
|
|
TLSConfig: TLSConfig{
|
|
|
|
CertFile: "testdata/valid_cert_file",
|
|
|
|
KeyFile: "testdata/valid_key_file",
|
|
|
|
},
|
2016-09-29 12:57:28 +00:00
|
|
|
},
|
2015-09-02 13:08:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-21 18:49:19 +00:00
|
|
|
{
|
|
|
|
JobName: "service-ec2",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2015-09-21 18:49:19 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
EC2SDConfigs: []*EC2SDConfig{
|
|
|
|
{
|
|
|
|
Region: "us-east-1",
|
|
|
|
AccessKey: "access",
|
2017-05-29 11:46:23 +00:00
|
|
|
SecretKey: "mysecret",
|
2016-11-23 11:41:19 +00:00
|
|
|
Profile: "profile",
|
|
|
|
RefreshInterval: model.Duration(60 * time.Second),
|
|
|
|
Port: 80,
|
|
|
|
},
|
2015-09-21 18:49:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-07 03:47:02 +00:00
|
|
|
{
|
|
|
|
JobName: "service-azure",
|
|
|
|
|
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
AzureSDConfigs: []*AzureSDConfig{
|
|
|
|
{
|
|
|
|
SubscriptionID: "11AAAA11-A11A-111A-A111-1111A1111A11",
|
|
|
|
TenantID: "BBBB222B-B2B2-2B22-B222-2BB2222BB2B2",
|
|
|
|
ClientID: "333333CC-3C33-3333-CCC3-33C3CCCCC33C",
|
2017-05-29 11:46:23 +00:00
|
|
|
ClientSecret: "mysecret",
|
2016-11-23 11:41:19 +00:00
|
|
|
RefreshInterval: model.Duration(5 * time.Minute),
|
|
|
|
Port: 9100,
|
|
|
|
},
|
2016-04-07 03:47:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-01-09 23:34:32 +00:00
|
|
|
{
|
|
|
|
JobName: "service-nerve",
|
|
|
|
|
2016-01-29 14:23:11 +00:00
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
2016-01-09 23:34:32 +00:00
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
NerveSDConfigs: []*NerveSDConfig{
|
|
|
|
{
|
|
|
|
Servers: []string{"localhost"},
|
|
|
|
Paths: []string{"/monitoring"},
|
|
|
|
Timeout: model.Duration(10 * time.Second),
|
|
|
|
},
|
2016-01-09 23:34:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-09-15 06:00:14 +00:00
|
|
|
{
|
|
|
|
JobName: "0123service-xxx",
|
|
|
|
|
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
StaticConfigs: []*TargetGroup{
|
|
|
|
{
|
|
|
|
Targets: []model.LabelSet{
|
|
|
|
{model.AddressLabel: "localhost:9090"},
|
|
|
|
},
|
2016-09-15 06:00:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
JobName: "測試",
|
|
|
|
|
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
2016-11-23 11:41:19 +00:00
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
StaticConfigs: []*TargetGroup{
|
|
|
|
{
|
|
|
|
Targets: []model.LabelSet{
|
|
|
|
{model.AddressLabel: "localhost:9090"},
|
|
|
|
},
|
2016-09-15 06:00:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-12-28 02:16:47 +00:00
|
|
|
{
|
|
|
|
JobName: "service-triton",
|
|
|
|
|
|
|
|
ScrapeInterval: model.Duration(15 * time.Second),
|
|
|
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
|
|
|
|
|
|
|
MetricsPath: DefaultScrapeConfig.MetricsPath,
|
|
|
|
Scheme: DefaultScrapeConfig.Scheme,
|
|
|
|
|
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
TritonSDConfigs: []*TritonSDConfig{
|
|
|
|
{
|
|
|
|
|
|
|
|
Account: "testAccount",
|
|
|
|
DNSSuffix: "triton.example.com",
|
|
|
|
Endpoint: "triton.example.com",
|
|
|
|
Port: 9163,
|
|
|
|
RefreshInterval: model.Duration(60 * time.Second),
|
|
|
|
Version: 1,
|
|
|
|
TLSConfig: TLSConfig{
|
|
|
|
CertFile: "testdata/valid_cert_file",
|
|
|
|
KeyFile: "testdata/valid_key_file",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-05-07 08:55:03 +00:00
|
|
|
},
|
2016-11-23 11:42:33 +00:00
|
|
|
AlertingConfig: AlertingConfig{
|
2016-11-24 14:17:50 +00:00
|
|
|
AlertmanagerConfigs: []*AlertmanagerConfig{
|
2016-11-23 11:42:33 +00:00
|
|
|
{
|
|
|
|
Scheme: "https",
|
|
|
|
Timeout: 10 * time.Second,
|
|
|
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
|
|
|
StaticConfigs: []*TargetGroup{
|
|
|
|
{
|
|
|
|
Targets: []model.LabelSet{
|
|
|
|
{model.AddressLabel: "1.2.3.4:9093"},
|
|
|
|
{model.AddressLabel: "1.2.3.5:9093"},
|
|
|
|
{model.AddressLabel: "1.2.3.6:9093"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-06-04 15:03:12 +00:00
|
|
|
original: "",
|
|
|
|
}
|
2015-05-07 08:55:03 +00:00
|
|
|
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
2015-06-07 15:40:22 +00:00
|
|
|
// Parse a valid file that sets a global scrape timeout. This tests whether parsing
|
|
|
|
// an overwritten default field in the global config permanently changes the default.
|
2015-08-05 16:30:37 +00:00
|
|
|
if _, err := LoadFile("testdata/global_timeout.good.yml"); err != nil {
|
2016-10-18 18:14:38 +00:00
|
|
|
t.Errorf("Error parsing %s: %s", "testdata/global_timeout.good.yml", err)
|
2015-06-07 15:40:22 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 16:30:37 +00:00
|
|
|
c, err := LoadFile("testdata/conf.good.yml")
|
2015-05-07 08:55:03 +00:00
|
|
|
if err != nil {
|
2015-06-12 11:39:59 +00:00
|
|
|
t.Fatalf("Error parsing %s: %s", "testdata/conf.good.yml", err)
|
2015-05-07 08:55:03 +00:00
|
|
|
}
|
2015-07-18 21:23:58 +00:00
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
bgot, err := yaml.Marshal(c)
|
|
|
|
if err != nil {
|
2015-06-12 11:39:59 +00:00
|
|
|
t.Fatalf("%s", err)
|
2015-05-07 08:55:03 +00:00
|
|
|
}
|
2015-07-18 21:23:58 +00:00
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
bexp, err := yaml.Marshal(expectedConf)
|
|
|
|
if err != nil {
|
2015-06-12 11:39:59 +00:00
|
|
|
t.Fatalf("%s", err)
|
2015-05-07 08:55:03 +00:00
|
|
|
}
|
|
|
|
expectedConf.original = c.original
|
2013-02-14 00:04:07 +00:00
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
if !reflect.DeepEqual(c, expectedConf) {
|
2015-06-12 11:39:59 +00:00
|
|
|
t.Fatalf("%s: unexpected config result: \n\n%s\n expected\n\n%s", "testdata/conf.good.yml", bgot, bexp)
|
2015-05-07 08:55:03 +00:00
|
|
|
}
|
2015-07-06 12:25:20 +00:00
|
|
|
|
|
|
|
// String method must not reveal authentication credentials.
|
|
|
|
s := c.String()
|
2017-05-29 11:46:23 +00:00
|
|
|
secretRe := regexp.MustCompile("<secret>")
|
|
|
|
matches := secretRe.FindAllStringIndex(s, -1)
|
|
|
|
if len(matches) != 5 || strings.Contains(s, "mysecret") {
|
2015-07-06 12:25:20 +00:00
|
|
|
t.Fatalf("config's String method reveals authentication credentials.")
|
|
|
|
}
|
2017-05-29 11:46:23 +00:00
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var expectedErrors = []struct {
|
|
|
|
filename string
|
|
|
|
errMsg string
|
2013-02-14 00:04:07 +00:00
|
|
|
}{
|
|
|
|
{
|
2015-05-07 08:55:03 +00:00
|
|
|
filename: "jobname.bad.yml",
|
2016-09-15 06:00:14 +00:00
|
|
|
errMsg: `job_name is empty`,
|
2013-02-14 00:04:07 +00:00
|
|
|
}, {
|
2015-05-07 08:55:03 +00:00
|
|
|
filename: "jobname_dup.bad.yml",
|
|
|
|
errMsg: `found multiple scrape configs with job name "prometheus"`,
|
2016-02-12 11:51:55 +00:00
|
|
|
}, {
|
|
|
|
filename: "scrape_interval.bad.yml",
|
|
|
|
errMsg: `scrape timeout greater than scrape interval`,
|
2013-06-11 20:59:27 +00:00
|
|
|
}, {
|
2015-05-07 08:55:03 +00:00
|
|
|
filename: "labelname.bad.yml",
|
|
|
|
errMsg: `"not$allowed" is not a valid label name`,
|
2015-06-06 07:55:22 +00:00
|
|
|
}, {
|
|
|
|
filename: "labelname2.bad.yml",
|
|
|
|
errMsg: `"not:allowed" is not a valid label name`,
|
2015-04-30 19:15:18 +00:00
|
|
|
}, {
|
2015-05-07 08:55:03 +00:00
|
|
|
filename: "regex.bad.yml",
|
|
|
|
errMsg: "error parsing regexp",
|
2015-06-24 07:07:17 +00:00
|
|
|
}, {
|
|
|
|
filename: "modulus_missing.bad.yml",
|
|
|
|
errMsg: "relabel configuration for hashmod requires non-zero modulus",
|
2017-03-18 21:32:08 +00:00
|
|
|
}, {
|
|
|
|
filename: "labelkeep.bad.yml",
|
|
|
|
errMsg: "labelkeep action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labelkeep2.bad.yml",
|
|
|
|
errMsg: "labelkeep action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labelkeep3.bad.yml",
|
|
|
|
errMsg: "labelkeep action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labelkeep4.bad.yml",
|
|
|
|
errMsg: "labelkeep action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labelkeep5.bad.yml",
|
|
|
|
errMsg: "labelkeep action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labeldrop.bad.yml",
|
|
|
|
errMsg: "labeldrop action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labeldrop2.bad.yml",
|
|
|
|
errMsg: "labeldrop action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labeldrop3.bad.yml",
|
|
|
|
errMsg: "labeldrop action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labeldrop4.bad.yml",
|
|
|
|
errMsg: "labeldrop action requires only 'regex', and no other fields",
|
|
|
|
}, {
|
|
|
|
filename: "labeldrop5.bad.yml",
|
|
|
|
errMsg: "labeldrop action requires only 'regex', and no other fields",
|
2015-05-28 05:36:21 +00:00
|
|
|
}, {
|
|
|
|
filename: "rules.bad.yml",
|
|
|
|
errMsg: "invalid rule file path",
|
2015-06-12 11:39:59 +00:00
|
|
|
}, {
|
|
|
|
filename: "unknown_attr.bad.yml",
|
|
|
|
errMsg: "unknown fields in scrape_config: consult_sd_configs",
|
2015-07-22 15:48:22 +00:00
|
|
|
}, {
|
|
|
|
filename: "bearertoken.bad.yml",
|
|
|
|
errMsg: "at most one of bearer_token & bearer_token_file must be configured",
|
|
|
|
}, {
|
|
|
|
filename: "bearertoken_basicauth.bad.yml",
|
|
|
|
errMsg: "at most one of basic_auth, bearer_token & bearer_token_file must be configured",
|
2015-10-23 15:47:10 +00:00
|
|
|
}, {
|
|
|
|
filename: "kubernetes_bearertoken.bad.yml",
|
|
|
|
errMsg: "at most one of bearer_token & bearer_token_file must be configured",
|
2016-07-18 13:16:27 +00:00
|
|
|
}, {
|
|
|
|
filename: "kubernetes_role.bad.yml",
|
|
|
|
errMsg: "role",
|
2017-04-19 12:36:34 +00:00
|
|
|
}, {
|
|
|
|
filename: "kubernetes_namespace_discovery.bad.yml",
|
|
|
|
errMsg: "unknown fields in namespaces",
|
2015-10-23 15:47:10 +00:00
|
|
|
}, {
|
|
|
|
filename: "kubernetes_bearertoken_basicauth.bad.yml",
|
|
|
|
errMsg: "at most one of basic_auth, bearer_token & bearer_token_file must be configured",
|
2015-09-02 13:08:37 +00:00
|
|
|
}, {
|
|
|
|
filename: "marathon_no_servers.bad.yml",
|
|
|
|
errMsg: "Marathon SD config must contain at least one Marathon server",
|
2015-11-07 14:25:51 +00:00
|
|
|
}, {
|
|
|
|
filename: "url_in_targetgroup.bad.yml",
|
|
|
|
errMsg: "\"http://bad\" is not a valid hostname",
|
2016-08-29 14:01:45 +00:00
|
|
|
}, {
|
|
|
|
filename: "target_label_missing.bad.yml",
|
|
|
|
errMsg: "relabel configuration for replace action requires 'target_label' value",
|
|
|
|
}, {
|
|
|
|
filename: "target_label_hashmod_missing.bad.yml",
|
|
|
|
errMsg: "relabel configuration for hashmod action requires 'target_label' value",
|
2013-12-03 10:59:38 +00:00
|
|
|
},
|
2013-02-14 00:04:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 08:55:03 +00:00
|
|
|
func TestBadConfigs(t *testing.T) {
|
|
|
|
for _, ee := range expectedErrors {
|
2015-08-05 16:30:37 +00:00
|
|
|
_, err := LoadFile("testdata/" + ee.filename)
|
2015-05-07 08:55:03 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Expected error parsing %s but got none", ee.filename)
|
2015-05-28 05:36:21 +00:00
|
|
|
continue
|
2015-05-07 08:55:03 +00:00
|
|
|
}
|
|
|
|
if !strings.Contains(err.Error(), ee.errMsg) {
|
|
|
|
t.Errorf("Expected error for %s to contain %q but got: %s", ee.filename, ee.errMsg, err)
|
2013-02-14 00:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 07:55:22 +00:00
|
|
|
|
2016-06-08 13:54:04 +00:00
|
|
|
func TestBadStaticConfigs(t *testing.T) {
|
|
|
|
content, err := ioutil.ReadFile("testdata/static_config.bad.json")
|
2015-06-06 07:55:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
var tg TargetGroup
|
|
|
|
err = json.Unmarshal(content, &tg)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Expected unmarshal error but got none.")
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 14:12:33 +00:00
|
|
|
|
|
|
|
func TestEmptyConfig(t *testing.T) {
|
|
|
|
c, err := Load("")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error parsing empty config file: %s", err)
|
|
|
|
}
|
|
|
|
exp := DefaultConfig
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*c, exp) {
|
|
|
|
t.Fatalf("want %v, got %v", exp, c)
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 17:58:34 +00:00
|
|
|
|
|
|
|
func TestEmptyGlobalBlock(t *testing.T) {
|
|
|
|
c, err := Load("global:\n")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error parsing empty config file: %s", err)
|
|
|
|
}
|
|
|
|
exp := DefaultConfig
|
|
|
|
exp.original = "global:\n"
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*c, exp) {
|
|
|
|
t.Fatalf("want %v, got %v", exp, c)
|
|
|
|
}
|
|
|
|
}
|
2015-09-03 09:47:09 +00:00
|
|
|
|
2016-10-19 10:32:42 +00:00
|
|
|
func TestTargetLabelValidity(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
str string
|
|
|
|
valid bool
|
|
|
|
}{
|
|
|
|
{"-label", false},
|
|
|
|
{"label", true},
|
|
|
|
{"label${1}", true},
|
|
|
|
{"${1}label", true},
|
|
|
|
{"${1}", true},
|
|
|
|
{"${1}label", true},
|
|
|
|
{"${", false},
|
|
|
|
{"$", false},
|
|
|
|
{"${}", false},
|
|
|
|
{"foo${", false},
|
|
|
|
{"$1", true},
|
|
|
|
{"asd$2asd", true},
|
|
|
|
{"-foo${1}bar-", false},
|
|
|
|
{"_${1}_", true},
|
|
|
|
{"foo${bar}foo", true},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
if relabelTarget.Match([]byte(test.str)) != test.valid {
|
|
|
|
t.Fatalf("Expected %q to be %v", test.str, test.valid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 09:47:09 +00:00
|
|
|
func kubernetesSDHostURL() URL {
|
|
|
|
tURL, _ := url.Parse("https://localhost:1234")
|
|
|
|
return URL{URL: tURL}
|
|
|
|
}
|