Skip to content

Commit

Permalink
Gate use of the WAL behind a method check and return an error on atte…
Browse files Browse the repository at this point in the history
…mpted use
  • Loading branch information
odeke-em committed Apr 26, 2021
1 parent f888833 commit e91c130
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti
return errs
}

// Now serialize the requests to the WAL.
if !prwe.walEnabled() {
return prwe.actualExport(ctx, requests)
}

// Otherwise, serialize the requests to the WAL.
if err := prwe.writeToWAL(ctx, requests); err != nil {
errs = append(errs, consumererror.Permanent(err))
}
Expand Down
16 changes: 10 additions & 6 deletions exporter/prometheusremotewriteexporter/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package prometheusremotewriteexporter

import (
"context"
"errors"
"fmt"
"path/filepath"
"time"
Expand Down Expand Up @@ -63,9 +64,13 @@ func (wc *walConfig) refreshDuration() time.Duration {
return wc.RefreshDuration
}

func (prwe *PrwExporter) walEnabled() bool { return prwe.walConfig != nil }

var errWALDisabled = errors.New("Write-Ahead-Log is disabled")

func (prwe *PrwExporter) retrieveWALIndices(context.Context) (err error) {
if prwe.walConfig == nil {
return nil
if !prwe.walEnabled() {
return errWALDisabled
}

prwe.walMu.Lock()
Expand Down Expand Up @@ -117,7 +122,7 @@ func (prwe *PrwExporter) flushToWAL(ctx context.Context, reqL []*prompb.WriteReq
}

func (prwe *PrwExporter) turnOnWALIfEnabled() error {
if prwe.walConfig == nil {
if !prwe.walEnabled() {
return nil
}

Expand Down Expand Up @@ -154,9 +159,8 @@ func (prwe *PrwExporter) closeWAL() {
}

func (prwe *PrwExporter) writeToWAL(ctx context.Context, requests []*prompb.WriteRequest) error {
if prwe.walConfig == nil {
// The WAL isn't enabled.
return nil
if !prwe.walEnabled() {
return errWALDisabled
}

startTime := time.Now()
Expand Down

0 comments on commit e91c130

Please sign in to comment.