Skip to content

Commit d17b5b0

Browse files
committed
fix tests
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent da86565 commit d17b5b0

44 files changed

Lines changed: 898 additions & 281 deletions

Some content is hidden

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

.ci/opensearch/Dockerfile.opensearch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG OPENSEARCH_VERSION
1+
ARG OPENSEARCH_VERSION=latest
22
FROM opensearchproject/opensearch:${OPENSEARCH_VERSION}
33

44
ARG opensearch_path=/usr/share/opensearch

.ci/opensearch/docker-compose.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ services:
1313
environment:
1414
- cluster.name=opensearch-cluster
1515
- node.name=opensearch-node1
16-
- node.roles=cluster_manager,data,ingest
16+
- node.roles=${OPENSEARCH_MANAGER_ROLE:-cluster_manager},data,ingest
1717
- discovery.seed_hosts=opensearch-node1,opensearch-node2,opensearch-node3
18-
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2,opensearch-node3
18+
- cluster.initial_${OPENSEARCH_MANAGER_SETTING:-cluster_manager}_nodes=opensearch-node1,opensearch-node2,opensearch-node3
1919
- bootstrap.memory_lock=false # Disable memory locking for development
2020
- path.repo=/usr/share/opensearch/mnt
2121
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
@@ -28,7 +28,7 @@ services:
2828
- http.publish_host=localhost
2929
- http.publish_port=9200
3030
# Memory settings
31-
- OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
31+
- OPENSEARCH_JAVA_OPTS=-Xms${OPENSEARCH_HEAP_SIZE:-1g} -Xmx${OPENSEARCH_HEAP_SIZE:-1g}
3232
ports:
3333
- "9200:9200"
3434
- "9300:9300"
@@ -57,9 +57,9 @@ services:
5757
environment:
5858
- cluster.name=opensearch-cluster
5959
- node.name=opensearch-node2
60-
- node.roles=cluster_manager,data,ingest
60+
- node.roles=${OPENSEARCH_MANAGER_ROLE:-cluster_manager},data,ingest
6161
- discovery.seed_hosts=opensearch-node1,opensearch-node2,opensearch-node3
62-
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2,opensearch-node3
62+
- cluster.initial_${OPENSEARCH_MANAGER_SETTING:-cluster_manager}_nodes=opensearch-node1,opensearch-node2,opensearch-node3
6363
- bootstrap.memory_lock=false # Disable memory locking for development
6464
- path.repo=/usr/share/opensearch/mnt
6565
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
@@ -72,7 +72,7 @@ services:
7272
- http.publish_host=localhost
7373
- http.publish_port=9201
7474
# Memory settings
75-
- OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
75+
- OPENSEARCH_JAVA_OPTS=-Xms${OPENSEARCH_HEAP_SIZE:-1g} -Xmx${OPENSEARCH_HEAP_SIZE:-1g}
7676
ports:
7777
- "9201:9200"
7878
- "9301:9300"
@@ -101,9 +101,9 @@ services:
101101
environment:
102102
- cluster.name=opensearch-cluster
103103
- node.name=opensearch-node3
104-
- node.roles=cluster_manager,data,ingest
104+
- node.roles=${OPENSEARCH_MANAGER_ROLE:-cluster_manager},data,ingest
105105
- discovery.seed_hosts=opensearch-node1,opensearch-node2,opensearch-node3
106-
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2,opensearch-node3
106+
- cluster.initial_${OPENSEARCH_MANAGER_SETTING:-cluster_manager}_nodes=opensearch-node1,opensearch-node2,opensearch-node3
107107
- bootstrap.memory_lock=false # Disable memory locking for development
108108
- path.repo=/usr/share/opensearch/mnt
109109
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
@@ -116,7 +116,7 @@ services:
116116
- http.publish_host=localhost
117117
- http.publish_port=9202
118118
# Memory settings
119-
- OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
119+
- OPENSEARCH_JAVA_OPTS=-Xms${OPENSEARCH_HEAP_SIZE:-1g} -Xmx${OPENSEARCH_HEAP_SIZE:-1g}
120120
ports:
121121
- "9202:9200"
122122
- "9302:9300"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ tmp/
66
.vscode
77
bin/
88

9-
.DS_Store
9+
.DS_Store
10+
# Admin certificates for testing
11+
admin.pem
12+
admin.key

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4343
### Fixed
4444

4545
- Fix flaky connection integration test by replacing arbitrary sleep times with proper server readiness polling
46+
- Fix OpenSearch 2.8.0+ Tasks API compatibility by adding cancellation_time_millis field to TasksListTask struct
4647
- Fix OpenSearch 3.1.0+ API compatibility by adding phase_results_processors field to nodes API and time_in_execution fields to cluster pending tasks API
4748
- Fix OpenSearch 3.2.0+ API compatibility by adding max_last_index_request_timestamp and startree query fields across nodes stats, indices stats, and cat APIs, plus settings field to security plugin health API
4849
- Fix OpenSearch 3.3.0+ API compatibility by adding neural_search breaker, query_failed and startree_query_failed search fields, search pipeline system_generated fields across multiple APIs, plus ingestion_status field to cluster state API and jwks_uri field to security config API

Makefile

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ endif
3333
ifdef race
3434
$(eval testintegargs += "-race")
3535
endif
36-
$(eval testintegargs += "-cover" "-tags=$(testintegtags)" "-timeout=1h" "./..." "-args" "-test.gocoverdir=$(PWD)/tmp/integration")
36+
$(eval TEST_PARALLEL ?= $(shell ncpu=$$(go env GOMAXPROCS 2>/dev/null); [ -z "$$ncpu" ] && ncpu=$$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4); parallel=$$((ncpu - 1)); [ $$parallel -lt 1 ] && parallel=1; echo $$parallel))
37+
$(eval testintegargs += "-cover" "-tags=$(testintegtags)" "-timeout=10m" "-parallel=$(TEST_PARALLEL)" "./..." "-args" "-test.gocoverdir=$(PWD)/tmp/integration")
3738
@mkdir -p $(PWD)/tmp/integration
3839
@echo "go test -v" $(testintegargs); \
3940
go test -v $(testintegargs);
@@ -126,10 +127,10 @@ lint.markdown:
126127
npm install -g $(package) --no-shrinkwrap; \
127128
fi
128129
@printf "\033[2m-> Running markdown lint...\033[0m\n"
129-
if npx $(package) --prose-wrap never --check **/*.md; [[ $$? -ne 0 ]]; then \
130+
if npx $(package) --prose-wrap never --check **/*.md; [ $$? -ne 0 ]; then \
130131
echo -e "\033[32m-> Found invalid files. Want to auto-format invalid files? (y/n) \033[0m"; \
131132
read RESP; \
132-
if [[ $$RESP = "y" || $$RESP = "Y" ]]; then \
133+
if [ "$$RESP" = "y" ] || [ "$$RESP" = "Y" ]; then \
133134
echo -e "\033[33m Formatting...\033[0m"; \
134135
npx $(package) --prose-wrap never --write **/*.md; \
135136
echo -e "\033[34m \nAll invalid files are formatted\033[0m"; \
@@ -197,7 +198,7 @@ endif
197198
set -e -o pipefail; \
198199
printf "\033[2m-> Commit and create Git tag? (y/n): \033[0m\c"; \
199200
read continue; \
200-
if [[ $$continue == "y" ]]; then \
201+
if [ "$$continue" = "y" ]; then \
201202
git add internal/version/version.go && \
202203
git commit --no-status --quiet --message "Release $(version)" && \
203204
git tag --annotate v$(version) --message 'Release $(version)'; \
@@ -225,14 +226,57 @@ godoc: ## Display documentation for the package
225226
godoc --http=localhost:6060 --play
226227

227228
cluster.build:
228-
docker compose --project-directory .ci/opensearch build --pull;
229+
@$(MAKE) cluster.docker-build
229230

230231
cluster.start:
231-
docker compose --project-directory .ci/opensearch up -d;
232+
@$(MAKE) cluster.docker-up
233+
@$(MAKE) cluster.get-cert
232234

233235
cluster.stop:
234236
docker compose --project-directory .ci/opensearch down;
235237

238+
cluster.docker-build:
239+
@# Determine version-specific settings
240+
$(eval OPENSEARCH_VERSION ?= latest)
241+
$(eval version_major := $(shell \
242+
if [ "$(OPENSEARCH_VERSION)" = "latest" ]; then \
243+
echo "2"; \
244+
else \
245+
echo "$(OPENSEARCH_VERSION)" | awk -F. '{print $$1}'; \
246+
fi \
247+
))
248+
$(eval manager_role := $(shell \
249+
if [ "$(version_major)" = "1" ]; then \
250+
echo "master"; \
251+
else \
252+
echo "cluster_manager"; \
253+
fi \
254+
))
255+
@echo "Building OpenSearch $(OPENSEARCH_VERSION) with role: $(manager_role)"
256+
OPENSEARCH_MANAGER_ROLE=$(manager_role) OPENSEARCH_MANAGER_SETTING=$(manager_role) \
257+
docker compose --project-directory .ci/opensearch build --pull
258+
259+
cluster.docker-up:
260+
@# Determine version-specific settings
261+
$(eval OPENSEARCH_VERSION ?= latest)
262+
$(eval version_major := $(shell \
263+
if [ "$(OPENSEARCH_VERSION)" = "latest" ]; then \
264+
echo "2"; \
265+
else \
266+
echo "$(OPENSEARCH_VERSION)" | awk -F. '{print $$1}'; \
267+
fi \
268+
))
269+
$(eval manager_role := $(shell \
270+
if [ "$(version_major)" = "1" ]; then \
271+
echo "master"; \
272+
else \
273+
echo "cluster_manager"; \
274+
fi \
275+
))
276+
@echo "Starting OpenSearch $(OPENSEARCH_VERSION) with role: $(manager_role)"
277+
OPENSEARCH_MANAGER_ROLE=$(manager_role) OPENSEARCH_MANAGER_SETTING=$(manager_role) \
278+
docker compose --project-directory .ci/opensearch up -d
279+
236280
cluster.scale.1: ## Start single-node cluster
237281
docker compose --project-directory .ci/opensearch up -d --scale opensearch-node2=0 --scale opensearch-node3=0;
238282

@@ -243,14 +287,24 @@ cluster.scale.3: ## Start full 3-node cluster
243287
docker compose --project-directory .ci/opensearch up -d --scale opensearch-node1=1 --scale opensearch-node2=1 --scale opensearch-node3=1;
244288

245289
cluster.get-cert:
246-
@if [[ -v SECURE_INTEGRATION ]] && [[ $$SECURE_INTEGRATION == "true" ]]; then \
247-
docker cp $$(docker compose --project-directory .ci/opensearch ps --format '{{.Name}}' | head -1):/usr/share/opensearch/config/kirk.pem admin.pem && \
248-
docker cp $$(docker compose --project-directory .ci/opensearch ps --format '{{.Name}}' | head -1):/usr/share/opensearch/config/kirk-key.pem admin.key; \
290+
@if [ -n "$${SECURE_INTEGRATION}" ] && [ "$${SECURE_INTEGRATION}" = "true" ]; then \
291+
CONTAINER=$$(docker compose --project-directory .ci/opensearch ps --format '{{.Name}}' | head -1); \
292+
if [ -z "$$CONTAINER" ]; then \
293+
echo "Error: No OpenSearch containers running. Start cluster first with 'make cluster.start'"; \
294+
exit 1; \
295+
fi; \
296+
docker cp $$CONTAINER:/usr/share/opensearch/config/kirk.pem admin.pem && \
297+
docker cp $$CONTAINER:/usr/share/opensearch/config/kirk-key.pem admin.key; \
249298
fi
250299

251300

252301
cluster.clean: ## Remove unused Docker volumes and networks
253302
@printf "\033[2m-> Cleaning up Docker assets...\033[0m\n"
303+
@# Remove OpenSearch built images to ensure clean rebuilds when switching versions
304+
@docker images -q opensearch-opensearch-node* | xargs -r docker rmi -f || true
305+
@# Remove OpenSearch volumes to clear stale data
306+
@docker volume ls -q --filter "name=opensearch" | xargs -r docker volume rm || true
307+
@# Clean up unused Docker resources
254308
docker volume prune --force
255309
docker network prune --force
256310
docker system prune --volumes --force
@@ -281,5 +335,5 @@ help: ## Display help
281335
#------------- <https://suva.sh/posts/well-documented-makefiles> --------------
282336

283337
.DEFAULT_GOAL := help
284-
.PHONY: help backport cluster cluster.clean coverage godoc lint lint.local release test test-all test-race test-bench test-integ test-unit linters linters.install
338+
.PHONY: help backport cluster.build cluster.start cluster.stop cluster.docker-build cluster.docker-up cluster.clean coverage godoc lint lint.local release test test-all test-race test-bench test-integ test-unit linters linters.install
285339
.SILENT: lint.markdown

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ require (
3030
github.com/tidwall/match v1.1.1 // indirect
3131
github.com/tidwall/pretty v1.2.1 // indirect
3232
github.com/tidwall/sjson v1.2.5 // indirect
33+
golang.org/x/mod v0.33.0 // indirect
3334
gopkg.in/yaml.v3 v3.0.1 // indirect
3435
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
5252
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
5353
github.com/wI2L/jsondiff v0.7.0 h1:1lH1G37GhBPqCfp/lrs91rf/2j3DktX6qYAKZkLuCQQ=
5454
github.com/wI2L/jsondiff v0.7.0/go.mod h1:KAEIojdQq66oJiHhDyQez2x+sRit0vIzC9KeK0yizxM=
55+
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
56+
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
5557
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
5658
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5759
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=

internal/test/config.go

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ package ostest
88

99
import (
1010
"crypto/tls"
11+
"fmt"
1112
"net/http"
1213
"os"
1314

15+
"golang.org/x/mod/semver"
16+
1417
"github.com/opensearch-project/opensearch-go/v4"
1518
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
1619
)
1720

21+
const (
22+
// OpenSearch default admin passwords
23+
defaultPasswordPre212 = "admin" // Default admin password in OpenSearch < 2.12.0
24+
defaultPasswordPost212 = "myStrongPassword123!" // Default admin password in OpenSearch >= 2.12.0
25+
26+
// Version where default admin password changed
27+
defaultPasswordChangeVersion = "v2.12.0"
28+
)
29+
1830
// IsSecure returns true when SECURE_INTEGRATION env is set to true
1931
func IsSecure() bool {
2032
return os.Getenv("SECURE_INTEGRATION") == "true"
@@ -48,25 +60,61 @@ func ClientConfig() (*opensearchapi.Config, error) {
4860
}, nil
4961
}
5062

51-
// GetPassword returns the password suited for the opensearch version
63+
// GetPassword returns the admin password for the opensearch version.
64+
// OpenSearch 2.12.0+ changed the default admin password from "admin" to "myStrongPassword123!".
65+
//
66+
// Note: This function tries to determine the correct password based on OPENSEARCH_VERSION env var.
67+
// If the env var doesn't match the actual running cluster, authentication may fail.
5268
func GetPassword() (string, error) {
53-
var (
54-
major, minor int64
55-
err error
56-
)
57-
password := "admin"
5869
version := os.Getenv("OPENSEARCH_VERSION")
5970

60-
if version != "latest" && version != "" {
61-
major, minor, _, err = opensearch.ParseVersion(version)
62-
if err != nil {
63-
return "", err
71+
// Default to pre-2.12 password for empty version or versions < 2.12.0
72+
password := defaultPasswordPre212
73+
74+
if version == "latest" {
75+
// Latest uses the post-2.12 default password
76+
password = defaultPasswordPost212
77+
} else if version != "" {
78+
// Normalize version to semver format (v2.12.0)
79+
if version[0] != 'v' {
80+
version = "v" + version
81+
}
82+
83+
// Validate semver format
84+
if !semver.IsValid(version) {
85+
return "", fmt.Errorf("invalid version format: %s", version)
6486
}
65-
if version == "latest" || major > 2 || (major == 2 && minor >= 12) {
66-
password = "myStrongPassword123!"
87+
88+
// OpenSearch 2.12.0+ uses the new default password
89+
if semver.Compare(version, defaultPasswordChangeVersion) >= 0 {
90+
password = defaultPasswordPost212
6791
}
68-
} else {
69-
password = "myStrongPassword123!"
7092
}
93+
7194
return password, nil
7295
}
96+
97+
// GetPasswordForCluster returns the admin password by trying to detect the actual cluster version.
98+
// This is more reliable than GetPassword() when OPENSEARCH_VERSION env var might not match reality.
99+
// It returns both possible passwords to try in order.
100+
func GetPasswordForCluster() []string {
101+
version := os.Getenv("OPENSEARCH_VERSION")
102+
103+
// If version is set and valid, trust it
104+
if version != "" && version != "latest" {
105+
if version[0] != 'v' {
106+
version = "v" + version
107+
}
108+
if semver.IsValid(version) {
109+
if semver.Compare(version, defaultPasswordChangeVersion) >= 0 {
110+
// For 2.12+, try post-2.12 password first, then fallback to pre-2.12
111+
return []string{defaultPasswordPost212, defaultPasswordPre212}
112+
}
113+
// For < 2.12, try pre-2.12 password first, then fallback to post-2.12
114+
return []string{defaultPasswordPre212, defaultPasswordPost212}
115+
}
116+
}
117+
118+
// Unknown or latest version: try pre-2.12 password first (most common), then post-2.12
119+
return []string{defaultPasswordPre212, defaultPasswordPost212}
120+
}

0 commit comments

Comments
 (0)