Skip to content

Commit 698cf5c

Browse files
committed
Fix monitoring reloading tests
Ensure we verify the policy update was actually applied before querying the monitoring endpoint. Add a retry on said request as well.
1 parent 2845ec9 commit 698cf5c

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

testing/integration/ess/monitoring_probe_preserve_text_cfg_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"time"
1717

1818
"github.com/gofrs/uuid/v5"
19+
"github.com/stretchr/testify/assert"
1920
"github.com/stretchr/testify/require"
2021
"github.com/stretchr/testify/suite"
2122

@@ -67,6 +68,7 @@ type MonitoringTextRunner struct {
6768
suite.Suite
6869
info *define.Info
6970
agentFixture *atesting.Fixture
71+
agentID string
7072

7173
ESHost string
7274

@@ -121,11 +123,12 @@ func (runner *MonitoringTextRunner) SetupSuite() {
121123
err = runner.agentFixture.WriteFileToWorkDir(ctx, defaultTextCfg, "elastic-agent.yml")
122124
require.NoError(runner.T(), err)
123125

124-
policyResp, _, err := tools.InstallAgentWithPolicy(ctx, runner.T(), installOpts, runner.agentFixture, runner.info.KibanaClient, basePolicy)
126+
policyResp, agentID, err := tools.InstallAgentWithPolicy(ctx, runner.T(), installOpts, runner.agentFixture, runner.info.KibanaClient, basePolicy)
125127
require.NoError(runner.T(), err)
126128

127129
runner.policyID = policyResp.ID
128130
runner.policyName = basePolicy.Name
131+
runner.agentID = agentID
129132

130133
_, err = tools.InstallPackageFromDefaultFile(ctx, runner.info.KibanaClient, "system",
131134
integration.PreinstalledPackages["system"], "testdata/system_integration_setup.json", uuid.Must(uuid.NewV4()).String(), policyResp.ID)
@@ -137,6 +140,8 @@ func (runner *MonitoringTextRunner) TestMonitoringLiveness() {
137140
defer cancel()
138141

139142
runner.AllComponentsHealthy(ctx)
143+
agent, err := runner.info.KibanaClient.GetAgent(ctx, kibana.GetAgentRequest{ID: runner.agentID})
144+
require.NoError(runner.T(), err)
140145

141146
client := http.Client{Timeout: time.Second * 4}
142147
endpoint := "http://localhost:6791/processes"
@@ -173,12 +178,21 @@ func (runner *MonitoringTextRunner) TestMonitoringLiveness() {
173178
require.NoError(runner.T(), err)
174179
require.Equal(runner.T(), http.StatusOK, statusCode, "non-200 status code; got response: %s", string(overrideResp))
175180

181+
// verify the new policy revision was applied
182+
newPolicyRevision := agent.PolicyRevision + 1
183+
require.Eventually(
184+
runner.T(),
185+
tools.IsPolicyRevision(ctx, runner.T(), runner.info.KibanaClient, runner.policyID, newPolicyRevision),
186+
5*time.Minute, time.Second)
187+
176188
runner.AllComponentsHealthy(ctx)
177189

178190
updatedEndpoint := "http://localhost:6792/processes"
179191
// second stage: ensure the HTTP config has updated
180-
req, err = http.NewRequestWithContext(ctx, "GET", updatedEndpoint, nil)
181-
require.NoError(runner.T(), err)
192+
require.EventuallyWithT(runner.T(), func(collect *assert.CollectT) {
193+
req, err = http.NewRequestWithContext(ctx, "GET", updatedEndpoint, nil)
194+
require.NoError(collect, err)
195+
}, time.Minute, time.Second)
182196

183197
initResp, err = client.Do(req)
184198
require.NoError(runner.T(), err)

testing/integration/ess/monitoring_probe_reload_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"time"
1717

1818
"github.com/gofrs/uuid/v5"
19+
"github.com/stretchr/testify/assert"
1920
"github.com/stretchr/testify/require"
2021
"github.com/stretchr/testify/suite"
2122

@@ -31,6 +32,7 @@ type MonitoringRunner struct {
3132
suite.Suite
3233
info *define.Info
3334
agentFixture *atesting.Fixture
35+
agentID string
3436

3537
ESHost string
3638

@@ -81,11 +83,12 @@ func (runner *MonitoringRunner) SetupSuite() {
8183
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
8284
defer cancel()
8385

84-
policyResp, _, err := tools.InstallAgentWithPolicy(ctx, runner.T(), installOpts, runner.agentFixture, runner.info.KibanaClient, basePolicy)
86+
policyResp, agentID, err := tools.InstallAgentWithPolicy(ctx, runner.T(), installOpts, runner.agentFixture, runner.info.KibanaClient, basePolicy)
8587
require.NoError(runner.T(), err)
8688

8789
runner.policyID = policyResp.ID
8890
runner.policyName = basePolicy.Name
91+
runner.agentID = agentID
8992

9093
_, err = tools.InstallPackageFromDefaultFile(ctx, runner.info.KibanaClient, "system",
9194
integration.PreinstalledPackages["system"], "testdata/system_integration_setup.json", uuid.Must(uuid.NewV4()).String(), policyResp.ID)
@@ -97,6 +100,8 @@ func (runner *MonitoringRunner) TestMonitoringLiveness() {
97100
defer cancel()
98101

99102
runner.AllComponentsHealthy(ctx)
103+
agent, err := runner.info.KibanaClient.GetAgent(ctx, kibana.GetAgentRequest{ID: runner.agentID})
104+
require.NoError(runner.T(), err)
100105

101106
client := http.Client{Timeout: time.Second * 4}
102107
endpoint := "http://localhost:6792/liveness"
@@ -133,11 +138,20 @@ func (runner *MonitoringRunner) TestMonitoringLiveness() {
133138
require.NoError(runner.T(), err)
134139
require.Equal(runner.T(), http.StatusOK, statusCode, "non-200 status code; got response: %s", string(overrideResp))
135140

141+
// verify the new policy revision was applied
142+
newPolicyRevision := agent.PolicyRevision + 1
143+
require.Eventually(
144+
runner.T(),
145+
tools.IsPolicyRevision(ctx, runner.T(), runner.info.KibanaClient, runner.agentID, newPolicyRevision),
146+
5*time.Minute, time.Second)
147+
136148
runner.AllComponentsHealthy(ctx)
137149

138150
// check to make sure that we now have a liveness probe response
139-
req, err = http.NewRequestWithContext(ctx, "GET", endpoint, nil)
140-
require.NoError(runner.T(), err)
151+
require.EventuallyWithT(runner.T(), func(collect *assert.CollectT) {
152+
req, err = http.NewRequestWithContext(ctx, "GET", endpoint, nil)
153+
require.NoError(collect, err)
154+
}, time.Minute, time.Second)
141155

142156
// second check: the /liveness endpoint should now be responding
143157
runner.CheckResponse(ctx, endpoint)

0 commit comments

Comments
 (0)