mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-14 05:47:15 +02:00
cmd: support logging reads & writes from sshbytestream to a file.
This commit is contained in:
parent
74719ad846
commit
6f84bf665d
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/zrepl/zrepl/rpc"
|
"github.com/zrepl/zrepl/rpc"
|
||||||
"github.com/zrepl/zrepl/sshbytestream"
|
"github.com/zrepl/zrepl/sshbytestream"
|
||||||
|
. "github.com/zrepl/zrepl/util"
|
||||||
"github.com/zrepl/zrepl/zfs"
|
"github.com/zrepl/zrepl/zfs"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
"io"
|
"io"
|
||||||
@ -37,6 +38,8 @@ type SSHTransport struct {
|
|||||||
TransportOpenCommand []string `mapstructure:"transport_open_command"`
|
TransportOpenCommand []string `mapstructure:"transport_open_command"`
|
||||||
SSHCommand string `mapstructure:"ssh_command"`
|
SSHCommand string `mapstructure:"ssh_command"`
|
||||||
Options []string
|
Options []string
|
||||||
|
ConnLogReadFile string `mapstructure:"connlog_read_file"`
|
||||||
|
ConnLogWriteFile string `mapstructure:"connlog_write_file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InitialReplPolicy string
|
type InitialReplPolicy string
|
||||||
@ -393,6 +396,10 @@ func (t SSHTransport) Connect() (r rpc.RPCRequester, err error) {
|
|||||||
if stream, err = sshbytestream.Outgoing(rpcTransport); err != nil {
|
if stream, err = sshbytestream.Outgoing(rpcTransport); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
stream, err = NewReadWriteCloserLogger(stream, t.ConnLogReadFile, t.ConnLogWriteFile)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
return rpc.ConnectByteStreamRPC(stream)
|
return rpc.ConnectByteStreamRPC(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ func doRun(c *cli.Context) error {
|
|||||||
Repeats: true,
|
Repeats: true,
|
||||||
RunFunc: func(log jobrun.Logger) error {
|
RunFunc: func(log jobrun.Logger) error {
|
||||||
log.Printf("doing pull: %v", pull)
|
log.Printf("doing pull: %v", pull)
|
||||||
return doPull(pull, log)
|
return doPull(pull, c, log)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ func doRun(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func doPull(pull Pull, log jobrun.Logger) (err error) {
|
func doPull(pull Pull, c *cli.Context, log jobrun.Logger) (err error) {
|
||||||
|
|
||||||
if lt, ok := pull.From.Transport.(LocalTransport); ok {
|
if lt, ok := pull.From.Transport.(LocalTransport); ok {
|
||||||
lt.SetHandler(Handler{
|
lt.SetHandler(Handler{
|
||||||
|
40
util/io.go
40
util/io.go
@ -2,8 +2,48 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ReadWriteCloserLogger struct {
|
||||||
|
RWC io.ReadWriteCloser
|
||||||
|
ReadFile *os.File
|
||||||
|
WriteFile *os.File
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReadWriteCloserLogger(rwc io.ReadWriteCloser, readlog, writelog string) (l *ReadWriteCloserLogger, err error) {
|
||||||
|
l = &ReadWriteCloserLogger{
|
||||||
|
RWC: rwc,
|
||||||
|
}
|
||||||
|
flags := os.O_CREATE | os.O_WRONLY
|
||||||
|
if l.ReadFile, err = os.OpenFile(readlog, flags, 0600); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if l.WriteFile, err = os.OpenFile(writelog, flags, 0600); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ReadWriteCloserLogger) Read(buf []byte) (n int, err error) {
|
||||||
|
n, err = c.RWC.Read(buf)
|
||||||
|
if _, writeErr := c.ReadFile.Write(buf[0:n]); writeErr != nil {
|
||||||
|
panic(writeErr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ReadWriteCloserLogger) Write(buf []byte) (n int, err error) {
|
||||||
|
n, err = c.RWC.Write(buf)
|
||||||
|
if _, writeErr := c.WriteFile.Write(buf[0:n]); writeErr != nil {
|
||||||
|
panic(writeErr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *ReadWriteCloserLogger) Close() error {
|
||||||
|
return c.RWC.Close()
|
||||||
|
}
|
||||||
|
|
||||||
type ChainedReader struct {
|
type ChainedReader struct {
|
||||||
Readers []io.Reader
|
Readers []io.Reader
|
||||||
curReader int
|
curReader int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user