github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/m3em/agent/types.go (about) 1 // Copyright (c) 2017 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package agent 22 23 import ( 24 "io" 25 "os" 26 "time" 27 28 "github.com/m3db/m3/src/m3em/generated/proto/m3em" 29 "github.com/m3db/m3/src/m3em/os/exec" 30 xclock "github.com/m3db/m3/src/x/clock" 31 "github.com/m3db/m3/src/x/instrument" 32 ) 33 34 // Agent is the remote executor of m3em operations 35 type Agent interface { 36 io.Closer 37 m3em.OperatorServer 38 39 // Running returns a flag indicating if the test process supervised 40 // by the Agent is running. 41 Running() bool 42 } 43 44 // Options represent the knobs for a m3em agent 45 type Options interface { 46 // Validate checks if the options set are valid 47 Validate() error 48 49 // SetInstrumentOptions sets the instrument options 50 SetInstrumentOptions(instrument.Options) Options 51 52 // InstrumentOptions returns the instrument options 53 InstrumentOptions() instrument.Options 54 55 // SetWorkingDirectory sets the agent's WorkingDirectory 56 SetWorkingDirectory(string) Options 57 58 // WorkingDirectory returns the agent's WorkingDirectory 59 WorkingDirectory() string 60 61 // SetExecGenFn sets the ExecGenFn 62 SetExecGenFn(fn ExecGenFn) Options 63 64 // ExecGenFn returns the ExecGenFn 65 ExecGenFn() ExecGenFn 66 67 // SetInitHostResourcesFn sets the InitHostResourcesFn 68 SetInitHostResourcesFn(HostResourcesFn) Options 69 70 // InitHostResourcesFn returns the InitHostResourcesFn 71 InitHostResourcesFn() HostResourcesFn 72 73 // SetReleaseHostResourcesFn sets the ReleaseHostResourcesFn 74 SetReleaseHostResourcesFn(HostResourcesFn) Options 75 76 // ReleaseHostResourcesFn returns the ReleaseHostResourcesFn 77 ReleaseHostResourcesFn() HostResourcesFn 78 79 // SetEnvMap sets the EnvMap used to execute any child processes 80 SetEnvMap(exec.EnvMap) Options 81 82 // EnvMap returns the EnvMap used to execute any child processes 83 EnvMap() exec.EnvMap 84 85 // SetHeartbeatTimeout sets the duration after which failed attempts at 86 // sending heartbeats will trigger the agent to reset itself 87 SetHeartbeatTimeout(time.Duration) Options 88 89 // HeartbeatTimeout sets the duration after which failed attempts at 90 // sending heartbeats will trigger the agent to reset itself 91 HeartbeatTimeout() time.Duration 92 93 // SetNowFn sets the now fn 94 SetNowFn(xclock.NowFn) Options 95 96 // NowFn returns the now fn 97 NowFn() xclock.NowFn 98 99 // SetNewFileMode sets the new file mode 100 SetNewFileMode(value os.FileMode) Options 101 102 // NewFileMode returns the new file mode 103 NewFileMode() os.FileMode 104 105 // SetNewDirectoryMode sets the new directory mode 106 SetNewDirectoryMode(value os.FileMode) Options 107 108 // NewDirectoryMode returns the new directory mode 109 NewDirectoryMode() os.FileMode 110 } 111 112 // HostResourcesFn is used by the Agent to capture/release any resources 113 // required on the host. E.g. we use hosts that are typically running 114 // staging versions of the service being tested, for our integration tests 115 // as well. So we use this function hook to stop any running instances of 116 // said service on the host. 117 type HostResourcesFn func() error 118 119 // ExecGenFn specifies the command to execute for a given build, and config 120 // e.g. say the process binary expects the config with a cli flag "-f", 121 // ExecGenFn("binary", "config") == "binary", ["-f", "config"] 122 type ExecGenFn func(buildPath string, configPath string) (execPath string, args []string)