@@ -874,18 +874,121 @@ func (r *tester) getFailureStoreDocs(ctx context.Context, dataStream string) ([]
874874 return docs , nil
875875}
876876
877+ type deprecationWarning struct {
878+ Level string `json:"level"`
879+ Message string `json:"message"`
880+ URL string `json:"url"`
881+ Details string `json:"details"`
882+
883+ ResolveDuringRollingUpgrade bool `json:"resolve_during_rolling_upgrade"`
884+
885+ index string
886+ }
887+
888+ func (r * tester ) getDeprecationWarnings (ctx context.Context , dataStream string ) ([]deprecationWarning , error ) {
889+ resp , err := r .esAPI .Migration .Deprecations (
890+ r .esAPI .Migration .Deprecations .WithContext (ctx ),
891+ r .esAPI .Migration .Deprecations .WithIndex (dataStream ),
892+ )
893+ if err != nil {
894+ return nil , fmt .Errorf ("request failed: %w" , err )
895+ }
896+ defer resp .Body .Close ()
897+
898+ if resp .IsError () {
899+ return nil , fmt .Errorf ("unexpected status code in response: %s" , resp .String ())
900+ }
901+
902+ // Apart from index_settings, there are also cluster_settings, node_settings and ml_settings.
903+ // There is also a data_streams field in the response that is not documented and is empty.
904+ // Here we are interested only on warnings on index settings.
905+ var results struct {
906+ IndexSettings map [string ][]deprecationWarning `json:"index_settings"`
907+ }
908+ err = json .NewDecoder (resp .Body ).Decode (& results )
909+ if err != nil {
910+ return nil , fmt .Errorf ("cannot decode response: %w" , err )
911+ }
912+
913+ var result []deprecationWarning
914+ for index , warnings := range results .IndexSettings {
915+ for _ , warning := range warnings {
916+ warning .index = index
917+ result = append (result , warning )
918+ }
919+ }
920+ return result , nil
921+ }
922+
923+ func (r * tester ) checkDeprecationWarnings (stackVersion * semver.Version , dataStream string , warnings []deprecationWarning , configName string ) []testrunner.TestResult {
924+ var results []testrunner.TestResult
925+ for _ , warning := range warnings {
926+ if ignoredDeprecationWarning (stackVersion , warning ) {
927+ continue
928+ }
929+ details := warning .Details
930+ if warning .index != "" {
931+ details = fmt .Sprintf ("%s (index: %s)" , details , warning .index )
932+ }
933+ tr := testrunner.TestResult {
934+ TestType : TestType ,
935+ Name : "Deprecation warnings - " + configName ,
936+ Package : r .testFolder .Package ,
937+ DataStream : r .testFolder .DataStream ,
938+ FailureMsg : warning .Message ,
939+ FailureDetails : details ,
940+ }
941+ results = append (results , tr )
942+ }
943+ return results
944+ }
945+
946+ func mustParseConstraint (c string ) * semver.Constraints {
947+ constraint , err := semver .NewConstraint (c )
948+ if err != nil {
949+ panic (err )
950+ }
951+ return constraint
952+ }
953+
954+ var ignoredWarnings = []struct {
955+ constraints * semver.Constraints
956+ pattern * regexp.Regexp
957+ }{
958+ {
959+ // This deprecation warning was introduced in 8.17.0 and fixed in Fleet in 8.17.2.
960+ // See https://github.com/elastic/kibana/pull/207133
961+ // Ignoring it because packages cannot do much about this on these versions.
962+ constraints : mustParseConstraint (`>=8.17.0,<8.17.2` ),
963+ pattern : regexp .MustCompile (`^Configuring source mode in mappings is deprecated and will be removed in future versions.` ),
964+ },
965+ }
966+
967+ func ignoredDeprecationWarning (stackVersion * semver.Version , warning deprecationWarning ) bool {
968+ for _ , rule := range ignoredWarnings {
969+ if rule .constraints != nil && ! rule .constraints .Check (stackVersion ) {
970+ continue
971+ }
972+ if rule .pattern .MatchString (warning .Message ) {
973+ return true
974+ }
975+ }
976+ return false
977+ }
978+
877979type scenarioTest struct {
878- dataStream string
879- indexTemplateName string
880- policyTemplateName string
881- kibanaDataStream kibana.PackageDataStream
882- syntheticEnabled bool
883- docs []common.MapStr
884- failureStore []failureStoreDocument
885- ignoredFields []string
886- degradedDocs []common.MapStr
887- agent agentdeployer.DeployedAgent
888- startTestTime time.Time
980+ dataStream string
981+ indexTemplateName string
982+ policyTemplateName string
983+ kibanaDataStream kibana.PackageDataStream
984+ syntheticEnabled bool
985+ docs []common.MapStr
986+ failureStore []failureStoreDocument
987+ deprecationWarnings []deprecationWarning
988+ ignoredFields []string
989+ degradedDocs []common.MapStr
990+ agent agentdeployer.DeployedAgent
991+ startTestTime time.Time
889992}
890993
891994type pipelineTrace []string
@@ -1293,6 +1396,14 @@ func (r *tester) prepareScenario(ctx context.Context, config *testConfig, stackC
12931396 return hits .size () > 0 , nil
12941397 }, 1 * time .Second , waitForDataTimeout )
12951398
1399+ // Get deprecation warnings after ensuring that there are ingested docs and thus the
1400+ // data stream exists.
1401+ scenario .deprecationWarnings , err = r .getDeprecationWarnings (ctx , scenario .dataStream )
1402+ if err != nil {
1403+ return nil , fmt .Errorf ("failed to get deprecation warnings for data stream %s: %w" , scenario .dataStream , err )
1404+ }
1405+ logger .Debugf ("Found %d deprecation warnings for data stream %s" , len (scenario .deprecationWarnings ), scenario .dataStream )
1406+
12961407 if service != nil && config .Service != "" && ! config .IgnoreServiceError {
12971408 exited , code , err := service .ExitCode (ctx , config .Service )
12981409 if err != nil && ! errors .Is (err , servicedeployer .ErrNotSupported ) {
@@ -1530,7 +1641,12 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
15301641 }
15311642 }
15321643
1533- err = validateIgnoredFields (r .stackVersion .Number , scenario , config )
1644+ stackVersion , err := semver .NewVersion (r .stackVersion .Number )
1645+ if err != nil {
1646+ return result .WithErrorf ("failed to parse stack version: %w" , err )
1647+ }
1648+
1649+ err = validateIgnoredFields (stackVersion , scenario , config )
15341650 if err != nil {
15351651 return result .WithError (err )
15361652 }
@@ -1597,6 +1713,10 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
15971713 }
15981714 }
15991715
1716+ if results := r .checkDeprecationWarnings (stackVersion , scenario .dataStream , scenario .deprecationWarnings , config .Name ()); len (results ) > 0 {
1717+ return results , nil
1718+ }
1719+
16001720 if r .withCoverage {
16011721 coverage , err := r .generateCoverageReport (result .CoveragePackageName ())
16021722 if err != nil {
@@ -2180,12 +2300,8 @@ func listExceptionFields(docs []common.MapStr, fieldsValidator *fields.Validator
21802300 return allFields
21812301}
21822302
2183- func validateIgnoredFields (stackVersionString string , scenario * scenarioTest , config * testConfig ) error {
2303+ func validateIgnoredFields (stackVersion * semver. Version , scenario * scenarioTest , config * testConfig ) error {
21842304 skipIgnoredFields := append ([]string (nil ), config .SkipIgnoredFields ... )
2185- stackVersion , err := semver .NewVersion (stackVersionString )
2186- if err != nil {
2187- return fmt .Errorf ("failed to parse stack version: %w" , err )
2188- }
21892305 if stackVersion .LessThan (semver .MustParse ("8.14.0" )) {
21902306 // Pre 8.14 Elasticsearch commonly has event.original not mapped correctly, exclude from check: https://github.com/elastic/elasticsearch/pull/106714
21912307 skipIgnoredFields = append (skipIgnoredFields , "event.original" )
0 commit comments