Skip to content

Commit 219ea59

Browse files
[8.19] (backport #9392) Enhancement/5235 use disk space error to set upgrade detail in coordinator (#10055)
* 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 (cherry picked from commit a7a76f6) # Conflicts: # internal/pkg/agent/application/coordinator/coordinator_unit_test.go * resolved merge conflicts --------- Co-authored-by: Kaan Yalti <[email protected]>
1 parent cde47ae commit 219ea59

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-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
@@ -27,6 +27,7 @@ import (
2727
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
2828
"github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
2929
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
30+
upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
3031
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
3132
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
3233
"github.com/elastic/elastic-agent/internal/pkg/agent/transpiler"
@@ -684,6 +685,15 @@ func (c *Coordinator) Upgrade(ctx context.Context, version string, sourceURI str
684685
det.SetState(details.StateCompleted)
685686
return c.upgradeMgr.AckAction(ctx, c.fleetAcker, action)
686687
}
688+
689+
c.logger.Errorw("upgrade failed", "error", logp.Error(err))
690+
// If ErrInsufficientDiskSpace is in the error chain, we want to set the
691+
// the error to ErrInsufficientDiskSpace so that the error message is
692+
// more concise and clear.
693+
if errors.Is(err, upgradeErrors.ErrInsufficientDiskSpace) {
694+
err = upgradeErrors.ErrInsufficientDiskSpace
695+
}
696+
687697
det.Fail(err)
688698
return err
689699
}

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ package coordinator
1313
import (
1414
"context"
1515
"errors"
16+
"fmt"
1617
"net"
18+
"sync"
1719
"testing"
1820
"time"
1921

2022
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
23+
"github.com/elastic/elastic-agent/internal/pkg/fleetapi"
24+
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker"
2125

2226
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status"
2327
"go.opentelemetry.io/collector/component/componentstatus"
@@ -30,8 +34,10 @@ import (
3034
"github.com/elastic/elastic-agent-libs/logp"
3135
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
3236
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring/reload"
37+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
3338
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
3439
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
40+
upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
3541
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
3642
"github.com/elastic/elastic-agent/internal/pkg/agent/transpiler"
3743
"github.com/elastic/elastic-agent/internal/pkg/config"
@@ -1569,3 +1575,100 @@ func (fs *fakeMonitoringServer) Reset() {
15691575
func (fs *fakeMonitoringServer) Addr() net.Addr {
15701576
return nil
15711577
}
1578+
1579+
type mockUpgradeManager struct {
1580+
upgradeErr error
1581+
}
1582+
1583+
func (m *mockUpgradeManager) Upgradeable() bool {
1584+
return true
1585+
}
1586+
1587+
func (m *mockUpgradeManager) Reload(cfg *config.Config) error {
1588+
return nil
1589+
}
1590+
1591+
func (m *mockUpgradeManager) Upgrade(ctx context.Context, version string, sourceURI string, action *fleetapi.ActionUpgrade, details *details.Details, skipVerifyOverride bool, skipDefaultPgp bool, pgpBytes ...string) (_ reexec.ShutdownCallbackFn, err error) {
1592+
return nil, m.upgradeErr
1593+
}
1594+
1595+
func (m *mockUpgradeManager) Ack(ctx context.Context, acker acker.Acker) error {
1596+
return nil
1597+
}
1598+
1599+
func (m *mockUpgradeManager) AckAction(ctx context.Context, acker acker.Acker, action fleetapi.Action) error {
1600+
return nil
1601+
}
1602+
1603+
func (m *mockUpgradeManager) MarkerWatcher() upgrade.MarkerWatcher {
1604+
return nil
1605+
}
1606+
1607+
func TestCoordinator_Upgrade_InsufficientDiskSpaceError(t *testing.T) {
1608+
log, _ := loggertest.New("coordinator-insufficient-disk-space-test")
1609+
1610+
mockUpgradeManager := &mockUpgradeManager{
1611+
upgradeErr: fmt.Errorf("wrapped: %w", upgradeErrors.ErrInsufficientDiskSpace),
1612+
}
1613+
1614+
initialState := State{
1615+
CoordinatorState: agentclient.Healthy,
1616+
CoordinatorMessage: "Running",
1617+
}
1618+
1619+
coord := &Coordinator{
1620+
state: initialState,
1621+
logger: log,
1622+
upgradeMgr: mockUpgradeManager,
1623+
stateBroadcaster: broadcaster.New(initialState, 64, 32),
1624+
overrideStateChan: make(chan *coordinatorOverrideState),
1625+
upgradeDetailsChan: make(chan *details.Details),
1626+
}
1627+
1628+
wg := sync.WaitGroup{}
1629+
wg.Add(2)
1630+
1631+
overrideStates := []agentclient.State{}
1632+
go func() {
1633+
state1 := <-coord.overrideStateChan
1634+
overrideStates = append(overrideStates, state1.state)
1635+
1636+
state2 := <-coord.overrideStateChan
1637+
if state2 != nil {
1638+
overrideStates = append(overrideStates, state2.state)
1639+
}
1640+
1641+
wg.Done()
1642+
}()
1643+
1644+
upgradeDetails := []*details.Details{}
1645+
go func() {
1646+
upgradeDetails = append(upgradeDetails, <-coord.upgradeDetailsChan)
1647+
upgradeDetails = append(upgradeDetails, <-coord.upgradeDetailsChan)
1648+
wg.Done()
1649+
}()
1650+
1651+
err := coord.Upgrade(t.Context(), "", "", nil)
1652+
require.Error(t, err)
1653+
require.Equal(t, err, upgradeErrors.ErrInsufficientDiskSpace)
1654+
1655+
wg.Wait()
1656+
1657+
require.Equal(t, []agentclient.State{agentclient.Upgrading}, overrideStates)
1658+
1659+
require.Equal(t, []*details.Details{
1660+
{
1661+
TargetVersion: "",
1662+
State: details.StateRequested,
1663+
ActionID: "",
1664+
},
1665+
{
1666+
TargetVersion: "",
1667+
State: details.StateFailed,
1668+
Metadata: details.Metadata{
1669+
FailedState: details.StateRequested,
1670+
ErrorMsg: upgradeErrors.ErrInsufficientDiskSpace.Error(),
1671+
},
1672+
},
1673+
}, upgradeDetails)
1674+
}

0 commit comments

Comments
 (0)