|
| 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 | +} |
0 commit comments