Documentation ¶
Index ¶
- func AllowedEnvironment(envs []string) []string
- func ExitStatus(err error) (int, bool)
- type Command
- type Option
- func WithCgroup(cgroupsManager cgroups.Manager, opts ...cgroups.AddCommandOption) Option
- func WithCommandGitVersion(gitCmdVersion string) Option
- func WithCommandName(commandName, subcommandName string) Option
- func WithDir(dir string) Option
- func WithEnvironment(environment []string) Option
- func WithFinalizer(finalizer func(context.Context, *Command)) Option
- func WithSetupStdin() Option
- func WithSetupStdout() Option
- func WithSpawnTokenManager(spawnTokenManager *SpawnTokenManager) Option
- func WithStderr(stderr io.Writer) Option
- func WithStdin(stdin io.Reader) Option
- func WithStdout(stdout io.Writer) Option
- type SpawnConfig
- type SpawnTokenManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowedEnvironment ¶
AllowedEnvironment filters the given slice of environment variables and returns all variables which are allowed per the variables defined above. This is useful for constructing a base environment in which a command can be run.
func ExitStatus ¶
ExitStatus will return the exit-code from an error returned by Wait().
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command encapsulates a running exec.Cmd. The embedded exec.Cmd is terminated and reaped automatically when the context.Context that created it is canceled.
func New ¶
New creates a Command from the given executable name and arguments On success, the Command contains a running subprocess. When ctx is canceled the embedded process will be terminated and reaped automatically.
func (*Command) Wait ¶
Wait calls Wait() on the exec.Cmd instance inside the command. This blocks until the command has finished and reports the command exit status via the error return value. Use ExitStatus to get the integer exit status from the error returned by Wait().
Wait returns a wrapped context error if the process was reaped due to the context being done.
type Option ¶
type Option func(cfg *config)
Option is an option that can be passed to `New()` for controlling how the command is being created.
func WithCgroup ¶
func WithCgroup(cgroupsManager cgroups.Manager, opts ...cgroups.AddCommandOption) Option
WithCgroup adds the spawned command to a Cgroup. The bucket used will be derived from the command's arguments and/or from the repository.
func WithCommandGitVersion ¶
WithCommandGitVersion overrides the "git_version" label used in metrics.
func WithCommandName ¶
WithCommandName overrides the "cmd" and "subcmd" label used in metrics.
func WithEnvironment ¶
WithEnvironment sets up environment variables that shall be set for the command.
func WithFinalizer ¶
WithFinalizer sets up the finalizer to be run when the command is being wrapped up. It will be called after `Wait()` has returned.
func WithSetupStdin ¶
func WithSetupStdin() Option
WithSetupStdin instructs New() to configure the stdin pipe of the command it is creating. This allows you call Write() on the command as if it is an ordinary io.Writer, sending data directly to the stdin of the process.
func WithSetupStdout ¶ added in v16.4.0
func WithSetupStdout() Option
WithSetupStdout instructs New() to configure the standard output pipe of the command it is creating. This allowsyou to call Read() on the command as if it is an ordinary io.Reader, reading output directly from the stdout of the process.
func WithSpawnTokenManager ¶ added in v16.2.0
func WithSpawnTokenManager(spawnTokenManager *SpawnTokenManager) Option
WithSpawnTokenManager assigns a spawn token manager for the command. If this option is not set, the command uses the process-global spawn token manager.
func WithStderr ¶
WithStderr sets up the command to write standard error to the given writer.
func WithStdout ¶
WithStdout sets up the command to write standard output to the given writer.
type SpawnConfig ¶
type SpawnConfig struct { // This default value (10 seconds) is very high. Spawning should take // milliseconds or less. If we hit 10 seconds, something is wrong, and // failing the request will create breathing room. Timeout time.Duration `split_words:"true" default:"10s"` // MaxSpawnParallel limits the number of goroutines that can spawn a // process at the same time. These parallel spawns will contend for a // single lock (syscall.ForkLock) in exec.Cmd.Start(). Can be modified at // runtime with the GITALY_COMMAND_SPAWN_MAX_PARALLEL variable. // // Note that this does not limit the total number of child processes that // can be attached to Gitaly at the same time. It only limits the rate at // which we can create new child processes. MaxParallel int `split_words:"true" default:"10"` }
SpawnConfig holds configuration for command spawning timeouts and parallelism.
type SpawnTokenManager ¶ added in v16.2.0
type SpawnTokenManager struct {
// contains filtered or unexported fields
}
SpawnTokenManager limits the number of goroutines that can spawn a process at a time.
func NewSpawnTokenManager ¶ added in v16.2.0
func NewSpawnTokenManager(config SpawnConfig) *SpawnTokenManager
NewSpawnTokenManager creates a SpawnTokenManager object from the input config
func NewSpawnTokenManagerFromEnv ¶ added in v16.2.0
func NewSpawnTokenManagerFromEnv() (*SpawnTokenManager, error)
NewSpawnTokenManagerFromEnv creates a SpawnTokenManager object with the config parsed from environment variables - GITALY_COMMAND_SPAWN_TIMEOUT for spawn token `Timeout` config - GITALY_COMMAND_SPAWN_MAX_PARALLEL for spawn token `MaxParallel` config
func (*SpawnTokenManager) Collect ¶ added in v16.2.0
func (m *SpawnTokenManager) Collect(metrics chan<- prometheus.Metric)
Collect is used to collect Prometheus metrics.
func (*SpawnTokenManager) Describe ¶ added in v16.2.0
func (m *SpawnTokenManager) Describe(descs chan<- *prometheus.Desc)
Describe is used to describe Prometheus metrics.
func (*SpawnTokenManager) GetSpawnToken ¶ added in v16.2.0
func (m *SpawnTokenManager) GetSpawnToken(ctx context.Context) (putToken func(), err error)
GetSpawnToken blocks until the caller either acquires a token or timeout. The caller is expected to call returned function to put the token back to the queue.