Fix open "/tmp/*" the system cannot find the path specified on windows (#8170)

Instead of hard-coding `/tmp` directory, use the OS default directory for temporary files
pull/8421/head
Etran-H 3 years ago committed by GitHub
parent c5725e4cae
commit 5447541e2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      clients/cmd/docker-driver/config_test.go
  2. 3
      clients/cmd/fluent-bit/dque.go
  3. 10
      clients/pkg/promtail/positions/positions_test.go
  4. 26
      clients/pkg/promtail/promtail_test.go
  5. 15
      clients/pkg/promtail/targets/journal/journaltarget_test.go
  6. 2
      pkg/storage/stores/indexshipper/compactor/retention/marker.go

@ -81,7 +81,7 @@ var pipeline = PipelineConfig{
}
func Test_parsePipeline(t *testing.T) {
f, err := os.CreateTemp("/tmp", "Test_parsePipeline")
f, err := os.CreateTemp("", "Test_parsePipeline")
if err != nil {
t.Fatal(err)
}

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
"sync"
"time"
@ -25,7 +26,7 @@ type dqueConfig struct {
}
var defaultDqueConfig = dqueConfig{
queueDir: "/tmp/flb-storage/loki",
queueDir: filepath.Join(os.TempDir(), "flb-storage/loki"),
queueSegmentSize: 500,
queueSync: false,
queueName: "dque",

@ -40,7 +40,7 @@ func TestReadPositionsOK(t *testing.T) {
}()
yaml := []byte(`positions:
/tmp/random.log: "17623"
/log/path/random.log: "17623"
`)
err := os.WriteFile(temp, yaml, 0644)
if err != nil {
@ -52,7 +52,7 @@ func TestReadPositionsOK(t *testing.T) {
}, log.NewNopLogger())
require.NoError(t, err)
require.Equal(t, "17623", pos["/tmp/random.log"])
require.Equal(t, "17623", pos["/log/path/random.log"])
}
func TestReadPositionsEmptyFile(t *testing.T) {
@ -145,7 +145,7 @@ func Test_ReadOnly(t *testing.T) {
_ = os.Remove(temp)
}()
yaml := []byte(`positions:
/tmp/random.log: "17623"
/log/path/random.log: "17623"
`)
err := os.WriteFile(temp, yaml, 0644)
if err != nil {
@ -162,7 +162,7 @@ func Test_ReadOnly(t *testing.T) {
defer p.Stop()
p.Put("/foo/bar/f", 12132132)
p.PutString("/foo/f", "100")
pos, err := p.Get("/tmp/random.log")
pos, err := p.Get("/log/path/random.log")
if err != nil {
t.Fatal(err)
}
@ -176,7 +176,7 @@ func Test_ReadOnly(t *testing.T) {
require.NoError(t, err)
require.Equal(t, map[string]string{
"/tmp/random.log": "17623",
"/log/path/random.log": "17623",
}, out)
}

@ -5,7 +5,6 @@ import (
"fmt"
"io"
"math"
"math/rand"
"net"
"net/http"
"net/url"
@ -39,6 +38,7 @@ import (
"github.com/grafana/loki/clients/pkg/promtail/server"
pserver "github.com/grafana/loki/clients/pkg/promtail/server"
file2 "github.com/grafana/loki/clients/pkg/promtail/targets/file"
"github.com/grafana/loki/clients/pkg/promtail/targets/testutils"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/util"
@ -54,8 +54,8 @@ func TestPromtail(t *testing.T) {
logger = level.NewFilter(logger, level.AllowInfo())
util_log.Logger = logger
initRandom()
dirName := "/tmp/promtail_test_" + randName()
testutils.InitRandom()
dirName := filepath.Join(os.TempDir(), "/promtail_test_"+testutils.RandName())
positionsFileName := dirName + "/positions.yml"
err := os.MkdirAll(dirName, 0o750)
@ -641,22 +641,8 @@ func buildTestConfig(t *testing.T, positionsFileName string, logDirName string)
return cfg
}
func initRandom() {
rand.Seed(time.Now().UnixNano())
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randName() string {
b := make([]rune, 10)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
func Test_DryRun(t *testing.T) {
f, err := os.CreateTemp("/tmp", "Test_DryRun")
f, err := os.CreateTemp("", "Test_DryRun")
require.NoError(t, err)
defer os.Remove(f.Name())
@ -701,7 +687,7 @@ func Test_DryRun(t *testing.T) {
}
func Test_Reload(t *testing.T) {
f, err := os.CreateTemp("/tmp", "Test_Reload")
f, err := os.CreateTemp("", "Test_Reload")
require.NoError(t, err)
defer os.Remove(f.Name())
@ -770,7 +756,7 @@ func Test_Reload(t *testing.T) {
}
func Test_ReloadFail_NotPanic(t *testing.T) {
f, err := os.CreateTemp("/tmp", "Test_Reload")
f, err := os.CreateTemp("", "Test_Reload")
require.NoError(t, err)
defer os.Remove(f.Name())

@ -6,6 +6,7 @@ package journal
import (
"io"
"os"
"path/filepath"
"strings"
"testing"
"time"
@ -70,7 +71,7 @@ func TestJournalTarget(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer
@ -132,7 +133,7 @@ func TestJournalTargetParsingErrors(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer
@ -200,7 +201,7 @@ func TestJournalTarget_JSON(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer
@ -260,7 +261,7 @@ func TestJournalTarget_Since(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer
@ -294,7 +295,7 @@ func TestJournalTarget_Cursor_TooOld(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer
@ -334,7 +335,7 @@ func TestJournalTarget_Cursor_NotTooOld(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer
@ -391,7 +392,7 @@ func TestJournalTarget_Matches(t *testing.T) {
logger := log.NewLogfmtLogger(w)
testutils.InitRandom()
dirName := "/tmp/" + testutils.RandName()
dirName := filepath.Join(os.TempDir(), testutils.RandName())
positionsFileName := dirName + "/positions.yml"
// Set the sync period to a really long value, to guarantee the sync timer

@ -252,7 +252,7 @@ func (r *markerProcessor) processPath(path string, deleteFunc func(ctx context.C
queue = make(chan *keyPair)
)
// we use a copy to view the file so that we can read and update at the same time.
viewFile, err := os.CreateTemp("/tmp/", "marker-view-")
viewFile, err := os.CreateTemp("", "marker-view-")
if err != nil {
return err
}

Loading…
Cancel
Save