diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index 7a4a46b473f..bb6ee9401bd 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -279,7 +279,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)) } diff --git a/exporter/prometheusremotewriteexporter/wal.go b/exporter/prometheusremotewriteexporter/wal.go index 97d07458d3a..50073683fee 100644 --- a/exporter/prometheusremotewriteexporter/wal.go +++ b/exporter/prometheusremotewriteexporter/wal.go @@ -16,6 +16,7 @@ package prometheusremotewriteexporter import ( "context" + "errors" "fmt" "path/filepath" "time" @@ -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() @@ -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 } @@ -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()