Skip to content

Commit 9a1b78a

Browse files
committed
Scope TestIntakeRefreshAPIKey's fakeintake API key check to the metrics endpoint instead of the global (route-unscoped) last-key
1 parent 596b9de commit 9a1b78a

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

test/fakeintake/client/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,19 @@ func (c *Client) GetLastAPIKey() (string, error) {
599599
return strings.TrimSpace(string(body)), nil
600600
}
601601

602+
// GetLastMetricPayloadAPIKey fetches fakeintake on `/api/v2/series` endpoint and returns
603+
// the API key of the last received metric payload
604+
func (c *Client) GetLastMetricPayloadAPIKey() (string, error) {
605+
payloads, err := c.getFakePayloads(metricsEndpoint)
606+
if err != nil {
607+
return "", err
608+
}
609+
if len(payloads) == 0 {
610+
return "", errors.New("no metric payloads found")
611+
}
612+
return payloads[len(payloads)-1].APIKey, nil
613+
}
614+
602615
func (c *Client) getMetric(name string) ([]*aggregator.MetricSeries, error) {
603616
if err := c.getMetrics(); err != nil {
604617
return nil, err

test/new-e2e/tests/agent-configuration/configrefresh_api_key_refresh_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ api_key: ENC[api_key]
7373
assert.Contains(t, status.Content, "API key ending with wxyz")
7474
}, 1*time.Minute, 10*time.Second)
7575

76-
// Assert that the fakeIntake has received the new API Key
76+
// Assert that the fakeIntake has received the new API Key on the metrics
77+
// endpoint (GetLastAPIKey is unscoped across all routes, so it can be
78+
// clobbered by unrelated traffic like remote-config polling)
7779
assert.EventuallyWithT(v.T(), func(t *assert.CollectT) {
78-
lastAPIKey, err := v.Env().FakeIntake.Client().GetLastAPIKey()
80+
lastAPIKey, err := v.Env().FakeIntake.Client().GetLastMetricPayloadAPIKey()
7981
assert.NoError(t, err)
8082
assert.Equal(t, secondAPIKey, lastAPIKey)
8183
}, 1*time.Minute, 10*time.Second)

0 commit comments

Comments
 (0)