Skip to content

Commit

Permalink
Exposing remote writer for use in integration tests (#3797)
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
  • Loading branch information
Danny Kopping authored Jun 3, 2021
1 parent f4bdf5d commit 0bf7b60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/ruler/appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newRemoteWriteAppendable(cfg Config, overrides RulesLimits, logger log.Logg
type RemoteWriteAppender struct {
logger log.Logger
ctx context.Context
remoteWriter remoteWriter
remoteWriter RemoteWriter
userID string
groupKey string

Expand All @@ -65,7 +65,7 @@ func (a *RemoteWriteAppendable) Appender(ctx context.Context) storage.Appender {
return appender
}

client, err := newRemoteWriter(a.cfg, a.userID)
client, err := NewRemoteWriter(a.cfg, a.userID)
if err != nil {
level.Error(a.logger).Log("msg", "error creating remote-write client; setting appender as noop", "err", err, "tenant", a.userID)
return &NoopAppender{}
Expand Down
12 changes: 6 additions & 6 deletions pkg/ruler/remote_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ type queueEntry struct {
sample cortexpb.Sample
}

type remoteWriter interface {
type RemoteWriter interface {
remote.WriteClient

PrepareRequest(queue *util.EvictingQueue) ([]byte, error)
}

type remoteWriteClient struct {
type RemoteWriteClient struct {
remote.WriteClient

labels []labels.Labels
Expand All @@ -43,7 +43,7 @@ type remoteWriteMetrics struct {
remoteWriteErrors *prometheus.CounterVec
}

func newRemoteWriter(cfg Config, userID string) (remoteWriter, error) {
func NewRemoteWriter(cfg Config, userID string) (RemoteWriter, error) {
writeClient, err := remote.NewWriteClient("recording_rules", &remote.ClientConfig{
URL: cfg.RemoteWrite.Client.URL,
Timeout: cfg.RemoteWrite.Client.RemoteTimeout,
Expand All @@ -57,12 +57,12 @@ func newRemoteWriter(cfg Config, userID string) (remoteWriter, error) {
return nil, errors.Wrapf(err, "could not create remote-write client for tenant: %v", userID)
}

return &remoteWriteClient{
return &RemoteWriteClient{
WriteClient: writeClient,
}, nil
}

func (r *remoteWriteClient) prepare(queue *util.EvictingQueue) error {
func (r *RemoteWriteClient) prepare(queue *util.EvictingQueue) error {
// reuse slices, resize if they are not big enough
if cap(r.labels) < queue.Length() {
r.labels = make([]labels.Labels, 0, queue.Length())
Expand All @@ -89,7 +89,7 @@ func (r *remoteWriteClient) prepare(queue *util.EvictingQueue) error {

// PrepareRequest takes the given queue and serializes it into a compressed
// proto write request that will be sent to Cortex
func (r *remoteWriteClient) PrepareRequest(queue *util.EvictingQueue) ([]byte, error) {
func (r *RemoteWriteClient) PrepareRequest(queue *util.EvictingQueue) ([]byte, error) {
// prepare labels and samples from queue
err := r.prepare(queue)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ruler/remote_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func TestPrepare(t *testing.T) {
client := remoteWriteClient{}
client := RemoteWriteClient{}
queue, err := util.NewEvictingQueue(1000, func() {})
require.Nil(t, err)

Expand Down Expand Up @@ -105,7 +105,7 @@ func createBasicAppender(t *testing.T) *RemoteWriteAppender {
appendable := createBasicAppendable(100)

appender := appendable.Appender(ctx).(*RemoteWriteAppender)
client, err := newRemoteWriter(appendable.cfg, "fake")
client, err := NewRemoteWriter(appendable.cfg, "fake")
require.Nil(t, err)

appender.remoteWriter = client
Expand Down

0 comments on commit 0bf7b60

Please sign in to comment.