Skip to content

Commit

Permalink
Use static addresses for am and querier
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Okoko <okokomichaels@outlook.com>
  • Loading branch information
idoqo committed Jun 1, 2021
1 parent ac4ecc9 commit 5e98c72
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
6 changes: 3 additions & 3 deletions pkg/rules/remotewrite/remotewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

type Config struct {
Name string `yaml:"name"`
RemoteStore *config.RemoteWriteConfig `yaml:"remote_write,omitempty"`
Name string `yaml:"name"`
RemoteStore *config.RemoteWriteConfig `yaml:"remote_write,omitempty"`
}

func LoadRemoteWriteConfig(configYAML []byte) (Config, error) {
Expand All @@ -38,4 +38,4 @@ func NewFanoutStorage(logger log.Logger, reg prometheus.Registerer, walDir strin
return nil, fmt.Errorf("failed applying config to remote storage: %w", err)
}
return storage.NewFanout(logger, walStore, remoteStore), nil
}
}
3 changes: 2 additions & 1 deletion test/e2e/e2ethanos/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package e2ethanos
import (
"encoding/json"
"fmt"
"github.com/thanos-io/thanos/pkg/rules/remotewrite"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"time"

"github.com/thanos-io/thanos/pkg/rules/remotewrite"

"github.com/cortexproject/cortex/integration/e2e"
"github.com/cortexproject/cortex/pkg/util"
"github.com/pkg/errors"
Expand Down
69 changes: 28 additions & 41 deletions test/e2e/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
commoncfg "github.com/prometheus/common/config"
"github.com/prometheus/prometheus/config"
"github.com/thanos-io/thanos/pkg/rules/remotewrite"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"sync"
"testing"
"time"

commoncfg "github.com/prometheus/common/config"
"github.com/prometheus/prometheus/config"
"github.com/thanos-io/thanos/pkg/rules/remotewrite"

"github.com/cortexproject/cortex/integration/e2e"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -560,10 +560,13 @@ func TestRule(t *testing.T) {
}
}

// TestRule_CanRemoteWriteData checks that Thanos Ruler can be run in stateless mode
// where it remote_writes rule evaluations to a Prometheus remote-write endpoint (typically
// a Thanos Receiver).
func TestRule_CanRemoteWriteData(t *testing.T) {
t.Parallel()

testAlertRuleRecordAbsentMetric := `
testRuleRecordAbsentMetric := `
groups:
- name: example_record_rules
interval: 100ms
Expand All @@ -579,16 +582,10 @@ groups:
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
t.Cleanup(cancel)

// Prepare work dirs.
rulesSubDir := filepath.Join("rules")
rulesSubDir := "rules"
rulesPath := filepath.Join(s.SharedDir(), rulesSubDir)
testutil.Ok(t, os.MkdirAll(rulesPath, os.ModePerm))
createRuleFile(t, filepath.Join(rulesPath, fmt.Sprintf("rules-0.yaml")), testAlertRuleRecordAbsentMetric)
amTargetsSubDir := filepath.Join("rules_am_targets")
testutil.Ok(t, os.MkdirAll(filepath.Join(s.SharedDir(), amTargetsSubDir), os.ModePerm))
queryTargetsSubDir := filepath.Join("rules_query_targets")
testutil.Ok(t, os.MkdirAll(filepath.Join(s.SharedDir(), queryTargetsSubDir), os.ModePerm))

createRuleFile(t, filepath.Join(rulesPath, "rules-0.yaml"), testRuleRecordAbsentMetric)

am, err := e2ethanos.NewAlertmanager(s.SharedDir(), "1")
testutil.Ok(t, err)
Expand All @@ -597,8 +594,7 @@ groups:
receiver, err := e2ethanos.NewReceiver(s.SharedDir(), s.NetworkName(), "1", 1)
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(receiver))
rwURL, err := url.Parse(e2ethanos.RemoteWriteEndpoint(receiver.NetworkEndpoint(8081)))
testutil.Ok(t, err)
rwURL := mustURLParse(t, e2ethanos.RemoteWriteEndpoint(receiver.NetworkEndpoint(8081)))

querier, err := e2ethanos.NewQuerier(s.SharedDir(), "1", []string{receiver.GRPCNetworkEndpoint()}, nil, nil, nil, nil, nil, "", "")
testutil.Ok(t, err)
Expand All @@ -607,13 +603,6 @@ groups:
r, err := e2ethanos.NewRuler(s.SharedDir(), "1", rulesSubDir, []alert.AlertmanagerConfig{
{
EndpointsConfig: http_util.EndpointsConfig{
FileSDConfigs: []http_util.FileSDConfig{
{
// FileSD which will be used to register discover dynamically am1.
Files: []string{filepath.Join(e2e.ContainerSharedDir, amTargetsSubDir, "*.yaml")},
RefreshInterval: model.Duration(time.Second),
},
},
StaticAddresses: []string{
am.NetworkHTTPEndpoint(),
},
Expand All @@ -625,30 +614,22 @@ groups:
}, []query.Config{
{
EndpointsConfig: http_util.EndpointsConfig{
// We test Statically Addressed queries in other tests. Focus on FileSD here.
FileSDConfigs: []http_util.FileSDConfig{
{
// FileSD which will be used to register discover dynamically q.
Files: []string{filepath.Join(e2e.ContainerSharedDir, queryTargetsSubDir, "*.yaml")},
RefreshInterval: model.Duration(time.Second),
},
StaticAddresses: []string{
querier.NetworkHTTPEndpoint(),
},
Scheme: "http",
},
},
}, true, remotewrite.Config{
}, true, remotewrite.Config{
Name: "ruler-rw-receivers",
RemoteStore: &config.RemoteWriteConfig{
URL: &commoncfg.URL{URL: rwURL},
URL: &commoncfg.URL{URL: rwURL},
Name: "thanos-receiver",
},
})
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(r))

writeTargets(t, filepath.Join(s.SharedDir(), queryTargetsSubDir, "targets.yaml"), querier.NetworkHTTPEndpoint())
writeTargets(t, filepath.Join(s.SharedDir(), amTargetsSubDir, "targets.yaml"), am.NetworkHTTPEndpoint())

t.Run("inject samples into receiver to reset its StoreAPI MinTime", func(t *testing.T) {
// inject data into receiver to reset its minTime (so it doesn't get filtered out by store)
// the sample is injected through a prometheus instance that remote_writes samples into the receiver node
Expand All @@ -660,11 +641,11 @@ groups:
Deduplicate: false,
}, []model.Metric{
{
"job":"myself",
"job": "myself",
"prometheus": "prom",
"receive": "1",
"replica": "0",
"tenant_id": "default-tenant",
"receive": "1",
"replica": "0",
"tenant_id": "default-tenant",
},
})
})
Expand All @@ -686,15 +667,21 @@ groups:
Deduplicate: false,
}, []model.Metric{
{
"__name__": "test_absent_metric",
"job":"thanos-receive",
"receive": "1",
"__name__": "test_absent_metric",
"job": "thanos-receive",
"receive": "1",
"tenant_id": "default-tenant",
},
})
})
}

// TestRule_CanPersistWALData checks that in stateless mode, Thanos Ruler can persist rule evaluations
// which couldn't be sent to the remote write endpoint (e.g because receiver isn't available).
func TestRule_CanPersistWALData(t *testing.T) {
//TODO: Implement test with unavailable remote-write endpoint(receiver)
}

// Test Ruler behavior on different storepb.PartialResponseStrategy when having partial response from single `failingStoreAPI`.
func TestRulePartialResponse(t *testing.T) {
t.Skip("TODO: Allow HTTP ports from binaries running on host to be accessible.")
Expand Down

0 comments on commit 5e98c72

Please sign in to comment.