Skip to content

Commit a7a76f6

Browse files
authored
Enhancement/5235 use disk space error to set upgrade detail in coordinator (#9392)
* enhancement(5235): added insufficinet disk space error handling in the coordinator * enhancement(5235): added coordinator tests for insufficient disk space error enhancement(5235): updated error in test enhancement(5235): fix coordinator test * enhancement(5235): added changelog fragment
1 parent 593a8b9 commit a7a76f6

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: enhancement
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: when there is a disk space error during an upgrade, agent responds with clean insufficient disk space error message
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: "elastic-agent"
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/9392
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
issue: https://github.com/elastic/elastic-agent/issues/5235

internal/pkg/agent/application/coordinator/coordinator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
3232
"github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
3333
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
34+
upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
3435
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
3536
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
3637
"github.com/elastic/elastic-agent/internal/pkg/agent/protection"
@@ -804,6 +805,15 @@ func (c *Coordinator) Upgrade(ctx context.Context, version string, sourceURI str
804805
det.SetState(details.StateCompleted)
805806
return c.upgradeMgr.AckAction(ctx, c.fleetAcker, action)
806807
}
808+
809+
c.logger.Errorw("upgrade failed", "error", logp.Error(err))
810+
// If ErrInsufficientDiskSpace is in the error chain, we want to set the
811+
// the error to ErrInsufficientDiskSpace so that the error message is
812+
// more concise and clear.
813+
if errors.Is(err, upgradeErrors.ErrInsufficientDiskSpace) {
814+
err = upgradeErrors.ErrInsufficientDiskSpace
815+
}
816+
807817
det.Fail(err)
808818
return err
809819
}

internal/pkg/agent/application/coordinator/coordinator_unit_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ import (
1515
"context"
1616
"encoding/json"
1717
"errors"
18+
"fmt"
1819
"net"
1920
"net/http"
2021
"net/http/httptest"
2122
"os"
2223
"path/filepath"
2324
"strings"
25+
"sync"
2426
"testing"
2527
"time"
2628

2729
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
30+
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker"
2831
"github.com/elastic/elastic-agent/internal/pkg/testutils"
2932

3033
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status"
@@ -41,9 +44,11 @@ import (
4144
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
4245
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring/reload"
4346
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
47+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
4448
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
4549
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
4650
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
51+
upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
4752
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
4853
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
4954
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -1977,3 +1982,100 @@ func TestHasEndpoint(t *testing.T) {
19771982
})
19781983
}
19791984
}
1985+
1986+
type mockUpgradeManager struct {
1987+
upgradeErr error
1988+
}
1989+
1990+
func (m *mockUpgradeManager) Upgradeable() bool {
1991+
return true
1992+
}
1993+
1994+
func (m *mockUpgradeManager) Reload(cfg *config.Config) error {
1995+
return nil
1996+
}
1997+
1998+
func (m *mockUpgradeManager) Upgrade(ctx context.Context, version string, rollback bool, sourceURI string, action *fleetapi.ActionUpgrade, details *details.Details, skipVerifyOverride bool, skipDefaultPgp bool, pgpBytes ...string) (_ reexec.ShutdownCallbackFn, err error) {
1999+
return nil, m.upgradeErr
2000+
}
2001+
2002+
func (m *mockUpgradeManager) Ack(ctx context.Context, acker acker.Acker) error {
2003+
return nil
2004+
}
2005+
2006+
func (m *mockUpgradeManager) AckAction(ctx context.Context, acker acker.Acker, action fleetapi.Action) error {
2007+
return nil
2008+
}
2009+
2010+
func (m *mockUpgradeManager) MarkerWatcher() upgrade.MarkerWatcher {
2011+
return nil
2012+
}
2013+
2014+
func TestCoordinator_Upgrade_InsufficientDiskSpaceError(t *testing.T) {
2015+
log, _ := loggertest.New("coordinator-insufficient-disk-space-test")
2016+
2017+
mockUpgradeManager := &mockUpgradeManager{
2018+
upgradeErr: fmt.Errorf("wrapped: %w", upgradeErrors.ErrInsufficientDiskSpace),
2019+
}
2020+
2021+
initialState := State{
2022+
CoordinatorState: agentclient.Healthy,
2023+
CoordinatorMessage: "Running",
2024+
}
2025+
2026+
coord := &Coordinator{
2027+
state: initialState,
2028+
logger: log,
2029+
upgradeMgr: mockUpgradeManager,
2030+
stateBroadcaster: broadcaster.New(initialState, 64, 32),
2031+
overrideStateChan: make(chan *coordinatorOverrideState),
2032+
upgradeDetailsChan: make(chan *details.Details),
2033+
}
2034+
2035+
wg := sync.WaitGroup{}
2036+
wg.Add(2)
2037+
2038+
overrideStates := []agentclient.State{}
2039+
go func() {
2040+
state1 := <-coord.overrideStateChan
2041+
overrideStates = append(overrideStates, state1.state)
2042+
2043+
state2 := <-coord.overrideStateChan
2044+
if state2 != nil {
2045+
overrideStates = append(overrideStates, state2.state)
2046+
}
2047+
2048+
wg.Done()
2049+
}()
2050+
2051+
upgradeDetails := []*details.Details{}
2052+
go func() {
2053+
upgradeDetails = append(upgradeDetails, <-coord.upgradeDetailsChan)
2054+
upgradeDetails = append(upgradeDetails, <-coord.upgradeDetailsChan)
2055+
wg.Done()
2056+
}()
2057+
2058+
err := coord.Upgrade(t.Context(), "", "", nil)
2059+
require.Error(t, err)
2060+
require.Equal(t, err, upgradeErrors.ErrInsufficientDiskSpace)
2061+
2062+
wg.Wait()
2063+
2064+
require.Equal(t, []agentclient.State{agentclient.Upgrading}, overrideStates)
2065+
2066+
require.Equal(t, []*details.Details{
2067+
{
2068+
TargetVersion: "",
2069+
State: details.StateRequested,
2070+
ActionID: "",
2071+
},
2072+
{
2073+
TargetVersion: "",
2074+
State: details.StateFailed,
2075+
Metadata: details.Metadata{
2076+
FailedState: details.StateRequested,
2077+
ErrorMsg: upgradeErrors.ErrInsufficientDiskSpace.Error(),
2078+
},
2079+
},
2080+
}, upgradeDetails)
2081+
}

0 commit comments

Comments
 (0)