From ac3cedb108c93ffc1b536ef282443559d29b11c8 Mon Sep 17 00:00:00 2001 From: johncming Date: Sat, 24 Aug 2019 09:39:15 +0800 Subject: [PATCH] promql: Modify the order of return values. (#5940) Signed-off-by: johncming --- promql/query_logger.go | 12 ++++++------ promql/query_logger_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/promql/query_logger.go b/promql/query_logger.go index 3d30062d6..256c3d775 100644 --- a/promql/query_logger.go +++ b/promql/query_logger.go @@ -76,27 +76,27 @@ func logUnfinishedQueries(filename string, filesize int, logger log.Logger) { } } -func getMMapedFile(filename string, filesize int, logger log.Logger) (error, []byte) { +func getMMapedFile(filename string, filesize int, logger log.Logger) ([]byte, error) { file, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644) if err != nil { level.Error(logger).Log("msg", "Error opening query log file", "file", filename, "err", err) - return err, []byte{} + return nil, err } err = file.Truncate(int64(filesize)) if err != nil { level.Error(logger).Log("msg", "Error setting filesize.", "filesize", filesize, "err", err) - return err, []byte{} + return nil, err } fileAsBytes, err := mmap.Map(file, mmap.RDWR, 0) if err != nil { level.Error(logger).Log("msg", "Failed to mmap", "file", filename, "Attempted size", filesize, "err", err) - return err, []byte{} + return nil, err } - return err, fileAsBytes + return fileAsBytes, err } func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.Logger) *ActiveQueryTracker { @@ -108,7 +108,7 @@ func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.L filename, filesize := filepath.Join(localStoragePath, "queries.active"), 1+maxQueries*entrySize logUnfinishedQueries(filename, filesize, logger) - err, fileAsBytes := getMMapedFile(filename, filesize, logger) + fileAsBytes, err := getMMapedFile(filename, filesize, logger) if err != nil { panic("Unable to create mmap-ed active query log") } diff --git a/promql/query_logger_test.go b/promql/query_logger_test.go index cc3743244..27e5b6644 100644 --- a/promql/query_logger_test.go +++ b/promql/query_logger_test.go @@ -113,7 +113,7 @@ func TestMMapFile(t *testing.T) { filename := file.Name() defer os.Remove(filename) - err, fileAsBytes := getMMapedFile(filename, 2, nil) + fileAsBytes, err := getMMapedFile(filename, 2, nil) if err != nil { t.Fatalf("Couldn't create test mmaped file")