From e91c130a1708a3b2dfb1c9c8ff29d6313320db01 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Sun, 25 Apr 2021 17:12:45 -0700 Subject: [PATCH] Gate use of the WAL behind a method check and return an error on attempted use --- .../prometheusremotewriteexporter/exporter.go | 6 +++++- exporter/prometheusremotewriteexporter/wal.go | 16 ++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index dc8d8d97c90..88f8a138967 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -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)) } 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()