From 09093a1a1aaa15893b71767b689989ee3613457f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 2 May 2018 20:34:23 -0700 Subject: [PATCH] agent/proxy: change LogDir to DataDir to reuse for other things --- agent/proxy/manager.go | 28 +++++++++++++++++++--------- agent/proxy/manager_test.go | 12 +++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/agent/proxy/manager.go b/agent/proxy/manager.go index bc2a8e728..7ed278037 100644 --- a/agent/proxy/manager.go +++ b/agent/proxy/manager.go @@ -54,11 +54,19 @@ type Manager struct { // implementation type. Logger *log.Logger - // LogDir is the path to the directory where logs will be written - // for daemon mode proxies. This directory will be created if it does - // not exist. If this is empty then logs will be dumped into the - // working directory. - LogDir string + // DataDir is the path to the directory where data for proxies is + // written, including snapshots for any state changes in the manager. + // Within the data dir, files will be written in the following locatins: + // + // * logs/ - log files named -std{out|err}.log + // * pids/ - pid files for daemons named .pid + // * state.ext - the state of the manager + // + DataDir string + + // SnapshotDir is the path to the directory where snapshots will + // be written + SnapshotDir string // CoalescePeriod and QuiescencePeriod control the timers for coalescing // updates from the local state. See the defaults at the top of this @@ -370,15 +378,17 @@ func (m *Manager) newProxy(mp *local.ManagedProxy) (Proxy, error) { // they log to the proper file path for the given service ID. func (m *Manager) configureLogDir(id string, cmd *exec.Cmd) error { // Create the log directory - if m.LogDir != "" { - if err := os.MkdirAll(m.LogDir, 0700); err != nil { + logDir := "" + if m.DataDir != "" { + logDir = filepath.Join(m.DataDir, "logs") + if err := os.MkdirAll(logDir, 0700); err != nil { return err } } // Configure the stdout, stderr paths - stdoutPath := logPath(m.LogDir, id, "stdout") - stderrPath := logPath(m.LogDir, id, "stderr") + stdoutPath := logPath(logDir, id, "stdout") + stderrPath := logPath(logDir, id, "stderr") // Open the files. We want to append to each. We expect these files // to be rotated by some external process. diff --git a/agent/proxy/manager_test.go b/agent/proxy/manager_test.go index 3bf200805..d14b71afa 100644 --- a/agent/proxy/manager_test.go +++ b/agent/proxy/manager_test.go @@ -198,15 +198,13 @@ func TestManagerRun_daemonLogs(t *testing.T) { defer m.Kill() // Configure a log dir so that we can read the logs - td, closer := testTempDir(t) - defer closer() - m.LogDir = filepath.Join(td, "logs") + logDir := filepath.Join(m.DataDir, "logs") // Create the service and calculate the log paths - path := filepath.Join(td, "notify") + path := filepath.Join(m.DataDir, "notify") id := testStateProxy(t, state, "web", helperProcess("output", path)) - stdoutPath := logPath(m.LogDir, id, "stdout") - stderrPath := logPath(m.LogDir, id, "stderr") + stdoutPath := logPath(logDir, id, "stdout") + stderrPath := logPath(logDir, id, "stderr") // Start the manager go m.Run() @@ -238,7 +236,7 @@ func testManager(t *testing.T) (*Manager, func()) { // Setup a temporary directory for logs td, closer := testTempDir(t) - m.LogDir = td + m.DataDir = td return m, func() { closer() } }