Skip to content

Commit 72545b0

Browse files
authored
Add flag to enable logsdb mode in logs data streams (#1939)
Add a new profile parameter, `stack.logsdb_enabled`, to enable the feature flag that enables the logs index mode in all logs data streams (elastic/elasticsearch#108762), in stacks that support it.
1 parent cd180dd commit 72545b0

File tree

6 files changed

+36
-48
lines changed

6 files changed

+36
-48
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ The following settings are available per profile:
650650
an absolute path, out of the `.elastic-package` directory.
651651
* `stack.kibana_http2_enabled` can be used to control if HTTP/2 should be used in versions of
652652
kibana that support it. Defaults to true.
653+
* `stack.logsdb_enabled` can be set to true to activate the feature flag in Elasticsearch that
654+
enables logs index mode in all data streams that support it. Defaults to false.
653655
* `stack.logstash_enabled` can be set to true to start Logstash and configure it as the
654656
default output for tests using elastic-package. Supported only by the compose provider.
655657
Defaults to false.

internal/profile/_static/config.yml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# Flag to enable apm-server in elastic-package stack profile config
1515
# stack.apm_enabled: true
1616

17+
## Logs DB
18+
# Flag to enable the logs index mode in logs data stream.
19+
# stack.logsdb_enabled: true
20+
1721
## Enable logstash for testing
1822
# Flag to enable logstash in elastic-package stack profile config
1923
# stack.logstash_enabled: true

internal/stack/_static/elasticsearch.yml.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ xpack.security.http.ssl.certificate: "certs/cert.pem"
1313

1414
ingest.geoip.downloader.enabled: false
1515

16-
{{ $version := fact "elasticsearch_version" }}
16+
{{- $version := fact "elasticsearch_version" -}}
17+
{{- $logsdb_enabled := fact "logsdb_enabled" -}}
18+
{{ if (and (eq $logsdb_enabled "true") (not (semverLessThan $version "8.15.0-SNAPSHOT"))) }}
19+
cluster.logsdb.enabled: true
20+
{{- end -}}
21+
1722
{{ if semverLessThan $version "8.0.0" }}
1823
script.max_compilations_rate: "use-context"
1924
script.context.template.max_compilations_rate: "unlimited"

internal/stack/resources.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060
configAPMEnabled = "stack.apm_enabled"
6161
configGeoIPDir = "stack.geoip_dir"
6262
configKibanaHTTP2Enabled = "stack.kibana_http2_enabled"
63+
configLogsDBEnabled = "stack.logsdb_enabled"
6364
configLogstashEnabled = "stack.logstash_enabled"
6465
configSelfMonitorEnabled = "stack.self_monitor_enabled"
6566
)
@@ -158,12 +159,13 @@ func applyResources(profile *profile.Profile, stackVersion string) error {
158159
"username": elasticsearchUsername,
159160
"password": elasticsearchPassword,
160161

162+
"agent_publish_ports": strings.Join(agentPorts, ","),
161163
"apm_enabled": profile.Config(configAPMEnabled, "false"),
162164
"geoip_dir": profile.Config(configGeoIPDir, "./ingest-geoip"),
165+
"kibana_http2_enabled": profile.Config(configKibanaHTTP2Enabled, "true"),
166+
"logsdb_enabled": profile.Config(configLogsDBEnabled, "false"),
163167
"logstash_enabled": profile.Config(configLogstashEnabled, "false"),
164168
"self_monitor_enabled": profile.Config(configSelfMonitorEnabled, "false"),
165-
"agent_publish_ports": strings.Join(agentPorts, ","),
166-
"kibana_http2_enabled": profile.Config(configKibanaHTTP2Enabled, "true"),
167169
})
168170

169171
if err := os.MkdirAll(stackDir, 0755); err != nil {

internal/testrunner/runners/system/tester.go

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

666644
type 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

tools/readme/readme.md.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ The following settings are available per profile:
192192
an absolute path, out of the `.elastic-package` directory.
193193
* `stack.kibana_http2_enabled` can be used to control if HTTP/2 should be used in versions of
194194
kibana that support it. Defaults to true.
195+
* `stack.logsdb_enabled` can be set to true to activate the feature flag in Elasticsearch that
196+
enables logs index mode in all data streams that support it. Defaults to false.
195197
* `stack.logstash_enabled` can be set to true to start Logstash and configure it as the
196198
default output for tests using elastic-package. Supported only by the compose provider.
197199
Defaults to false.

0 commit comments

Comments
 (0)