@@ -23,8 +23,6 @@ import (
2323 "time"
2424
2525 "github.com/alecthomas/units"
26- "github.com/google/go-cmp/cmp"
27- "github.com/google/go-cmp/cmp/cmpopts"
2826 "github.com/grafana/regexp"
2927 "github.com/prometheus/common/config"
3028 "github.com/prometheus/common/model"
@@ -126,12 +124,11 @@ var expectedConf = &Config{
126124 Name : "drop_expensive" ,
127125 WriteRelabelConfigs : []* relabel.Config {
128126 {
129- SourceLabels : model.LabelNames {"__name__" },
130- Separator : ";" ,
131- Regex : relabel .MustNewRegexp ("expensive.*" ),
132- Replacement : "$1" ,
133- Action : relabel .Drop ,
134- MetricNameValidationScheme : model .UTF8Validation ,
127+ SourceLabels : model.LabelNames {"__name__" },
128+ Separator : ";" ,
129+ Regex : relabel .MustNewRegexp ("expensive.*" ),
130+ Replacement : "$1" ,
131+ Action : relabel .Drop ,
135132 },
136133 },
137134 QueueConfig : DefaultQueueConfig ,
@@ -281,56 +278,50 @@ var expectedConf = &Config{
281278
282279 RelabelConfigs : []* relabel.Config {
283280 {
284- SourceLabels : model.LabelNames {"job" , "__meta_dns_name" },
285- TargetLabel : "job" ,
286- Separator : ";" ,
287- Regex : relabel .MustNewRegexp ("(.*)some-[regex]" ),
288- Replacement : "foo-${1}" ,
289- Action : relabel .Replace ,
290- MetricNameValidationScheme : model .UTF8Validation ,
281+ SourceLabels : model.LabelNames {"job" , "__meta_dns_name" },
282+ TargetLabel : "job" ,
283+ Separator : ";" ,
284+ Regex : relabel .MustNewRegexp ("(.*)some-[regex]" ),
285+ Replacement : "foo-${1}" ,
286+ Action : relabel .Replace ,
291287 },
292288 {
293- SourceLabels : model.LabelNames {"abc" },
294- TargetLabel : "cde" ,
295- Separator : ";" ,
296- Regex : relabel .DefaultRelabelConfig .Regex ,
297- Replacement : relabel .DefaultRelabelConfig .Replacement ,
298- Action : relabel .Replace ,
299- MetricNameValidationScheme : model .UTF8Validation ,
289+ SourceLabels : model.LabelNames {"abc" },
290+ TargetLabel : "cde" ,
291+ Separator : ";" ,
292+ Regex : relabel .DefaultRelabelConfig .Regex ,
293+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
294+ Action : relabel .Replace ,
300295 },
301296 {
302- TargetLabel : "abc" ,
303- Separator : ";" ,
304- Regex : relabel .DefaultRelabelConfig .Regex ,
305- Replacement : "static" ,
306- Action : relabel .Replace ,
307- MetricNameValidationScheme : model .UTF8Validation ,
297+ TargetLabel : "abc" ,
298+ Separator : ";" ,
299+ Regex : relabel .DefaultRelabelConfig .Regex ,
300+ Replacement : "static" ,
301+ Action : relabel .Replace ,
308302 },
309303 {
310- TargetLabel : "abc" ,
311- Separator : ";" ,
312- Regex : relabel .MustNewRegexp ("" ),
313- Replacement : "static" ,
314- Action : relabel .Replace ,
315- MetricNameValidationScheme : model .UTF8Validation ,
304+ TargetLabel : "abc" ,
305+ Separator : ";" ,
306+ Regex : relabel .MustNewRegexp ("" ),
307+ Replacement : "static" ,
308+ Action : relabel .Replace ,
316309 },
317310 {
318- SourceLabels : model.LabelNames {"foo" },
319- TargetLabel : "abc" ,
320- Action : relabel .KeepEqual ,
321- Regex : relabel .DefaultRelabelConfig .Regex ,
322- Replacement : relabel .DefaultRelabelConfig .Replacement ,
323- Separator : relabel .DefaultRelabelConfig .Separator ,
324- MetricNameValidationScheme : model .UTF8Validation ,
311+ SourceLabels : model.LabelNames {"foo" },
312+ TargetLabel : "abc" ,
313+ Action : relabel .KeepEqual ,
314+ Regex : relabel .DefaultRelabelConfig .Regex ,
315+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
316+ Separator : relabel .DefaultRelabelConfig .Separator ,
325317 },
326318 {
327- SourceLabels : model.LabelNames {"foo" },
328- TargetLabel : "abc" ,
329- Action : relabel .DropEqual ,
330- Regex : relabel .DefaultRelabelConfig .Regex ,
331- Replacement : relabel .DefaultRelabelConfig .Replacement ,
332- Separator : relabel .DefaultRelabelConfig .Separator ,
333- MetricNameValidationScheme : model .UTF8Validation ,
319+ SourceLabels : model.LabelNames {"foo" },
320+ TargetLabel : "abc" ,
321+ Action : relabel .DropEqual ,
322+ Regex : relabel .DefaultRelabelConfig .Regex ,
323+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
324+ Separator : relabel .DefaultRelabelConfig .Separator ,
334325 },
335326 },
336327 },
@@ -385,61 +376,54 @@ var expectedConf = &Config{
385376
386377 RelabelConfigs : []* relabel.Config {
387378 {
388- SourceLabels : model.LabelNames {"job" },
389- Regex : relabel .MustNewRegexp ("(.*)some-[regex]" ),
390- Separator : ";" ,
391- Replacement : relabel .DefaultRelabelConfig .Replacement ,
392- Action : relabel .Drop ,
393- MetricNameValidationScheme : model .UTF8Validation ,
379+ SourceLabels : model.LabelNames {"job" },
380+ Regex : relabel .MustNewRegexp ("(.*)some-[regex]" ),
381+ Separator : ";" ,
382+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
383+ Action : relabel .Drop ,
394384 },
395385 {
396- SourceLabels : model.LabelNames {"__address__" },
397- TargetLabel : "__tmp_hash" ,
398- Regex : relabel .DefaultRelabelConfig .Regex ,
399- Replacement : relabel .DefaultRelabelConfig .Replacement ,
400- Modulus : 8 ,
401- Separator : ";" ,
402- Action : relabel .HashMod ,
403- MetricNameValidationScheme : model .UTF8Validation ,
386+ SourceLabels : model.LabelNames {"__address__" },
387+ TargetLabel : "__tmp_hash" ,
388+ Regex : relabel .DefaultRelabelConfig .Regex ,
389+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
390+ Modulus : 8 ,
391+ Separator : ";" ,
392+ Action : relabel .HashMod ,
404393 },
405394 {
406- SourceLabels : model.LabelNames {"__tmp_hash" },
407- Regex : relabel .MustNewRegexp ("1" ),
408- Separator : ";" ,
409- Replacement : relabel .DefaultRelabelConfig .Replacement ,
410- Action : relabel .Keep ,
411- MetricNameValidationScheme : model .UTF8Validation ,
395+ SourceLabels : model.LabelNames {"__tmp_hash" },
396+ Regex : relabel .MustNewRegexp ("1" ),
397+ Separator : ";" ,
398+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
399+ Action : relabel .Keep ,
412400 },
413401 {
414- Regex : relabel .MustNewRegexp ("1" ),
415- Separator : ";" ,
416- Replacement : relabel .DefaultRelabelConfig .Replacement ,
417- Action : relabel .LabelMap ,
418- MetricNameValidationScheme : model .UTF8Validation ,
402+ Regex : relabel .MustNewRegexp ("1" ),
403+ Separator : ";" ,
404+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
405+ Action : relabel .LabelMap ,
419406 },
420407 {
421- Regex : relabel .MustNewRegexp ("d" ),
422- Separator : ";" ,
423- Replacement : relabel .DefaultRelabelConfig .Replacement ,
424- Action : relabel .LabelDrop ,
425- MetricNameValidationScheme : model .UTF8Validation ,
408+ Regex : relabel .MustNewRegexp ("d" ),
409+ Separator : ";" ,
410+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
411+ Action : relabel .LabelDrop ,
426412 },
427413 {
428- Regex : relabel .MustNewRegexp ("k" ),
429- Separator : ";" ,
430- Replacement : relabel .DefaultRelabelConfig .Replacement ,
431- Action : relabel .LabelKeep ,
432- MetricNameValidationScheme : model .UTF8Validation ,
414+ Regex : relabel .MustNewRegexp ("k" ),
415+ Separator : ";" ,
416+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
417+ Action : relabel .LabelKeep ,
433418 },
434419 },
435420 MetricRelabelConfigs : []* relabel.Config {
436421 {
437- SourceLabels : model.LabelNames {"__name__" },
438- Regex : relabel .MustNewRegexp ("expensive_metric.*" ),
439- Separator : ";" ,
440- Replacement : relabel .DefaultRelabelConfig .Replacement ,
441- Action : relabel .Drop ,
442- MetricNameValidationScheme : model .UTF8Validation ,
422+ SourceLabels : model.LabelNames {"__name__" },
423+ Regex : relabel .MustNewRegexp ("expensive_metric.*" ),
424+ Separator : ";" ,
425+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
426+ Action : relabel .Drop ,
443427 },
444428 },
445429 },
@@ -494,13 +478,12 @@ var expectedConf = &Config{
494478
495479 RelabelConfigs : []* relabel.Config {
496480 {
497- SourceLabels : model.LabelNames {"__meta_sd_consul_tags" },
498- Regex : relabel .MustNewRegexp ("label:([^=]+)=([^,]+)" ),
499- Separator : "," ,
500- TargetLabel : "${1}" ,
501- Replacement : "${2}" ,
502- Action : relabel .Replace ,
503- MetricNameValidationScheme : model .UTF8Validation ,
481+ SourceLabels : model.LabelNames {"__meta_sd_consul_tags" },
482+ Regex : relabel .MustNewRegexp ("label:([^=]+)=([^,]+)" ),
483+ Separator : "," ,
484+ TargetLabel : "${1}" ,
485+ Replacement : "${2}" ,
486+ Action : relabel .Replace ,
504487 },
505488 },
506489 },
@@ -1292,13 +1275,12 @@ var expectedConf = &Config{
12921275
12931276 RelabelConfigs : []* relabel.Config {
12941277 {
1295- Action : relabel .Uppercase ,
1296- Regex : relabel .DefaultRelabelConfig .Regex ,
1297- Replacement : relabel .DefaultRelabelConfig .Replacement ,
1298- Separator : relabel .DefaultRelabelConfig .Separator ,
1299- SourceLabels : model.LabelNames {"instance" },
1300- TargetLabel : "instance" ,
1301- MetricNameValidationScheme : model .UTF8Validation ,
1278+ Action : relabel .Uppercase ,
1279+ Regex : relabel .DefaultRelabelConfig .Regex ,
1280+ Replacement : relabel .DefaultRelabelConfig .Replacement ,
1281+ Separator : relabel .DefaultRelabelConfig .Separator ,
1282+ SourceLabels : model.LabelNames {"instance" },
1283+ TargetLabel : "instance" ,
13021284 },
13031285 },
13041286
@@ -1970,14 +1952,7 @@ func TestLoadConfig(t *testing.T) {
19701952 c , err := LoadFile ("testdata/conf.good.yml" , false , promslog .NewNopLogger ())
19711953
19721954 require .NoError (t , err )
1973- testutil .RequireEqualWithOptions (t , expectedConf , c , []cmp.Option {
1974- cmpopts .IgnoreUnexported (config.ProxyConfig {}),
1975- cmpopts .IgnoreUnexported (ionos.SDConfig {}),
1976- cmpopts .IgnoreUnexported (stackit.SDConfig {}),
1977- cmpopts .IgnoreUnexported (regexp.Regexp {}),
1978- cmpopts .IgnoreUnexported (hetzner.SDConfig {}),
1979- cmpopts .IgnoreUnexported (Config {}),
1980- })
1955+ require .Equal (t , expectedConf , c )
19811956}
19821957
19831958func TestScrapeIntervalLarger (t * testing.T ) {
0 commit comments