github.com/thanos-io/thanos@v0.32.5/pkg/rules/prometheus_test.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package rules
     5  
     6  import (
     7  	"fmt"
     8  	"net/url"
     9  	"os"
    10  	"path/filepath"
    11  	"testing"
    12  
    13  	"github.com/prometheus/prometheus/model/labels"
    14  
    15  	"github.com/efficientgo/core/testutil"
    16  	"github.com/thanos-io/thanos/pkg/promclient"
    17  	"github.com/thanos-io/thanos/pkg/testutil/e2eutil"
    18  )
    19  
    20  func TestPrometheus_Rules_e2e(t *testing.T) {
    21  	p, err := e2eutil.NewPrometheus()
    22  	testutil.Ok(t, err)
    23  	defer func() { testutil.Ok(t, p.Stop()) }()
    24  
    25  	curr, err := os.Getwd()
    26  	testutil.Ok(t, err)
    27  	root := filepath.Join(curr, "../../")
    28  
    29  	p.SetConfig(fmt.Sprintf(`
    30  global:
    31    external_labels:
    32      region: eu-west
    33  
    34  rule_files:
    35    - %s/examples/alerts/alerts.yaml
    36    - %s/examples/alerts/rules.yaml
    37  `, root, root))
    38  	testutil.Ok(t, p.Start())
    39  
    40  	u, err := url.Parse(fmt.Sprintf("http://%s", p.Addr()))
    41  	testutil.Ok(t, err)
    42  
    43  	promRules := NewPrometheus(u, promclient.NewDefaultClient(), func() labels.Labels {
    44  		return labels.FromStrings("replica", "test1")
    45  	})
    46  	testRulesAgainstExamples(t, filepath.Join(root, "examples/alerts"), promRules)
    47  }