Documentation
¶
Index ¶
- type Agent
- func (a *Agent) CheckAvailable() error
- func (a *Agent) Cleanup() (err error)
- func (a *Agent) CopyIncludes() (err error)
- func (a *Agent) CreateTemp() error
- func (a *Agent) DryRun() []error
- func (a *Agent) RecordManifest()
- func (a *Agent) ResultsDest() string
- func (a *Agent) Run() []error
- func (a *Agent) RunProducts() error
- func (a *Agent) Setup() error
- func (a *Agent) TempDir() string
- func (a *Agent) WriteOutput() (err error)
- type Config
- type Environment
- type ManifestOp
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 NewAgentWithContext ¶ added in v0.5.0
NewAgentWithContext produces a new Agent that includes a custom context.Context, initialized for subsequent running.
func (*Agent) CheckAvailable ¶
CheckAvailable runs healthchecks for each enabled product
func (*Agent) Cleanup ¶
Cleanup removes the temporary directory and its contents, returning an error if it is unable to do so.
func (*Agent) CopyIncludes ¶
CopyIncludes copies user-specified files over to our tempdir.
func (*Agent) CreateTemp ¶
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
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.