Skip to content

Commit 62ca035

Browse files
committed
Add 7.x to 8.x to 9.x test and increase timeout
1 parent ae4c46f commit 62ca035

File tree

4 files changed

+228
-3
lines changed

4 files changed

+228
-3
lines changed

.github/workflows/functional-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- '8.x' # Latest 8 version
3636
- '9.0'
3737
- '9.1'
38+
- '9.x' # Latest 9 version
3839
steps:
3940
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
4041

@@ -60,7 +61,7 @@ jobs:
6061
export TF_VAR_CREATED_DATE=$(date +%s)
6162
VERSION="${{ matrix.active-version }}"
6263
VERSION="${VERSION//./_}"
63-
go test -run="(_to_${VERSION}$|_to_${VERSION}__)" -v -timeout=40m -target="${{ matrix.environment }}" ./
64+
go test -run="(_to_${VERSION}$|_to_${VERSION}__)" -v -timeout=60m -target="${{ matrix.environment }}" ./
6465
6566
# notify:
6667
# if: always()

functionaltests/9_x_test.go

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package functionaltests
19+
20+
import (
21+
"testing"
22+
23+
"github.com/elastic/apm-server/functionaltests/internal/asserts"
24+
"github.com/elastic/apm-server/functionaltests/internal/ecclient"
25+
)
26+
27+
func TestUpgrade_7_17_to_8_x_to_9_x_Snapshot_Standalone_to_Managed(t *testing.T) {
28+
fromVersion7 := getLatestSnapshot(t, "7.17")
29+
toVersion8 := getLatestSnapshot(t, "8")
30+
toVersion9 := getLatestSnapshot(t, "9")
31+
32+
t.Run("UpgradeFirst", func(t *testing.T) {
33+
t.Parallel()
34+
runner := upgradeThenManaged789Runner(fromVersion7, toVersion8, toVersion9)
35+
runner.Run(t)
36+
})
37+
38+
t.Run("ManagedFirst", func(t *testing.T) {
39+
t.Parallel()
40+
runner := managedThenUpgrade789Runner(fromVersion7, toVersion8, toVersion9)
41+
runner.Run(t)
42+
})
43+
}
44+
45+
func upgradeThenManaged789Runner(fromVersion7, toVersion8, toVersion9 ecclient.StackVersion) testStepsRunner {
46+
// Data streams in 8.x should be all ILM if upgraded to a stack < 8.15 and > 8.16.
47+
checkILM8 := asserts.CheckDataStreamsWant{
48+
Quantity: 8,
49+
PreferIlm: true,
50+
DSManagedBy: managedByILM,
51+
IndicesPerDS: 1,
52+
IndicesManagedBy: []string{managedByILM},
53+
}
54+
// Data streams in 9.x should also be all ILM, but with rollover due to changes
55+
// in underlying template.
56+
checkILMRollover9 := asserts.CheckDataStreamsWant{
57+
Quantity: 8,
58+
PreferIlm: true,
59+
DSManagedBy: managedByILM,
60+
IndicesPerDS: 2,
61+
IndicesManagedBy: []string{managedByILM, managedByILM},
62+
}
63+
64+
return testStepsRunner{
65+
Steps: []testStep{
66+
// Start from 7.x.
67+
createStep{
68+
DeployVersion: fromVersion7,
69+
APMDeploymentMode: apmStandalone,
70+
},
71+
ingestLegacyStep{},
72+
// Upgrade to 8.x.
73+
upgradeLegacyStep{NewVersion: toVersion8},
74+
ingestStep{CheckDataStream: checkILM8},
75+
// Resolve deprecations and upgrade to 9.x.
76+
resolveDeprecationsStep{},
77+
upgradeStep{
78+
NewVersion: toVersion9,
79+
CheckDataStream: checkILM8,
80+
},
81+
ingestStep{CheckDataStream: checkILMRollover9},
82+
// Migrate to managed.
83+
migrateManagedStep{},
84+
ingestStep{CheckDataStream: checkILMRollover9},
85+
checkErrorLogsStep{
86+
ESErrorLogsIgnored: esErrorLogs{
87+
eventLoopShutdown,
88+
},
89+
APMErrorLogsIgnored: apmErrorLogs{
90+
tlsHandshakeError,
91+
esReturnedUnknown503,
92+
refreshCache503,
93+
populateSourcemapFetcher403,
94+
},
95+
},
96+
},
97+
}
98+
}
99+
100+
func managedThenUpgrade789Runner(fromVersion7, toVersion8, toVersion9 ecclient.StackVersion) testStepsRunner {
101+
checkILM := asserts.CheckDataStreamIndividualWant{
102+
PreferIlm: true,
103+
DSManagedBy: managedByILM,
104+
IndicesManagedBy: []string{managedByILM},
105+
}
106+
checkILMRollover := asserts.CheckDataStreamIndividualWant{
107+
PreferIlm: true,
108+
DSManagedBy: managedByILM,
109+
IndicesManagedBy: []string{managedByILM, managedByILM},
110+
}
111+
112+
check8 := map[string]asserts.CheckDataStreamIndividualWant{
113+
// These data streams are created in 7.x as well, so when we ingest
114+
// again in 8.x, they will be rolled-over.
115+
"traces-apm-%s": checkILMRollover,
116+
"metrics-apm.app.opbeans_python-%s": checkILMRollover,
117+
"metrics-apm.internal-%s": checkILMRollover,
118+
"logs-apm.error-%s": checkILMRollover,
119+
// These data streams are only created in 8.x, so they will only have
120+
// 1 index.
121+
"metrics-apm.service_destination.1m-%s": checkILM,
122+
"metrics-apm.service_transaction.1m-%s": checkILM,
123+
"metrics-apm.service_summary.1m-%s": checkILM,
124+
"metrics-apm.transaction.1m-%s": checkILM,
125+
}
126+
127+
checkILMRolloverTwice := asserts.CheckDataStreamIndividualWant{
128+
PreferIlm: true,
129+
DSManagedBy: managedByILM,
130+
IndicesManagedBy: []string{managedByILM, managedByILM, managedByILM},
131+
}
132+
133+
check9 := map[string]asserts.CheckDataStreamIndividualWant{
134+
// These data streams are rolled over in 8.x, so with the 9.x rollover
135+
// there will be 3 indices per DS.
136+
"traces-apm-%s": checkILMRolloverTwice,
137+
"metrics-apm.app.opbeans_python-%s": checkILMRolloverTwice,
138+
"metrics-apm.internal-%s": checkILMRolloverTwice,
139+
"logs-apm.error-%s": checkILMRolloverTwice,
140+
// These data streams are only created in 8.x, so they will only be
141+
// rolled over once.
142+
"metrics-apm.service_destination.1m-%s": checkILMRollover,
143+
"metrics-apm.service_transaction.1m-%s": checkILMRollover,
144+
"metrics-apm.service_summary.1m-%s": checkILMRollover,
145+
"metrics-apm.transaction.1m-%s": checkILMRollover,
146+
}
147+
148+
// These data streams are created in 7.x, but not used in 8.x and 9.x,
149+
// so we ignore them to avoid wrong assertions.
150+
ignoredDataStreams := []string{
151+
"metrics-apm.app.opbeans_node-%s",
152+
"metrics-apm.app.opbeans_ruby-%s",
153+
"metrics-apm.app.opbeans_go-%s",
154+
}
155+
156+
return testStepsRunner{
157+
Steps: []testStep{
158+
// Start from 7.x.
159+
createStep{
160+
DeployVersion: fromVersion7,
161+
APMDeploymentMode: apmStandalone,
162+
},
163+
ingestLegacyStep{},
164+
// Migrate to managed.
165+
migrateManagedStep{},
166+
ingestLegacyStep{},
167+
// Upgrade to 8.x.
168+
upgradeLegacyStep{NewVersion: toVersion8},
169+
ingestStep{
170+
IgnoreDataStreams: ignoredDataStreams,
171+
CheckIndividualDataStream: check8,
172+
},
173+
// Resolve deprecations and upgrade to 9.x.
174+
resolveDeprecationsStep{},
175+
upgradeStep{
176+
NewVersion: toVersion9,
177+
CheckIndividualDataStream: check8,
178+
},
179+
ingestStep{
180+
IgnoreDataStreams: ignoredDataStreams,
181+
CheckIndividualDataStream: check9,
182+
},
183+
checkErrorLogsStep{
184+
ESErrorLogsIgnored: esErrorLogs{
185+
eventLoopShutdown,
186+
addIndexTemplateTracesError,
187+
},
188+
APMErrorLogsIgnored: apmErrorLogs{
189+
tlsHandshakeError,
190+
esReturnedUnknown503,
191+
refreshCache503,
192+
preconditionClusterInfoCtxCanceled,
193+
waitServerReadyCtxCanceled,
194+
grpcServerStopped,
195+
populateSourcemapFetcher403,
196+
},
197+
},
198+
},
199+
}
200+
}

functionaltests/steps_legacy_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,14 @@ func (m migrateManagedStep) Step(t *testing.T, ctx context.Context, e *testStepE
202202
emptyDataStreamsIngest(e.dsNamespace))
203203
return testStepResult{DSDocCount: dsDocCount}
204204
}
205+
206+
type resolveDeprecationsStep struct{}
207+
208+
var _ testStep = resolveDeprecationsStep{}
209+
210+
func (r resolveDeprecationsStep) Step(t *testing.T, ctx context.Context, e *testStepEnv, previousRes testStepResult) testStepResult {
211+
t.Log("------ resolve migration deprecations ------")
212+
err := e.kbc.ResolveMigrationDeprecations(ctx)
213+
require.NoError(t, err)
214+
return previousRes
215+
}

functionaltests/steps_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ func formatAllMap[T any](m map[string]T, s string) map[string]T {
237237
type upgradeStep struct {
238238
NewVersion ecclient.StackVersion
239239
CheckDataStream asserts.CheckDataStreamsWant
240+
// IgnoreDataStreams are the data streams to be ignored in assertions.
241+
// The data stream names can contain '%s' to indicate namespace.
242+
IgnoreDataStreams []string
243+
// CheckIndividualDataStream is used to check the data streams individually
244+
// instead of as a whole using CheckDataStream.
245+
// The data stream names can contain '%s' to indicate namespace.
246+
CheckIndividualDataStream map[string]asserts.CheckDataStreamIndividualWant
240247
}
241248

242249
var _ testStep = upgradeStep{}
@@ -256,13 +263,19 @@ func (u upgradeStep) Step(t *testing.T, ctx context.Context, e *testStepEnv, pre
256263
// We assert that no changes happened in the number of documents after upgrade
257264
// to ensure the state didn't change.
258265
// We don't expect any change here unless something broke during the upgrade.
259-
dsDocCount := getDocCountPerDS(t, ctx, e.esc)
266+
ignoreDS := formatAll(u.IgnoreDataStreams, e.dsNamespace)
267+
dsDocCount := getDocCountPerDS(t, ctx, e.esc, ignoreDS...)
260268
asserts.CheckDocCount(t, dsDocCount, previousRes.DSDocCount,
261269
emptyDataStreamsIngest(e.dsNamespace))
262270

263271
t.Log("check data streams after upgrade")
264272
dataStreams := getAPMDataStreams(t, ctx, e.esc)
265-
asserts.CheckDataStreams(t, u.CheckDataStream, dataStreams)
273+
if u.CheckIndividualDataStream != nil {
274+
expected := formatAllMap(u.CheckIndividualDataStream, e.dsNamespace)
275+
asserts.CheckDataStreamsIndividually(t, expected, dataStreams)
276+
} else {
277+
asserts.CheckDataStreams(t, u.CheckDataStream, dataStreams)
278+
}
266279

267280
return testStepResult{DSDocCount: dsDocCount}
268281
}

0 commit comments

Comments
 (0)