Skip to content

Commit

Permalink
Adjust DefaultPromConfig signature; use constant instead
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Gera <matejgera@gmail.com>
  • Loading branch information
matej-g committed Mar 3, 2022
1 parent 0e8ee80 commit a8aa8a1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 50 deletions.
9 changes: 5 additions & 4 deletions test/e2e/e2ethanos/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,15 +1030,16 @@ func NewS3Config(bucket, endpoint, basePath string) s3.Config {
// NOTE: by using aggregation all results are now unsorted.
var QueryUpWithoutInstance = func() string { return "sum(up) without (instance)" }

// LocalPrometheusTarget is a constant to be used in the Prometheus config if you
// wish to enable Prometheus to scrape itself in a test.
const LocalPrometheusTarget = "localhost:9090"

// DefaultPromConfig returns Prometheus config that sets Prometheus to:
// * expose 2 external labels, source and replica.
// * optionallly scrape self. This will produce up == 0 metric which we can assert on.
// * optionally remote write endpoint to write into.
func DefaultPromConfig(name string, replica int, remoteWriteEndpoint, ruleFile string, scrapeSelf bool, scrapeTargets ...string) string {
func DefaultPromConfig(name string, replica int, remoteWriteEndpoint, ruleFile string, scrapeTargets ...string) string {
var targets string
if scrapeSelf {
targets = "localhost:9090"
}
if len(scrapeTargets) > 0 {
targets = strings.Join(scrapeTargets, ",")
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/exemplars_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestExemplarsAPI_Fanout(t *testing.T) {
prom1, sidecar1, err = e2ethanos.NewPrometheusWithSidecar(
e,
"prom1",
e2ethanos.DefaultPromConfig("ha", 0, "", "", true, "localhost:9090", qUnitiated.InternalEndpoint("http")),
e2ethanos.DefaultPromConfig("ha", 0, "", "", "localhost:9090", qUnitiated.InternalEndpoint("http"), e2ethanos.LocalPrometheusTarget),
"",
e2ethanos.DefaultPrometheusImage(),
"",
Expand All @@ -52,7 +52,7 @@ func TestExemplarsAPI_Fanout(t *testing.T) {
prom2, sidecar2, err = e2ethanos.NewPrometheusWithSidecar(
e,
"prom2",
e2ethanos.DefaultPromConfig("ha", 1, "", "", true, "localhost:9090", qUnitiated.InternalEndpoint("http")),
e2ethanos.DefaultPromConfig("ha", 1, "", "", "localhost:9090", qUnitiated.InternalEndpoint("http"), e2ethanos.LocalPrometheusTarget),
"",
e2ethanos.DefaultPrometheusImage(),
"",
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/info_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func TestInfo(t *testing.T) {
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone1", e2ethanos.DefaultPromConfig("prom-alone1", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone1", e2ethanos.DefaultPromConfig("prom-alone1", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "alone2", e2ethanos.DefaultPromConfig("prom-alone2", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "")
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "alone2", e2ethanos.DefaultPromConfig("prom-alone2", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom3, sidecar3, err := e2ethanos.NewPrometheusWithSidecar(e, "alone3", e2ethanos.DefaultPromConfig("prom-alone3", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "")
prom3, sidecar3, err := e2ethanos.NewPrometheusWithSidecar(e, "alone3", e2ethanos.DefaultPromConfig("prom-alone3", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1, prom2, sidecar2, prom3, sidecar3))

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/metadata_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestMetadataAPI_Fanout(t *testing.T) {
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(
e,
"prom1",
e2ethanos.DefaultPromConfig("ha", 0, "", "", false, "localhost:9090", "sidecar-prom1:8080"),
e2ethanos.DefaultPromConfig("ha", 0, "", "", e2ethanos.LocalPrometheusTarget, "sidecar-prom1:8080"),
"",
e2ethanos.DefaultPrometheusImage(), "",
)
Expand All @@ -39,7 +39,7 @@ func TestMetadataAPI_Fanout(t *testing.T) {
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(
e,
"prom2",
e2ethanos.DefaultPromConfig("ha", 1, "", "", false, "localhost:9090", "sidecar-prom2:8080"),
e2ethanos.DefaultPromConfig("ha", 1, "", "", e2ethanos.LocalPrometheusTarget, "sidecar-prom2:8080"),
"",
e2ethanos.DefaultPrometheusImage(), "",
)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestQueryFrontend(t *testing.T) {

now := time.Now()

prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "1", e2ethanos.DefaultPromConfig("test", 0, "", "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "1", e2ethanos.DefaultPromConfig("test", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom, sidecar))

Expand Down Expand Up @@ -396,7 +396,7 @@ func TestQueryFrontendMemcachedCache(t *testing.T) {

now := time.Now()

prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "1", e2ethanos.DefaultPromConfig("test", 0, "", "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "1", e2ethanos.DefaultPromConfig("test", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom, sidecar))

Expand Down
34 changes: 17 additions & 17 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestSidecarNotReady(t *testing.T) {
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom, sidecar))
testutil.Ok(t, prom.Stop())
Expand Down Expand Up @@ -110,13 +110,13 @@ func TestQuery(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(receiverRunnable))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "remote-and-sidecar", e2ethanos.DefaultPromConfig("prom-both-remote-write-and-sidecar", 1234, e2ethanos.RemoteWriteEndpoint(receiver.InternalEndpoint("remote-write")), "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "remote-and-sidecar", e2ethanos.DefaultPromConfig("prom-both-remote-write-and-sidecar", 1234, e2ethanos.RemoteWriteEndpoint(receiver.InternalEndpoint("remote-write")), "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom3, sidecar3, err := e2ethanos.NewPrometheusWithSidecar(e, "ha1", e2ethanos.DefaultPromConfig("prom-ha", 0, "", filepath.Join(e2ethanos.ContainerSharedDir, "", "*.yaml"), true), "", e2ethanos.DefaultPrometheusImage(), "")
prom3, sidecar3, err := e2ethanos.NewPrometheusWithSidecar(e, "ha1", e2ethanos.DefaultPromConfig("prom-ha", 0, "", filepath.Join(e2ethanos.ContainerSharedDir, "", "*.yaml"), e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom4, sidecar4, err := e2ethanos.NewPrometheusWithSidecar(e, "ha2", e2ethanos.DefaultPromConfig("prom-ha", 1, "", filepath.Join(e2ethanos.ContainerSharedDir, "", "*.yaml"), true), "", e2ethanos.DefaultPrometheusImage(), "")
prom4, sidecar4, err := e2ethanos.NewPrometheusWithSidecar(e, "ha2", e2ethanos.DefaultPromConfig("prom-ha", 1, "", filepath.Join(e2ethanos.ContainerSharedDir, "", "*.yaml"), e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1, prom2, sidecar2, prom3, sidecar3, prom4, sidecar4))

Expand Down Expand Up @@ -264,9 +264,9 @@ func TestQueryLabelNames(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(receiverRunnable))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "remote-and-sidecar", e2ethanos.DefaultPromConfig("prom-both-remote-write-and-sidecar", 1234, e2ethanos.RemoteWriteEndpoint(receiver.InternalEndpoint("remote-write")), "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "remote-and-sidecar", e2ethanos.DefaultPromConfig("prom-both-remote-write-and-sidecar", 1234, e2ethanos.RemoteWriteEndpoint(receiver.InternalEndpoint("remote-write")), "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1, prom2, sidecar2))

Expand Down Expand Up @@ -316,9 +316,9 @@ func TestQueryLabelValues(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(receiverRunnable))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", true), "", e2ethanos.DefaultPrometheusImage(), "")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "remote-and-sidecar", e2ethanos.DefaultPromConfig("prom-both-remote-write-and-sidecar", 1234, e2ethanos.RemoteWriteEndpoint(receiver.InternalEndpoint("remote-write")), "", false), "", e2ethanos.DefaultPrometheusImage(), "")
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "remote-and-sidecar", e2ethanos.DefaultPromConfig("prom-both-remote-write-and-sidecar", 1234, e2ethanos.RemoteWriteEndpoint(receiver.InternalEndpoint("remote-write")), ""), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1, prom2, sidecar2))

Expand Down Expand Up @@ -359,7 +359,7 @@ func TestQueryWithAuthorizedSidecar(t *testing.T) {
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", true), defaultWebConfig(), e2ethanos.DefaultPrometheusImage(), "")
prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), defaultWebConfig(), e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom, sidecar))

Expand Down Expand Up @@ -417,7 +417,7 @@ func TestQueryCompatibilityWithPreInfoAPI(t *testing.T) {
p1, s1, err := e2ethanos.NewPrometheusWithSidecarCustomImage(
e,
"p1",
e2ethanos.DefaultPromConfig("p1", 0, "", filepath.Join(e2ethanos.ContainerSharedDir, promRulesSubDir, "*.yaml"), true, "localhost:9090", qUninit.InternalEndpoint("http")),
e2ethanos.DefaultPromConfig("p1", 0, "", filepath.Join(e2ethanos.ContainerSharedDir, promRulesSubDir, "*.yaml"), e2ethanos.LocalPrometheusTarget, qUninit.InternalEndpoint("http")),
"",
e2ethanos.DefaultPrometheusImage(),
"",
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestSidecarStorePushdown(t *testing.T) {
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", ""), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1))

Expand Down Expand Up @@ -817,11 +817,11 @@ func TestSidecarQueryEvaluation(t *testing.T) {
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", ""), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1))

prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "p2", e2ethanos.DefaultPromConfig("p2", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "p2", e2ethanos.DefaultPromConfig("p2", 0, "", ""), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom2, sidecar2))

Expand Down Expand Up @@ -1187,11 +1187,11 @@ func TestSidecarQueryEvaluationWithDedup(t *testing.T) {
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", ""), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1))

prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "p2", e2ethanos.DefaultPromConfig("p1", 1, "", "", false), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
prom2, sidecar2, err := e2ethanos.NewPrometheusWithSidecar(e, "p2", e2ethanos.DefaultPromConfig("p1", 1, "", ""), "", e2ethanos.DefaultPrometheusImage(), "", "remote-write-receiver")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom2, sidecar2))

Expand Down Expand Up @@ -1231,7 +1231,7 @@ func TestSidecarAlignmentPushdown(t *testing.T) {

now := time.Now()

prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", "", false), "", e2ethanos.DefaultPrometheusImage(), now.Add(time.Duration(-1)*time.Hour).Format(time.RFC3339), now.Format(time.RFC3339), "remote-write-receiver")
prom1, sidecar1, err := e2ethanos.NewPrometheusWithSidecar(e, "p1", e2ethanos.DefaultPromConfig("p1", 0, "", ""), "", e2ethanos.DefaultPrometheusImage(), now.Add(time.Duration(-1)*time.Hour).Format(time.RFC3339), now.Format(time.RFC3339), "remote-write-receiver")
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1))

Expand Down
Loading

0 comments on commit a8aa8a1

Please sign in to comment.