mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Add historical journald and log export flags to operator debug command (#26410)
* Add -log-file-export and -log-lookback commands to add historical log to debug capture * use monitor.PrepFile() helper for other historical log tests
This commit is contained in:
@@ -100,14 +100,7 @@ func TestMonitor_Export(t *testing.T) {
|
||||
expectedText = "log log log log log"
|
||||
)
|
||||
|
||||
dir := t.TempDir()
|
||||
f, err := os.CreateTemp(dir, "log")
|
||||
must.NoError(t, err)
|
||||
for range 1000 {
|
||||
_, _ = f.WriteString(fmt.Sprintf("%v [INFO] it's log, it's log, it's big it's heavy it's wood", time.Now()))
|
||||
}
|
||||
f.Close()
|
||||
goldenFilePath := f.Name()
|
||||
goldenFilePath := PrepFile(t).Name()
|
||||
goldenFileContents, err := os.ReadFile(goldenFilePath)
|
||||
must.NoError(t, err)
|
||||
|
||||
|
||||
@@ -17,27 +17,6 @@ import (
|
||||
"github.com/shoenig/test/must"
|
||||
)
|
||||
|
||||
var writeLine = []byte("[INFO] log log log made of wood you are heavy but so good\n")
|
||||
|
||||
func prepFile(t *testing.T) *os.File {
|
||||
const loopCount = 10
|
||||
// Create test file to read from
|
||||
dir := t.TempDir()
|
||||
f, err := os.CreateTemp(dir, "log")
|
||||
must.NoError(t, err)
|
||||
|
||||
for range loopCount {
|
||||
_, _ = f.Write(writeLine)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
// Create test file reader for stream set up
|
||||
goldenFilePath := f.Name()
|
||||
fileReader, err := os.Open(goldenFilePath)
|
||||
must.NoError(t, err)
|
||||
return fileReader
|
||||
}
|
||||
|
||||
func TestClientStreamReader_StreamFixed(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
|
||||
@@ -80,7 +59,7 @@ func TestClientStreamReader_StreamFixed(t *testing.T) {
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
file := prepFile(t)
|
||||
file := PrepFile(t)
|
||||
goldenFileContents, err := os.ReadFile(file.Name())
|
||||
must.NoError(t, err)
|
||||
|
||||
|
||||
@@ -6,15 +6,19 @@ package monitor
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-msgpack/v2/codec"
|
||||
sframer "github.com/hashicorp/nomad/client/lib/streamframer"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/shoenig/test/must"
|
||||
)
|
||||
|
||||
// StreamingClient is an interface that implements the StreamingRpcHandler function
|
||||
@@ -22,6 +26,27 @@ type StreamingClient interface {
|
||||
StreamingRpcHandler(string) (structs.StreamingRpcHandler, error)
|
||||
}
|
||||
|
||||
var writeLine = []byte(fmt.Sprintf("[INFO] log log log made of wood you are heavy but so good, %v\n", time.Now()))
|
||||
|
||||
func PrepFile(t *testing.T) *os.File {
|
||||
const loopCount = 100
|
||||
// Create test file to read from
|
||||
dir := t.TempDir()
|
||||
f, err := os.CreateTemp(dir, "log")
|
||||
must.NoError(t, err)
|
||||
|
||||
for range loopCount {
|
||||
_, _ = f.Write(writeLine)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
// Create test file reader for stream set up
|
||||
goldenFilePath := f.Name()
|
||||
fileReader, err := os.Open(goldenFilePath)
|
||||
must.NoError(t, err)
|
||||
return fileReader
|
||||
}
|
||||
|
||||
// ExportMonitorClient_TestHelper consolidates streaming test setup for use in
|
||||
// client and server RPChandler tests
|
||||
func ExportMonitorClient_TestHelper(req cstructs.MonitorExportRequest, c StreamingClient,
|
||||
|
||||
Reference in New Issue
Block a user