agent

package
v0.0.55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

README

agent

The scoring agent is a long-running process that executes service checks on behalf of the competition. It acts as the bridge between the API server and the services being monitored: it fetches work from the API, runs the corresponding check script, and reports the result back.

On startup, the agent prepends a local scripts directory (resolved relative to the working directory) to the process PATH, then spawns a configurable number of goroutines. Every goroutine runs independently in an infinite loop: sleep for the configured interval, fetch the next check assignment from the API server, run the check, and post the result back. Because goroutines share no state with each other, any number can run concurrently against the same API endpoint safely.

Each check assignment specifies a check name, a target host and team number, and optionally a set of user credentials. An assignment may instead come back flagged as a no-op, which is how the API server signals that the competition is currently paused; the goroutine logs it, runs nothing, and sleeps until its next iteration. The agent serializes the full service details to a temporary JSON file and runs the check name as a subprocess, passing the temp file path as the only argument. The subprocess timeout is determined in priority order: the service's own configured timeout if present, otherwise the loop interval if it is at least five seconds, otherwise a 30-second default. Exit code 0 is a pass; any other exit code is a fail. The subprocess's stdout and stderr are captured into separate buffers and reported as two distinct fields on the result, so consumers can present or filter the two streams independently. If the subprocess cannot be launched or fails in an unexpected way, the goroutine logs the error and skips to the next iteration without posting a result.

The package also provides a function to extract the embedded default check scripts to a local scripts/ directory. Scripts already present on disk are skipped unless overwriting is explicitly requested.

Configuration is provided via CLI flags (--api-url, --loop-time, --num-threads), corresponding environment variables with the QU_ prefix, or any combination of both via viper.

Documentation

Index

Constants

View Source
const Fail bool = false
View Source
const Pass bool = true

Variables

This section is empty.

Functions

func DumpScripts

func DumpScripts(forceOverwrite bool)

DumpScripts creates the default scripts directory in the cwd.

func Start

func Start(cfg *AgentConfig)

Start runs the agent.

Types

type AgentConfig

type AgentConfig struct {
	APIURL     string `mapstructure:"api_url"`
	LoopTime   int    `mapstructure:"loop_time"` // seconds
	NumThreads int    `mapstructure:"num_threads"`
}

AgentConfig holds the viper-loadable agent configuration. Fields map to viper keys, which in turn map to QU_<KEY> env vars and --<key> CLI flags (e.g. api_url → QU_API_URL / --api-url).

func (*AgentConfig) Loop

func (cfg *AgentConfig) Loop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL