forked from elastic/elastic-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Upgrade Details] Ensure details report
UPG_WATCHING
for the entire…
… time that the upgrade is being watched (elastic#3827) * Don't set upgrade details when creating upgrade marker * Set UPG_WATCHING state right before starting to watch upgrade * Log upgrade details whenever they're set on the coordinator * Fix logging location * Revert "Don't set upgrade details when creating upgrade marker" This reverts commit 6821832. * Fix logic with assuming UPG_ROLLBACK state * Add FIXME * Correctly observe upgrade details changes * Update unit test * Include upgrade details in status output * Check upgrade details state before and after upgrade watcher starts * Check that upgrade details have been cleared out upon successful upgrade * Update unit test * Fixing up upgrade integration tests * Add unit test + fix details object being used * Define AgentStatusOutput.IsZero() and use it * Make sure Marker Watcher accounts for `UPG_COMPLETED` state * Fix location of assertion * Fix error message * Join errors for wrapping * Debugging why TestStandaloneDowngradeToSpecificSnapshotBuild is failing * Cast string to details.State * Remove version override debugging * Wrap bugfix assertions in version checks * Introduce upgradetest.WithDisableUpgradeWatcherUpgradeDetailsCheck option * Call option function * Debugging * Fixing version check logic * Remove debugging statements
- Loading branch information
1 parent
cc81e4b
commit ad7e1b5
Showing
11 changed files
with
257 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details" | ||
"github.com/elastic/elastic-agent/internal/pkg/agent/errors" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/fleetapi" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/elastic-agent/pkg/core/logger" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade" | ||
) | ||
|
||
func TestInitUpgradeDetails(t *testing.T) { | ||
testMarker := &upgrade.UpdateMarker{ | ||
Action: &fleetapi.ActionUpgrade{ | ||
ActionID: "foobar", | ||
}, | ||
} | ||
|
||
saveCount := 0 | ||
mockSaveMarker := func(marker *upgrade.UpdateMarker, _ bool) error { | ||
saveCount++ | ||
if saveCount <= 3 { | ||
testMarker = marker | ||
return nil | ||
} | ||
return errors.New("some error") | ||
} | ||
|
||
log, obs := logger.NewTesting("initUpgradeDetails") | ||
|
||
upgradeDetails := initUpgradeDetails(testMarker, mockSaveMarker, log) | ||
|
||
// Verify initial state | ||
require.NotNil(t, testMarker.Details) | ||
require.Equal(t, details.StateWatching, testMarker.Details.State) | ||
require.Equal(t, 0, obs.Len()) | ||
|
||
// Verify state after changing details state | ||
upgradeDetails.SetState(details.StateRollback) | ||
require.NotNil(t, testMarker.Details) | ||
require.Equal(t, details.StateRollback, testMarker.Details.State) | ||
require.Equal(t, 0, obs.Len()) | ||
|
||
// Verify state after clearing details state | ||
upgradeDetails.SetState(details.StateCompleted) | ||
require.Nil(t, testMarker.Details) | ||
require.Equal(t, 0, obs.Len()) | ||
|
||
// Verify state after changing details state and there's an | ||
// error saving the marker | ||
upgradeDetails.SetState(details.StateRollback) | ||
require.NotNil(t, testMarker.Details) | ||
require.Equal(t, 1, obs.Len()) | ||
logs := obs.TakeAll() | ||
require.Equal(t, zapcore.ErrorLevel, logs[0].Level) | ||
require.Equal(t, `unable to save upgrade marker after setting upgrade details (state = UPG_ROLLBACK): some error`, logs[0].Message) | ||
|
||
// Verify state after clearing details state and there's an | ||
// error saving the marker | ||
upgradeDetails.SetState(details.StateCompleted) | ||
require.Nil(t, testMarker.Details) | ||
require.Equal(t, 1, obs.Len()) | ||
logs = obs.TakeAll() | ||
require.Equal(t, zapcore.ErrorLevel, logs[0].Level) | ||
require.Equal(t, `unable to save upgrade marker after clearing upgrade details: some error`, logs[0].Message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.