agent

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Start    time.Time       `json:"started_at"`
	End      time.Time       `json:"ended_at"`
	Duration string          `json:"duration"`
	NumOps   int             `json:"num_ops"`
	Config   Config          `json:"configuration"`
	Version  version.Version `json:"version"`
	// ManifestOps holds a slice of ops with a subset of fields so we can safely render them in `manifest.json`
	ManifestOps map[string][]ManifestOp `json:"ops"`
	// Agent-level redactions are passed through to all products
	Redactions []*redact.Redact `json:"redactions"`
	// Environment describes details about the process that constructed the agent
	Environment Environment `json:"environment"`
	// contains filtered or unexported fields
}

Agent stores the runtime state that we use throughout the Agent's lifecycle.

func NewAgent

func NewAgent(config Config, logger hclog.Logger) (*Agent, error)

NewAgent produces a new Agent, initialized for subsequent running.

func NewAgentWithContext added in v0.5.0

func NewAgentWithContext(ctx context.Context, config Config, logger hclog.Logger) (*Agent, error)

NewAgentWithContext produces a new Agent that includes a custom context.Context, initialized for subsequent running.

func (*Agent) CheckAvailable

func (a *Agent) CheckAvailable() error

CheckAvailable runs healthchecks for each enabled product

func (*Agent) Cleanup

func (a *Agent) Cleanup() (err error)

Cleanup removes the temporary directory and its contents, returning an error if it is unable to do so.

func (*Agent) CopyIncludes

func (a *Agent) CopyIncludes() (err error)

CopyIncludes copies user-specified files over to our tempdir.

func (*Agent) CreateTemp

func (a *Agent) CreateTemp() error

CreateTemp Creates a temporary directory so that we may gather results and files before compressing the final artifact.

func (*Agent) DryRun added in v0.3.1

func (a *Agent) DryRun() []error

DryRun runs the agent to log what would occur during a run, without issuing any commands or writing to disk.

func (*Agent) RecordManifest added in v0.3.0

func (a *Agent) RecordManifest()

RecordManifest writes additional data to the agent to serialize into manifest.json

func (*Agent) ResultsDest added in v0.5.0

func (a *Agent) ResultsDest() string

ResultsDest is provided for read-only access to the destination where the agent writes its results. The particular destination is determined by the agent while running; it is unexported to avoid accidental overwrite by external packages. However, its value is useful to know for downstream user interaction, so this method intends to provide that ability.

func (*Agent) Run

func (a *Agent) Run() []error

Run manages the Agent's lifecycle. We create our temp directory, copy files, run their ops, write the results, and finally cleanup after ourselves. We collect any errors up and return them to the caller, only returning when done or if the error warrants ending the run early.

func (*Agent) RunProducts

func (a *Agent) RunProducts() error

RunProducts executes all ops for this run. TODO(mkcp): We can avoid locking and waiting on results if all results are generated async. Then they can get streamed back to the dispatcher and merged into either a sync.Map or a purpose-built results map with insert(), read(), and merge().

func (*Agent) Setup

func (a *Agent) Setup() error

Setup instantiates each enabled product for the run. We compose product-specific configuration with the shared config that each product needs to build its runners.

func (*Agent) TempDir

func (a *Agent) TempDir() string

TempDir returns "hcdiag-" and an ISO 8601-formatted timestamp for temporary directory and tar file names. e.g. "hcdiag-2021-11-22T223938Z"

func (*Agent) WriteOutput

func (a *Agent) WriteOutput() (err error)

WriteOutput renders the manifest and results of the diagnostics run and writes the compressed archive.

type Config

type Config struct {
	// HCL stores configuration we receive from the custom config.
	HCL         hcl.HCL   `json:"hcl"`
	OS          string    `json:"operating_system"`
	Serial      bool      `json:"serial"`
	Dryrun      bool      `json:"dry_run"`
	Consul      bool      `json:"consul_enabled"`
	Nomad       bool      `json:"nomad_enabled"`
	TFE         bool      `json:"terraform_ent_enabled"`
	Vault       bool      `json:"vault_enabled"`
	Since       time.Time `json:"since"`
	Until       time.Time `json:"until"`
	Includes    []string  `json:"includes"`
	Destination string    `json:"destination"`

	// DebugDuration
	DebugDuration time.Duration `json:"debug_duration"`
	// DebugInterval
	DebugInterval time.Duration `json:"debug_interval"`
	// We omit this from JSON to avoid duplicates in manifest.json; it is copied and serialized in Agent instead.
	Environment Environment `json:"-"`
}

Config stores user input from the CLI and an HCL file.

type Environment added in v0.5.0

type Environment struct {
	// Command is the CLI command entered to execute a Run.
	Command string `json:"command"`
	// Username is the username of the process that started a Run.
	Username string `json:"username"`
	// Hostname is the hostname of the machine where the Run was executed.
	Hostname string `json:"hostname"`
}

Environment describes runtime details about the execution environment of the Agent.

type ManifestOp added in v0.4.0

type ManifestOp struct {
	ID       string    `json:"op"`
	Error    string    `json:"error"`
	Status   op.Status `json:"status"`
	Duration string    `json:"duration"`
}

ManifestOp provides a subset of op state, specifically excluding results, so we can safely render metadata about ops without exposing customer info in manifest.json

func WalkResultsForManifest added in v0.5.0

func WalkResultsForManifest(results map[string]op.Op) []ManifestOp

WalkResultsForManifest translates maps of arbitrarily deeply nested op.Ops and flattens them into a slice of ManifestOp. In the case of nested runners, such as in Do or Seq blocks, outer Op will contain results for all the inner runners. This function allows for reporting on the total number of Ops rather than just the outer Op.

Jump to

Keyboard shortcuts

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