@@ -607,60 +607,38 @@ func (r *tester) runTestPerVariant(ctx context.Context, result *testrunner.Resul
607607 return partial , nil
608608}
609609
610- func (r * tester ) isSyntheticsEnabled (ctx context.Context , dataStream , componentTemplatePackage string ) (bool , error ) {
611- resp , err := r .esAPI .Cluster .GetComponentTemplate (
612- r .esAPI .Cluster .GetComponentTemplate .WithContext (ctx ),
613- r .esAPI .Cluster .GetComponentTemplate .WithName (componentTemplatePackage ),
610+ func (r * tester ) isSyntheticsEnabled (ctx context.Context , dataStreamName string ) (bool , error ) {
611+ resp , err := r .esAPI .Indices .SimulateIndexTemplate (dataStreamName ,
612+ r .esAPI .Indices .SimulateIndexTemplate .WithContext (ctx ),
614613 )
615614 if err != nil {
616- return false , fmt .Errorf ("could not get component template %s from data stream %s: %w" , componentTemplatePackage , dataStream , err )
615+ return false , fmt .Errorf ("could not simulate index template for %s: %w" , dataStreamName , err )
617616 }
618617 defer resp .Body .Close ()
619618
620- if resp .StatusCode == http .StatusNotFound {
621- // @package component template doesn't exist before 8.2. On these versions synthetics was not supported
622- // in any case, so just return false.
623- logger .Debugf ("no component template %s found for data stream %s" , componentTemplatePackage , dataStream )
624- return false , nil
625- }
626619 if resp .IsError () {
627- return false , fmt .Errorf ("could not get component template %s for data stream %s: %s" , componentTemplatePackage , dataStream , resp .String ())
620+ return false , fmt .Errorf ("could not simulate index template for %s: %s" , dataStreamName , resp .String ())
628621 }
629622
630623 var results struct {
631- ComponentTemplates []struct {
632- Name string `json:"name"`
633- ComponentTemplate struct {
634- Template struct {
635- Mappings struct {
636- Source * struct {
637- Mode string `json:"mode"`
638- } `json:"_source,omitempty"`
639- } `json:"mappings"`
640- } `json:"template"`
641- } `json:"component_template"`
642- } `json:"component_templates"`
624+ Template struct {
625+ Mappings struct {
626+ Source * struct {
627+ Mode string `json:"mode"`
628+ } `json:"_source,omitempty"`
629+ } `json:"mappings"`
630+ } `json:"template"`
643631 }
644632
645633 if err := json .NewDecoder (resp .Body ).Decode (& results ); err != nil {
646- return false , fmt .Errorf ("could not decode search results response: %w" , err )
647- }
648-
649- if len (results .ComponentTemplates ) == 0 {
650- logger .Debugf ("no component template %s found for data stream %s" , componentTemplatePackage , dataStream )
651- return false , nil
634+ return false , fmt .Errorf ("could not decode index template simulation response: %w" , err )
652635 }
653- if len (results .ComponentTemplates ) != 1 {
654- return false , fmt .Errorf ("ambiguous response, expected one component template for %s, found %d" , componentTemplatePackage , len (results .ComponentTemplates ))
655- }
656-
657- template := results .ComponentTemplates [0 ]
658636
659- if template . ComponentTemplate .Template .Mappings .Source == nil {
637+ if results .Template .Mappings .Source == nil {
660638 return false , nil
661639 }
662640
663- return template . ComponentTemplate .Template .Mappings .Source .Mode == "synthetic" , nil
641+ return results .Template .Mappings .Source .Mode == "synthetic" , nil
664642}
665643
666644type hits struct {
@@ -962,11 +940,6 @@ func (r *tester) prepareScenario(ctx context.Context, config *testConfig, svcInf
962940 dataStreamDataset ,
963941 ds .Namespace ,
964942 )
965- componentTemplatePackage := fmt .Sprintf (
966- "%s-%s@package" ,
967- ds .Inputs [0 ].Streams [0 ].DataStream .Type ,
968- dataStreamDataset ,
969- )
970943
971944 r .cleanTestScenarioHandler = func (ctx context.Context ) error {
972945 logger .Debugf ("Deleting data stream for testing %s" , scenario .dataStream )
@@ -1130,10 +1103,10 @@ func (r *tester) prepareScenario(ctx context.Context, config *testConfig, svcInf
11301103 return nil , testrunner.ErrTestCaseFailed {Reason : fmt .Sprintf ("could not find hits in %s data stream" , scenario .dataStream )}
11311104 }
11321105
1133- logger .Debugf ("check whether or not synthetics is enabled (component template %s)..." , componentTemplatePackage )
1134- scenario .syntheticEnabled , err = r .isSyntheticsEnabled (ctx , scenario .dataStream , componentTemplatePackage )
1106+ logger .Debugf ("check whether or not synthetics is enabled (data stream %s)..." , scenario . dataStream )
1107+ scenario .syntheticEnabled , err = r .isSyntheticsEnabled (ctx , scenario .dataStream )
11351108 if err != nil {
1136- return nil , fmt .Errorf ("failed to check if synthetic source is enabled: %w" , err )
1109+ return nil , fmt .Errorf ("failed to check if synthetic source is enabled for data stream %s : %w" , scenario . dataStream , err )
11371110 }
11381111 logger .Debugf ("data stream %s has synthetics enabled: %t" , scenario .dataStream , scenario .syntheticEnabled )
11391112
0 commit comments