Skip to content

Commit

Permalink
Include upgrade details in diagnostics bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Oct 18, 2023
1 parent 1e0d816 commit 9f9f29f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
26 changes: 14 additions & 12 deletions internal/pkg/agent/application/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,13 @@ func (c *Coordinator) DiagnosticHooks() diagnostics.Hooks {
State runtime.ComponentState `yaml:"state"`
}
type StateHookOutput struct {
State agentclient.State `yaml:"state"`
Message string `yaml:"message"`
FleetState agentclient.State `yaml:"fleet_state"`
FleetMessage string `yaml:"fleet_message"`
LogLevel logp.Level `yaml:"log_level"`
Components []StateComponentOutput `yaml:"components"`
State agentclient.State `yaml:"state"`
Message string `yaml:"message"`
FleetState agentclient.State `yaml:"fleet_state"`
FleetMessage string `yaml:"fleet_message"`
LogLevel logp.Level `yaml:"log_level"`
Components []StateComponentOutput `yaml:"components"`
UpgradeDetails *details.Details `yaml:"upgrade_details,omitempty"`
}

s := c.State()
Expand All @@ -799,12 +800,13 @@ func (c *Coordinator) DiagnosticHooks() diagnostics.Hooks {
}
}
output := StateHookOutput{
State: s.State,
Message: s.Message,
FleetState: s.FleetState,
FleetMessage: s.FleetMessage,
LogLevel: s.LogLevel,
Components: compStates,
State: s.State,
Message: s.Message,
FleetState: s.FleetState,
FleetMessage: s.FleetMessage,
LogLevel: s.LogLevel,
Components: compStates,
UpgradeDetails: s.UpgradeDetails,
}
o, err := yaml.Marshal(output)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/pkg/agent/application/upgrade/details/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ type Observer func(details *Details)

// Details consists of details regarding an ongoing upgrade.
type Details struct {
TargetVersion string `json:"target_version"`
State State `json:"state"`
ActionID string `json:"action_id,omitempty"`
Metadata Metadata `json:"metadata"`
TargetVersion string `json:"target_version" yaml:"target_version"`
State State `json:"state" yaml:"state"`
ActionID string `json:"action_id,omitempty" yaml:"action_id,omitempty"`
Metadata Metadata `json:"metadata" yaml:"metadata"`

observers []Observer
mu sync.Mutex
}

// Metadata consists of metadata relating to a specific upgrade state
type Metadata struct {
ScheduledAt time.Time `json:"scheduled_at,omitempty"`
DownloadPercent float64 `json:"download_percent,omitempty"`
DownloadRate float64 `json:"download_rate,omitempty"`
ScheduledAt time.Time `json:"scheduled_at,omitempty" yaml:"scheduled_at,omitempty"`
DownloadPercent float64 `json:"download_percent,omitempty" yaml:"download_percent,omitempty"`
DownloadRate float64 `json:"download_rate,omitempty" yaml:"download_rate,omitempty"`

// FailedState is the state an upgrade was in if/when it failed. Use the
// Fail() method of UpgradeDetails to correctly record details when
// an upgrade fails.
FailedState State `json:"failed_state"`
FailedState State `json:"failed_state" yaml:"failed_state,omitempty"`

// ErrorMsg is any error message encountered if/when an upgrade fails. Use
// the Fail() method of UpgradeDetails to correctly record details when
// an upgrade fails.
ErrorMsg string `json:"error_msg"`
ErrorMsg string `json:"error_msg" yaml:"error_msg,omitempty"`
}

func NewDetails(targetVersion string, initialState State, actionID string) *Details {
Expand Down

0 comments on commit 9f9f29f

Please sign in to comment.