|
| 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__Snapshot_Standalone_to_Managed(t *testing.T) { |
| 28 | + fromVersion := getLatestSnapshot(t, "7.17") |
| 29 | + toVersion := getLatestSnapshot(t, "8") |
| 30 | + |
| 31 | + t.Run("UpgradeFirst", func(t *testing.T) { |
| 32 | + t.Parallel() |
| 33 | + runner := upgradeThenManaged78Runner(fromVersion, toVersion) |
| 34 | + runner.Run(t) |
| 35 | + }) |
| 36 | + |
| 37 | + t.Run("ManagedFirst", func(t *testing.T) { |
| 38 | + t.Parallel() |
| 39 | + runner := managedThenUpgrade78Runner(fromVersion, toVersion) |
| 40 | + runner.Run(t) |
| 41 | + }) |
| 42 | +} |
| 43 | + |
| 44 | +func TestUpgrade_7_17_to_8_x__BC_Standalone_to_Managed(t *testing.T) { |
| 45 | + fromVersion := getLatestVersionOrSkip(t, "7.17") |
| 46 | + toVersion := getLatestBCOrSkip(t, "8") |
| 47 | + |
| 48 | + t.Run("UpgradeFirst", func(t *testing.T) { |
| 49 | + t.Parallel() |
| 50 | + runner := upgradeThenManaged78Runner(fromVersion, toVersion) |
| 51 | + runner.Run(t) |
| 52 | + }) |
| 53 | + |
| 54 | + t.Run("ManagedFirst", func(t *testing.T) { |
| 55 | + t.Parallel() |
| 56 | + runner := managedThenUpgrade78Runner(fromVersion, toVersion) |
| 57 | + runner.Run(t) |
| 58 | + }) |
| 59 | +} |
| 60 | + |
| 61 | +func upgradeThenManaged78Runner(fromVersion, toVersion ecclient.StackVersion) testStepsRunner { |
| 62 | + // Data streams in 8.x should be all ILM if upgraded to a stack < 8.15 and > 8.16. |
| 63 | + checkILM := asserts.CheckDataStreamsWant{ |
| 64 | + Quantity: 8, |
| 65 | + PreferIlm: true, |
| 66 | + DSManagedBy: managedByILM, |
| 67 | + IndicesPerDS: 1, |
| 68 | + IndicesManagedBy: []string{managedByILM}, |
| 69 | + } |
| 70 | + |
| 71 | + return testStepsRunner{ |
| 72 | + Steps: []testStep{ |
| 73 | + createStep{ |
| 74 | + DeployVersion: fromVersion, |
| 75 | + APMDeploymentMode: apmStandalone, |
| 76 | + }, |
| 77 | + ingestLegacyStep{}, |
| 78 | + upgradeLegacyStep{NewVersion: toVersion}, |
| 79 | + ingestStep{CheckDataStream: checkILM}, |
| 80 | + migrateManagedStep{}, |
| 81 | + ingestStep{CheckDataStream: checkILM}, |
| 82 | + checkErrorLogsStep{ |
| 83 | + ESErrorLogsIgnored: esErrorLogs{ |
| 84 | + eventLoopShutdown, |
| 85 | + }, |
| 86 | + APMErrorLogsIgnored: apmErrorLogs{ |
| 87 | + tlsHandshakeError, |
| 88 | + esReturnedUnknown503, |
| 89 | + refreshCache503, |
| 90 | + // TODO: remove once fixed |
| 91 | + populateSourcemapFetcher403, |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +func managedThenUpgrade78Runner(fromVersion, toVersion ecclient.StackVersion) testStepsRunner { |
| 99 | + checkILM := asserts.CheckDataStreamIndividualWant{ |
| 100 | + PreferIlm: true, |
| 101 | + DSManagedBy: managedByILM, |
| 102 | + IndicesManagedBy: []string{managedByILM}, |
| 103 | + } |
| 104 | + checkILMRollover := asserts.CheckDataStreamIndividualWant{ |
| 105 | + PreferIlm: true, |
| 106 | + DSManagedBy: managedByILM, |
| 107 | + IndicesManagedBy: []string{managedByILM, managedByILM}, |
| 108 | + } |
| 109 | + |
| 110 | + check := map[string]asserts.CheckDataStreamIndividualWant{ |
| 111 | + // These data streams are created in 7.x as well, so when we ingest again |
| 112 | + // in 8.x, they will be rolled-over. |
| 113 | + "traces-apm-%s": checkILMRollover, |
| 114 | + "metrics-apm.app.opbeans_python-%s": checkILMRollover, |
| 115 | + "metrics-apm.internal-%s": checkILMRollover, |
| 116 | + "logs-apm.error-%s": checkILMRollover, |
| 117 | + // These data streams are only created in 8.x, so they will only have 1 index. |
| 118 | + "metrics-apm.service_destination.1m-%s": checkILM, |
| 119 | + "metrics-apm.service_transaction.1m-%s": checkILM, |
| 120 | + "metrics-apm.service_summary.1m-%s": checkILM, |
| 121 | + "metrics-apm.transaction.1m-%s": checkILM, |
| 122 | + } |
| 123 | + |
| 124 | + // These data streams are created in 7.x, but not used in 8.x, |
| 125 | + // so we ignore them to avoid wrong assertions. |
| 126 | + ignoredDataStreams := []string{ |
| 127 | + "metrics-apm.app.opbeans_node-%s", |
| 128 | + "metrics-apm.app.opbeans_ruby-%s", |
| 129 | + "metrics-apm.app.opbeans_go-%s", |
| 130 | + } |
| 131 | + |
| 132 | + return testStepsRunner{ |
| 133 | + Steps: []testStep{ |
| 134 | + createStep{ |
| 135 | + DeployVersion: fromVersion, |
| 136 | + APMDeploymentMode: apmStandalone, |
| 137 | + }, |
| 138 | + ingestLegacyStep{}, |
| 139 | + migrateManagedStep{}, |
| 140 | + ingestLegacyStep{}, |
| 141 | + upgradeLegacyStep{NewVersion: toVersion}, |
| 142 | + ingestStep{ |
| 143 | + IgnoreDataStreams: ignoredDataStreams, |
| 144 | + CheckIndividualDataStream: check, |
| 145 | + }, |
| 146 | + checkErrorLogsStep{ |
| 147 | + ESErrorLogsIgnored: esErrorLogs{ |
| 148 | + eventLoopShutdown, |
| 149 | + addIndexTemplateTracesError, |
| 150 | + }, |
| 151 | + APMErrorLogsIgnored: apmErrorLogs{ |
| 152 | + tlsHandshakeError, |
| 153 | + esReturnedUnknown503, |
| 154 | + refreshCache503, |
| 155 | + preconditionClusterInfoCtxCanceled, |
| 156 | + waitServerReadyCtxCanceled, |
| 157 | + grpcServerStopped, |
| 158 | + // TODO: remove once fixed |
| 159 | + populateSourcemapFetcher403, |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
| 163 | + } |
| 164 | +} |
0 commit comments