Skip to content

Commit 4c38619

Browse files
authored
Allow to run Elastic stack with other licenses (#2501)
This PR adds support into elastic-package to run an Elastic stack with a different subscription. By default it keeps the trial subscription. And in this PR it is added support to run an Elastic stack with basic subscription.
1 parent 2282a9e commit 4c38619

File tree

105 files changed

+9357
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+9357
-8
lines changed

.buildkite/pipeline.trigger.integration.tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ STACK_COMMAND_TESTS=(
2222
test-stack-command-8x
2323
test-stack-command-9x
2424
test-stack-command-with-apm-server
25+
test-stack-command-with-basic-subscription
26+
test-stack-command-with-self-monitor
2527
)
2628

2729
for test in "${STACK_COMMAND_TESTS[@]}"; do

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ test-stack-command-with-apm-server:
8484
test-stack-command-with-self-monitor:
8585
SELF_MONITOR_ENABLED=true ./scripts/test-stack-command.sh
8686

87+
test-stack-command-with-basic-subscription:
88+
ELASTIC_SUBSCRIPTION=basic ./scripts/test-stack-command.sh
89+
8790
test-stack-command: test-stack-command-default test-stack-command-7x test-stack-command-800 test-stack-command-8x test-stack-command-9x test-stack-command-with-apm-server
8891

8992
test-check-packages: test-check-packages-with-kind test-check-packages-other test-check-packages-parallel test-check-packages-with-custom-agent test-check-packages-benchmarks test-check-packages-false-positives test-check-packages-with-logstash

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ The following settings are available per profile:
652652
the serverless stack provider.
653653
* `stack.serverless.region` can be used to select the region to use when starting
654654
serverless projects.
655+
* `stack.elastic_subscription` allows to select the Elastic subscription type to be used in the stack.
656+
Currently, it is supported "basic" and "[trial](https://www.elastic.co/guide/en/elasticsearch/reference/current/start-trial.html)",
657+
which enables all subscription features for 30 days. Defaults to "trial".
655658

656659
## Useful environment variables
657660

internal/profile/_static/config.yml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
# stack.agent.ports:
2828
# - 127.0.0.1:1514:1514/udp
2929

30+
## Set license subscription
31+
# stack.elastic_subscription: "basic"

internal/profile/testdata/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
stack.geoip_dir: "/home/foo/Documents/ingest-geoip"
33
stack.apm_enabled: true
44
stack.logstash_enabled: true
5+
stack.elastic_subscription: basic
56

67
# An empty string, should exist, but return empty.
78
other.empty: ""

internal/stack/_static/elasticsearch.yml.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ http.host: "0.0.0.0"
44

55
indices.id_field_data.enabled: true
66

7-
xpack.license.self_generated.type: "trial"
7+
{{ $elastic_subscription := fact "elastic_subscription" }}
8+
xpack.license.self_generated.type: "{{ $elastic_subscription }}"
89
xpack.security.enabled: true
910
xpack.security.authc.api_key.enabled: true
1011
xpack.security.http.ssl.enabled: true

internal/stack/_static/kibana.yml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ xpack.fleet.outputs:
161161
{{- if eq $version "9.0.0-SNAPSHOT" }}
162162
xpack.fleet.internal.registry.kibanaVersionCheckEnabled: false
163163
{{- end }}
164+
165+
logging.loggers:
166+
- name: plugins.fleet
167+
level: debug

internal/stack/resources.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"html/template"
1212
"os"
1313
"path/filepath"
14+
"slices"
1415
"strings"
1516

1617
"github.com/Masterminds/semver/v3"
@@ -57,12 +58,13 @@ const (
5758
elasticsearchUsername = "elastic"
5859
elasticsearchPassword = "changeme"
5960

60-
configAPMEnabled = "stack.apm_enabled"
61-
configGeoIPDir = "stack.geoip_dir"
62-
configKibanaHTTP2Enabled = "stack.kibana_http2_enabled"
63-
configLogsDBEnabled = "stack.logsdb_enabled"
64-
configLogstashEnabled = "stack.logstash_enabled"
65-
configSelfMonitorEnabled = "stack.self_monitor_enabled"
61+
configAPMEnabled = "stack.apm_enabled"
62+
configGeoIPDir = "stack.geoip_dir"
63+
configKibanaHTTP2Enabled = "stack.kibana_http2_enabled"
64+
configLogsDBEnabled = "stack.logsdb_enabled"
65+
configLogstashEnabled = "stack.logstash_enabled"
66+
configSelfMonitorEnabled = "stack.self_monitor_enabled"
67+
configElasticSubscription = "stack.elastic_subscription"
6668
)
6769

6870
var (
@@ -135,6 +137,11 @@ var (
135137
Content: staticSource.File("_static/Dockerfile.logstash"),
136138
},
137139
}
140+
141+
elasticSubscriptionsSupported = []string{
142+
"basic",
143+
"trial",
144+
}
138145
)
139146

140147
func applyResources(profile *profile.Profile, stackVersion string) error {
@@ -145,6 +152,11 @@ func applyResources(profile *profile.Profile, stackVersion string) error {
145152
return fmt.Errorf("failed to unmarshal stack.agent.ports: %w", err)
146153
}
147154

155+
elasticSubscriptionProfile := profile.Config(configElasticSubscription, "trial")
156+
if !slices.Contains(elasticSubscriptionsSupported, elasticSubscriptionProfile) {
157+
return fmt.Errorf("unsupported Elastic subscription %q: supported subscriptions: %s", elasticSubscriptionProfile, strings.Join(elasticSubscriptionsSupported, ", "))
158+
}
159+
148160
resourceManager := resource.NewManager()
149161
resourceManager.AddFacter(resource.StaticFacter{
150162
"registry_base_image": PackageRegistryBaseImage,
@@ -168,6 +180,7 @@ func applyResources(profile *profile.Profile, stackVersion string) error {
168180
"logsdb_enabled": profile.Config(configLogsDBEnabled, "false"),
169181
"logstash_enabled": profile.Config(configLogstashEnabled, "false"),
170182
"self_monitor_enabled": profile.Config(configSelfMonitorEnabled, "false"),
183+
"elastic_subscription": elasticSubscriptionProfile,
171184
})
172185

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

scripts/test-stack-command.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -euxo pipefail
55
VERSION=${1:-default}
66
APM_SERVER_ENABLED=${APM_SERVER_ENABLED:-false}
77
SELF_MONITOR_ENABLED=${SELF_MONITOR_ENABLED:-false}
8+
ELASTIC_SUBSCRIPTION=${ELASTIC_SUBSCRIPTION:-""}
89

910
cleanup() {
1011
r=$?
@@ -23,6 +24,10 @@ cleanup() {
2324
elastic-package profiles delete with-self-monitor
2425
fi
2526

27+
if [[ "${ELASTIC_SUBSCRIPTION}" != "" ]]; then
28+
elastic-package profiles delete with-elastic-subscription
29+
fi
30+
2631
exit $r
2732
}
2833

@@ -71,6 +76,16 @@ stack.self_monitor_enabled: true
7176
EOF
7277
fi
7378

79+
if [[ "${ELASTIC_SUBSCRIPTION}" != "" ]]; then
80+
profile=with-elastic-subscription
81+
elastic-package profiles create -v ${profile}
82+
elastic-package profiles use ${profile}
83+
84+
cat ~/.elastic-package/profiles/${profile}/config.yml.example - <<EOF > ~/.elastic-package/profiles/${profile}/config.yml
85+
stack.elastic_subscription: ${ELASTIC_SUBSCRIPTION}
86+
EOF
87+
fi
88+
7489
mkdir -p "${OUTPUT_PATH_STATUS}"
7590

7691
# Initial status empty
@@ -115,6 +130,8 @@ elastic-package stack status -v 2> "${OUTPUT_PATH_STATUS}/running.txt"
115130
clean_status_output "${OUTPUT_PATH_STATUS}/expected_running.txt" > "${OUTPUT_PATH_STATUS}/expected_no_spaces.txt"
116131
clean_status_output "${OUTPUT_PATH_STATUS}/running.txt" > "${OUTPUT_PATH_STATUS}/running_no_spaces.txt"
117132

133+
diff -q "${OUTPUT_PATH_STATUS}/running_no_spaces.txt" "${OUTPUT_PATH_STATUS}/expected_no_spaces.txt"
134+
118135
if [ "${APM_SERVER_ENABLED}" = true ]; then
119136
curl http://localhost:8200/
120137
fi
@@ -127,4 +144,17 @@ if [ "${SELF_MONITOR_ENABLED}" = true ]; then
127144
-f "${ELASTIC_PACKAGE_ELASTICSEARCH_HOST}/metrics-system.*/_search?allow_no_indices=false&size=0"
128145
fi
129146

130-
diff -q "${OUTPUT_PATH_STATUS}/running_no_spaces.txt" "${OUTPUT_PATH_STATUS}/expected_no_spaces.txt"
147+
subscription=$(curl -s -S \
148+
-u "${ELASTIC_PACKAGE_ELASTICSEARCH_USERNAME}:${ELASTIC_PACKAGE_ELASTICSEARCH_PASSWORD}" \
149+
--cacert "${ELASTIC_PACKAGE_CA_CERT}" \
150+
-f "${ELASTIC_PACKAGE_ELASTICSEARCH_HOST}/_license" |jq -r '.license.type')
151+
152+
expected_subscription="trial"
153+
if [[ "${ELASTIC_SUBSCRIPTION}" != "" ]]; then
154+
expected_subscription="${ELASTIC_SUBSCRIPTION}"
155+
fi
156+
157+
if [[ "${subscription}" != "${expected_subscription}" ]]; then
158+
echo "Unexpected \"${subscription}\" subscription found, but expected \"${expected_subscription}\""
159+
exit 1
160+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stack.elastic_subscription=basic

0 commit comments

Comments
 (0)