Skip to content

Commit b5823bd

Browse files
ycombinatorpchila
andauthored
Adding new configuration setting: agent.upgrade.rollback.window (elastic#8065)
* Adding new configuration setting: agent.upgrade.rollback.window * Adding CHANGELOG entry * Update config reference template * Run mage update * Update _meta/config/common.reference.p2.yml.tmpl Co-authored-by: Paolo Chilà <[email protected]> * Update changelog/fragments/1746197293-config-rollback-window.yaml Co-authored-by: Paolo Chilà <[email protected]> --------- Co-authored-by: Paolo Chilà <[email protected]>
1 parent 89902d1 commit b5823bd

File tree

5 files changed

+160
-1
lines changed

5 files changed

+160
-1
lines changed

_meta/config/common.reference.p2.yml.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ inputs:
119119
# # duration will increase for subsequent retry attempts in a randomized exponential backoff manner.
120120
# retry_sleep_init_duration: 30s
121121

122+
# agent.upgrade
123+
# # rollback settings
124+
# rollback:
125+
# # duration in which an upgraded Agent may be manually rolled back.
126+
# window: 168h
127+
122128
# agent.process:
123129
# # timeout for creating new processes. when process is not successfully created by this timeout
124130
# # start operation is considered a failure
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Adds a new configuration setting, `agent.upgrade.rollback.window`
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+
The value of the `agent.upgrade.rollback.window` setting determines the period after upgrading
21+
Elastic Agent when a rollback to the previous version can be triggered. This is an optional
22+
setting, with a default value of `168h` (7 days). The value can be any string that is parseable
23+
by https://pkg.go.dev/time#ParseDuration.
24+
25+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
26+
component: elastic-agent
27+
28+
# PR URL; optional; the PR number that added the changeset.
29+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
30+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
31+
# Please provide it if you are adding a fragment for a different PR.
32+
pr: https://github.com/elastic/elastic-agent/pull/8065
33+
34+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
35+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
36+
issue: https://github.com/elastic/elastic-agent/issues/6881

elastic-agent.reference.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ inputs:
125125
# # duration will increase for subsequent retry attempts in a randomized exponential backoff manner.
126126
# retry_sleep_init_duration: 30s
127127

128+
# agent.upgrade
129+
# # rollback settings
130+
# rollback:
131+
# # duration in which an upgraded Agent may be manually rolled back.
132+
# window: 168h
133+
128134
# agent.process:
129135
# # timeout for creating new processes. when process is not successfully created by this timeout
130136
# # start operation is considered a failure

internal/pkg/agent/configuration/upgrade.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ const (
1212

1313
// interval between checks for new (upgraded) Agent returning an error status.
1414
defaultStatusCheckInterval = 30 * time.Second
15+
16+
// period during which an upgraded Agent can be asked to rollback to the previous
17+
// Agent version on disk.
18+
defaultRollbackWindowDuration = 7 * 24 * time.Hour // 7 days
1519
)
1620

1721
// UpgradeConfig is the configuration related to Agent upgrades.
1822
type UpgradeConfig struct {
19-
Watcher *UpgradeWatcherConfig `yaml:"watcher" config:"watcher" json:"watcher"`
23+
Watcher *UpgradeWatcherConfig `yaml:"watcher" config:"watcher" json:"watcher"`
24+
Rollback *UpgradeRollbackConfig `yaml:"rollback" config:"rollback" json:"rollback"`
2025
}
2126

2227
type UpgradeWatcherConfig struct {
@@ -27,6 +32,10 @@ type UpgradeWatcherCheckConfig struct {
2732
Interval time.Duration `yaml:"interval" config:"interval" json:"interval"`
2833
}
2934

35+
type UpgradeRollbackConfig struct {
36+
Window time.Duration `yaml:"window" config:"window" json:"window"`
37+
}
38+
3039
func DefaultUpgradeConfig() *UpgradeConfig {
3140
return &UpgradeConfig{
3241
Watcher: &UpgradeWatcherConfig{
@@ -35,5 +44,8 @@ func DefaultUpgradeConfig() *UpgradeConfig {
3544
Interval: defaultStatusCheckInterval,
3645
},
3746
},
47+
Rollback: &UpgradeRollbackConfig{
48+
Window: defaultRollbackWindowDuration,
49+
},
3850
}
3951
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
package configuration
6+
7+
import (
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/require"
12+
13+
"github.com/elastic/elastic-agent/internal/pkg/config"
14+
)
15+
16+
func TestParseUpgradeConfig(t *testing.T) {
17+
tests := map[string]struct {
18+
cfg map[string]any
19+
expected UpgradeConfig
20+
}{
21+
"default": {
22+
cfg: map[string]any{},
23+
expected: UpgradeConfig{
24+
Watcher: &UpgradeWatcherConfig{
25+
GracePeriod: defaultGracePeriodDuration,
26+
ErrorCheck: UpgradeWatcherCheckConfig{
27+
Interval: defaultStatusCheckInterval,
28+
},
29+
},
30+
Rollback: &UpgradeRollbackConfig{
31+
Window: defaultRollbackWindowDuration,
32+
},
33+
},
34+
},
35+
"watcher_grace_period": {
36+
cfg: map[string]any{
37+
"watcher": map[string]any{
38+
"grace_period": "2m",
39+
},
40+
},
41+
expected: UpgradeConfig{
42+
Watcher: &UpgradeWatcherConfig{
43+
GracePeriod: 2 * time.Minute,
44+
ErrorCheck: UpgradeWatcherCheckConfig{
45+
Interval: defaultStatusCheckInterval,
46+
},
47+
},
48+
Rollback: &UpgradeRollbackConfig{
49+
Window: defaultRollbackWindowDuration,
50+
},
51+
},
52+
},
53+
"watcher_error_check_interval": {
54+
cfg: map[string]any{
55+
"watcher": map[string]any{
56+
"error_check": map[string]any{
57+
"interval": "1h",
58+
},
59+
},
60+
},
61+
expected: UpgradeConfig{
62+
Watcher: &UpgradeWatcherConfig{
63+
GracePeriod: defaultGracePeriodDuration,
64+
ErrorCheck: UpgradeWatcherCheckConfig{
65+
Interval: 1 * time.Hour,
66+
},
67+
},
68+
Rollback: &UpgradeRollbackConfig{
69+
Window: defaultRollbackWindowDuration,
70+
},
71+
},
72+
},
73+
"rollback_window": {
74+
cfg: map[string]any{
75+
"rollback.window": "8h",
76+
},
77+
expected: UpgradeConfig{
78+
Watcher: &UpgradeWatcherConfig{
79+
GracePeriod: defaultGracePeriodDuration,
80+
ErrorCheck: UpgradeWatcherCheckConfig{
81+
Interval: defaultStatusCheckInterval,
82+
},
83+
},
84+
Rollback: &UpgradeRollbackConfig{
85+
Window: 8 * time.Hour,
86+
},
87+
},
88+
},
89+
}
90+
91+
for name, test := range tests {
92+
t.Run(name, func(t *testing.T) {
93+
c := DefaultUpgradeConfig()
94+
cfg := config.MustNewConfigFrom(test.cfg)
95+
require.NoError(t, cfg.UnpackTo(c))
96+
require.Equal(t, test.expected, *c)
97+
})
98+
}
99+
}

0 commit comments

Comments
 (0)