From 98752251a50e101e82e5e71453fed80399daced0 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Thu, 3 Jun 2021 16:37:23 +0200 Subject: [PATCH] Exposing remote writer for use in integration tests Signed-off-by: Danny Kopping --- pkg/ruler/appender.go | 4 ++-- pkg/ruler/remote_write.go | 12 ++++++------ pkg/ruler/remote_write_test.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/ruler/appender.go b/pkg/ruler/appender.go index 21bacc8b430d..80e6c3e31d09 100644 --- a/pkg/ruler/appender.go +++ b/pkg/ruler/appender.go @@ -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 @@ -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{} diff --git a/pkg/ruler/remote_write.go b/pkg/ruler/remote_write.go index 13b4f910df53..1c4df4485720 100644 --- a/pkg/ruler/remote_write.go +++ b/pkg/ruler/remote_write.go @@ -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 @@ -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, @@ -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()) @@ -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 { diff --git a/pkg/ruler/remote_write_test.go b/pkg/ruler/remote_write_test.go index 43b77bbf374c..9a5efa2460fc 100644 --- a/pkg/ruler/remote_write_test.go +++ b/pkg/ruler/remote_write_test.go @@ -15,7 +15,7 @@ import ( ) func TestPrepare(t *testing.T) { - client := remoteWriteClient{} + client := RemoteWriteClient{} queue, err := util.NewEvictingQueue(1000, func() {}) require.Nil(t, err) @@ -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