Skip to content

Commit 9eed25c

Browse files
authored
Migrate to v5 API (#867)
Update `opensearch-go` to use `v5`-native APIs and deprecate v4 primitives. The previously-previewed generated client is promoted to the canonical `opensearchapi/` package, the module path moves to `/v5`, and intelligent request routing plus partial-failure error reporting become the defaults. ### Breaking changes - **Module path** is now `github.com/opensearch-project/opensearch-go/v5`. Update import paths from `/v4` to `/v5`; the in-source `opensearchapi.X` qualifier is unchanged. - **Canonical `opensearchapi/` is code-generated** by `cmd/osgen` from the OpenSearch API specification, replacing the hand-written v4 package (formerly previewed at `v5preview/opensearchapi/`). Field-level deltas (`DocumentID` -> `ID`, optional `Params` becoming `*Params`, shared params moving into embedded `TimeoutParams`/`DebugParams`, `BulkResp.Items` becoming `[]BulkItem`) are documented in `opensearchapi/MIGRATING.md`. - **Plugin import paths** move to `github.com/opensearch-project/opensearch-go/v5/plugins/<name>`; generated clients cover all 25 plugins. - **Default Router is on** unless `OPENSEARCH_GO_ROUTER=false`. In v4 the router was opt-in. - **Partial-failure errors are reported by default** (`Config.Errors == nil` resolves to `errmask.Empty`). Set `errmask.New(errmask.All)` or `OPENSEARCH_GO_ERROR_MASK` to restore v4-style masking. ### Highlights - Group document operations under `client.Doc` and point-in-time operations under `client.PIT`; `client.Document`/`client.PointInTime` remain as aliases. The indices sub-client is `client.Index` (with `client.Indices`/`Indexes` aliases). Thin v4-compat forwarders keep top-level `client.Bulk`/`MGet`/`Update` working. - Generate query parameters whose value `0` is meaningful (`if_seq_no`/ `if_primary_term` on `delete`/`index`/`update` and the plugin policy writes, plus `size` on `search`) as `*int` so a deliberate `0` reaches the wire. - Treat OpenSearch plugin acronyms (ISM/KNN/LTR/ML/PPL/SM/UBI/WLM) as initialisms so generated identifiers are all-uppercase per Go convention. - Transport/signer correctness from #859: close error-response bodies, classify `Perform` body-read errors via a sentinel, drain bodies on raw `RoundTrip` paths, and close request bodies on signer read errors. `Client.Do` buffers response payloads into `rawBody` and `Response.String()` is non-consuming. - Add a `build-samples` Makefile target and CI job so `_samples/*.go` (excluded from `go build ./...`) can no longer break silently. ### Docs Migration guidance in `opensearchapi/MIGRATING.md`, `UPGRADING.md`, and the `guides/` tree; a copy-paste least-privilege cluster role for routing and discovery in `guides/security.md`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check [here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).
1 parent fdf85c4 commit 9eed25c

2,712 files changed

Lines changed: 47829 additions & 92114 deletions

File tree

Some content is hidden

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

.codecov.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ coverage:
2929
opensearchapi:
3030
paths:
3131
- "opensearchapi/"
32-
target: 14%
33-
threshold: 2%
34-
opensearchapiv5:
35-
paths:
36-
- "v5preview/opensearchapi/"
3732
target: 25%
3833
threshold: 5%
3934
patch: off

.github/workflows/check-gen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: make -j gen
1818
- name: Check for diff
1919
run: |
20-
if ! git diff --exit-code internal/path/builders_gen.go internal/path/builders_gen_test.go v5preview/opensearchapi/; then
20+
if ! git diff --exit-code internal/path/builders_gen.go internal/path/builders_gen_test.go opensearchapi/ plugins/; then
2121
echo "::warning::Generated code is out of date. Run 'make gen' and commit the result."
2222
exit 1
2323
fi

.github/workflows/test-compatibility.yml

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,28 @@ env:
88
jobs:
99
integ-test-compat:
1010
runs-on: ubuntu-latest
11-
continue-on-error: ${{ matrix.entry.opensearch_version == 'latest' }}
11+
continue-on-error: ${{ matrix.opensearch_version == 'latest' }}
1212
strategy:
1313
fail-fast: false
14-
# OpenSearch <=2.17.x carries a node-join/node-left race condition
15-
# (fixed in 2.18 via opensearch-project/OpenSearch#15521, backported
16-
# via opensearch-project/OpenSearch#16118) that leaves a node in
17-
# cluster state but disconnected at the transport layer, breaking
18-
# NodesStats RPC fan-out indefinitely and hanging /_cat/nodes-based
19-
# readiness gates. Single-node clusters cannot hit the race, so
20-
# affected versions run with OPENSEARCH_NODE_COUNT=1 below.
14+
# The supported set tracks the OpenSearch releases still receiving patches
15+
# within the last 12 months at each opensearch-go release: every release of
16+
# the current major plus the latest release of the previous major. Today
17+
# that is 2.19.x and all of 3.x. See opensearch-project/opensearch-go#856.
18+
# Re-evaluate this list at each release. All supported lines run as 3-node
19+
# clusters.
2120
matrix:
2221
secured: ["true", "false"]
23-
entry:
24-
- { opensearch_version: 1.3.20, node_count: 1 }
25-
- { opensearch_version: 2.0.1, node_count: 1 }
26-
- { opensearch_version: 2.1.0, node_count: 1 }
27-
- { opensearch_version: 2.2.1, node_count: 1 }
28-
- { opensearch_version: 2.3.0, node_count: 1 }
29-
- { opensearch_version: 2.4.1, node_count: 1 }
30-
- { opensearch_version: 2.5.0, node_count: 1 }
31-
- { opensearch_version: 2.6.0, node_count: 1 }
32-
- { opensearch_version: 2.7.0, node_count: 1 }
33-
- { opensearch_version: 2.8.0, node_count: 1 }
34-
- { opensearch_version: 2.9.0, node_count: 1 }
35-
- { opensearch_version: 2.10.0, node_count: 1 }
36-
- { opensearch_version: 2.11.1, node_count: 1 }
37-
- { opensearch_version: 2.12.0, node_count: 1 }
38-
- { opensearch_version: 2.13.0, node_count: 1 }
39-
- { opensearch_version: 2.14.0, node_count: 1 }
40-
- { opensearch_version: 2.15.0, node_count: 1 }
41-
- { opensearch_version: 2.16.0, node_count: 1 }
42-
- { opensearch_version: 2.17.1, node_count: 1 }
43-
- { opensearch_version: 2.18.0, node_count: 3 }
44-
- { opensearch_version: 2.19.5, node_count: 3 }
45-
- { opensearch_version: 3.0.0, node_count: 3 }
46-
- { opensearch_version: 3.1.0, node_count: 3 }
47-
- { opensearch_version: 3.2.0, node_count: 3 }
48-
- { opensearch_version: 3.3.2, node_count: 3 }
49-
- { opensearch_version: 3.4.0, node_count: 3 }
50-
- { opensearch_version: 3.5.0, node_count: 3 }
51-
- { opensearch_version: 3.6.0, node_count: 3 }
52-
- { opensearch_version: latest, node_count: 3 }
22+
opensearch_version:
23+
- 2.19.5
24+
- 3.0.0
25+
- 3.1.0
26+
- 3.2.0
27+
- 3.3.2
28+
- 3.4.0
29+
- 3.5.0
30+
- 3.6.0
31+
- 3.7.0
32+
- latest
5333
steps:
5434
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
5535

@@ -67,19 +47,13 @@ jobs:
6747
6848
- name: Launch OpenSearch cluster
6949
run: |
70-
export OPENSEARCH_VERSION=${{ matrix.entry.opensearch_version }}
50+
export OPENSEARCH_VERSION=${{ matrix.opensearch_version }}
7151
export SECURE_INTEGRATION=${{ matrix.secured }}
72-
export OPENSEARCH_NODE_COUNT=${{ matrix.entry.node_count }}
52+
export OPENSEARCH_NODE_COUNT=3
7353
make cluster.clean cluster.build cluster.start
7454
if [ "${SECURE_INTEGRATION}" = "true" ]; then
7555
CURL_URL="https://localhost:9200"
76-
# Password changed in OpenSearch 2.12.0
77-
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
78-
if [ $(version ${OPENSEARCH_VERSION}) -ge $(version "2.12.0") ] || [ "${OPENSEARCH_VERSION}" = "latest" ]; then
79-
CURL_OPTS="-sfku admin:myStrongPassword123!"
80-
else
81-
CURL_OPTS="-sfku admin:admin"
82-
fi
56+
CURL_OPTS="-sfku admin:myStrongPassword123!"
8357
else
8458
CURL_URL="http://localhost:9200"
8559
CURL_OPTS="-sf"
@@ -113,9 +87,9 @@ jobs:
11387
11488
- name: Integration test
11589
run: |
116-
export OPENSEARCH_VERSION=${{ matrix.entry.opensearch_version }}
90+
export OPENSEARCH_VERSION=${{ matrix.opensearch_version }}
11791
export SECURE_INTEGRATION=${{ matrix.secured }}
118-
export OPENSEARCH_NODE_COUNT=${{ matrix.entry.node_count }}
92+
export OPENSEARCH_NODE_COUNT=3
11993
make cluster.get-cert test-integ-core test-integ-plugins race=true
12094
12195
- name: Stop the OpenSearch cluster

.github/workflows/test-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
env:
66
GITHUB_ACTIONS: true
7-
OPENSEARCH_VERSION: 3.6.0
7+
OPENSEARCH_VERSION: 3.7.0
88
OPENSEARCH_NODE_COUNT: 3
99
SECURE_INTEGRATION: true
1010
CONTAINER_RUNTIME: docker

.github/workflows/test-unit.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ jobs:
3838
with: { go-version-file: 'go.mod' }
3939
- run: go version
4040
- run: make test-bench
41+
42+
samples:
43+
name: Build samples
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
47+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
48+
with: { go-version-file: 'go.mod' }
49+
- run: go version
50+
- run: make build-samples
51+

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ linters:
162162
path: opensearchtransport/opensearchtransport.go
163163
- linters:
164164
- dupl
165-
path: (-params\.go|api_indices|api_dangling\.go|api_point_in_time\.go|rethrottle\.go|api_cat-.*\.go|plugins/security/api_\w+.go|plugins/security/api_.*-patch.go|_gen\.go)
165+
path: (-params\.go|api_indices|api_dangling\.go|api_point_in_time\.go|rethrottle\.go|api_cat-.*\.go|_gen\.go)
166166
# Generated code emits long lines from upstream spec descriptions, table
167167
# rows, and inline struct literals that lose readability if wrapped at the
168168
# template level.
169169
- linters:
170170
- lll
171-
path: _integ_gen_test\.go|internal/path/builders_gen(_test)?\.go|v5preview/opensearchapi/.*_gen\.go
171+
path: _integ_gen_test\.go|internal/path/builders_gen(_test)?\.go|opensearchapi/.*_gen\.go
172172
paths:
173173
- third_party$
174174
- builtin$

0 commit comments

Comments
 (0)