Skip to content

Commit 34a0f90

Browse files
committed
feat(opensearchapi)!: regenerate with typed string enums
Regenerate opensearchapi and plugins after the osgen string-enum change. Enum-like fields and query parameters that were plain string are now named types with exported consts: NodeRole (cat-nodes, nodes-info), Result and VersionType (write ops), TimeUnit (cat time params), OpType, SearchType, and the rest. NodeRole now carries the search and warm roles. BREAKING CHANGE: fields and query params across opensearchapi and plugins change from string to named enum types (e.g. Roles []string -> []NodeRole, Result string -> Result). Values still assign and compare as strings via the named type; type-strict comparisons against untyped string literals need the const (e.g. opensearchapi.ResultUpdated). Updates the one such hand-written assertion in api_document_lifecycle_test.go. Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent fc88610 commit 34a0f90

77 files changed

Lines changed: 774 additions & 234 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.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

77
### Added
88

9+
- `cmd/osgen`: emit enum-like `oneOf`-of-`{type: string, const: X}` schemas as named Go string types with one exported const per value (e.g. `type NodeRole string` with `NodeRoleData`, `NodeRoleSearch`, `NodeRoleWarm`, ...), instead of collapsing them to a plain `string`. The type is permissive: backed by `string`, `encoding/json` round-trips any value, so an unknown value a newer server or plugin introduces decodes cleanly rather than erroring (unlike the closed int-backed `RestStatus` enum, whose `UnmarshalJSON` rejects unknown values). No custom `(Un)MarshalJSON` is generated; the consts add discoverability, compile-time typo protection, and spec-driven drift detection. Detection is default-on for the const-`oneOf` shape (deny-list to opt out); branches are version-filtered, then reduced to values yielding a valid, unique Go const identifier and deduplicated by generated const name (collapsing `NodeRole`'s duplicate `search` across a version boundary and `TranslogDurability`'s `ASYNC`/`async` casing collision, reporting a dropped distinct value to stderr). Query parameters whose schema is a const-`oneOf` are typed too. Also bundles the `search` and `warm` node roles into the vendored spec ([#998](https://github.com/opensearch-project/opensearch-go/pull/998))
910
- Export the `opensearchapi` and plugin sub-client types (`documentClient` -> `DocumentClient`, `catClient` -> `CatClient`, plugin `roleClient` -> `RoleClient`, etc.), so each sub-client renders its own godoc page with a navigable method list instead of being an unexported type reachable only through a `Client` field. The change is additive and non-breaking: field access (`client.Doc.Get`) is unchanged, the `apiClient`/`client` back-pointer stays unexported so external populated construction remains impossible, and each generated type carries a doc comment noting it must be obtained via `NewClient` (the zero value is not usable). Adds a receiver-to-sub-client map to the `opensearchapi` package doc and generated package docs to the plugin packages that have sub-clients ([#989](https://github.com/opensearch-project/opensearch-go/pull/989))
1011
- Add `VerifyDeadAfter` (`opensearch.Config` / `opensearchtransport.Config`, env override `OPENSEARCH_GO_VERIFY_DEAD_AFTER`): bounds how long a connection proven reachable may still be blindly resurrected as a last-resort "zombie" while dead. Each discovery cycle clears the viability mark on any non-seed connection that has been dead longer than the window, so a node that never recovers stops absorbing requests and must health-check clean again before it is routed to; seed connections are exempt. The env var accepts a boolean (`true` selects the 15m default, `false` disables the expiry) or a `time.ParseDuration` string; the `Config` field follows the `0` = default, `<0` = disabled, `>0` = explicit convention. See `guides/transport-routing.md` (Zombie Connection Resurrection and Connection Viability) and `guides/config-envvars.md`
1112
- Add response observer events to `opensearchtransport.ConnectionObserver`: `OnRequestResponse(RequestResponseEvent)` fired once per request by `Transport.Request` (full-read duration, exact response-byte count) and `OnStreamResponse(StreamResponseEvent)` fired by `Transport.Stream` (time-to-first-byte, Content-Length header). Both events are flat value types passed by value, so the fire path is allocation-free and a nil observer costs nothing; `BaseConnectionObserver` gains no-op defaults so existing observers are unaffected. Adds `opensearchtransport.Transport.Request` (and an `opensearch.Client.Request` passthrough) as the buffered counterpart to `Stream`, through which `opensearch.Execute[T]` now routes
@@ -175,6 +176,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
175176

176177
### Changed
177178

179+
- **BREAKING**: `cmd/osgen` now types enum-like `oneOf`-of-const fields and query parameters across `opensearchapi` and the plugin packages, so fields and params that were `string` change to named enum types (e.g. `Roles []string` -> `Roles []NodeRole`, `Result string` -> `Result Result`, the `cat` `time` param `string` -> `TimeUnit`, and similarly `OpType`, `SearchType`, `VersionType`, ...). Values still assign and compare as strings through the named type, so most call sites are unaffected; only type-strict comparisons against untyped string literals need the const (e.g. `require.Equal(t, opensearchapi.ResultUpdated, resp.Result)` instead of `"updated"`). ([#998](https://github.com/opensearch-project/opensearch-go/pull/998))
178180
- `cmd/osapifix`: map the v4 -> v5 partial-failure type renames from `opensearchapi/UPGRADING_V4_TO_V5.md` in the v4 -> v5 hop, so code walking the per-shard failure slice migrates instead of silently breaking. `ResponseShards` -> `ShardStatistics` and `ResponseShardsFailure` -> `ShardSearchFailure` (dropping the removed `Primary`/`Status` fields) are rewritten; `DocumentError` -> `ErrorRespBase` is reported as a manual semantic followup because the two types share no fields. ([#963](https://github.com/opensearch-project/opensearch-go/pull/963))
179181
- Add a first-class container-provider abstraction to the test harness `Makefile`. `CONTAINER_PROVIDER` is auto-detected by CLI presence in the order Colima -> Rancher Desktop (`rdctl`) -> Docker, and overridable with `CONTAINER_PROVIDER=colima|rancher|docker`. Selecting a provider pins the docker context (`colima` / `rancher-desktop`; the Docker provider leaves the active context alone, and a pre-set `DOCKER_CONTEXT` in the environment is respected), resolves the CLI runtime `$(CTR)` (now `docker` by default for every provider, with `CONTAINER_RUNTIME=nerdctl` as an advanced override), ensures the backing VM/daemon is running via the new `cluster.provider.ensure` target (wired into `cluster.start`), and sets `vm.max_map_count` through the provider's VM (`colima ssh` / `rdctl shell`) or a privileged helper container. Previously `$(CTR)` preferred `nerdctl` whenever it was on `PATH`, so a Rancher-installed `nerdctl` could hijack a Colima session. `make cluster.runtime` now reports the detected provider, docker context, and runtime
180182
- **BREAKING**: Per-request transport metrics (`requests`, `failures`, responses-by-status) are now always collected via lock-free atomics, independent of `EnableMetrics`. `EnableMetrics` now gates only the detailed-metrics snapshot (per-connection, per-policy, and router state returned by `Metrics()`). The responses-by-status counter moved from a mutex-guarded map to a lock-free atomic array. `Metrics()` no longer returns an error when metrics are disabled -- it always returns the per-request counters (callers that branched on `if err != nil` for the disabled case should drop that check). See [`UPGRADING_V5.md`](UPGRADING_V5.md#metrics-error-on-disabled-removed) for migration. ([#891](https://github.com/opensearch-project/opensearch-go/issues/891))

cmd/osgen/rawmessage_allowlist.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ AsynchronousSearchSearch/ext # map
5656
ClusterComponentTemplateNode/_meta # map
5757
ClusterComponentTemplateSummary/_meta # map
5858

59-
# --- cluster.get_decommission_awareness ---
60-
ClusterGetDecommissionAwarenessResp/[entries] # map
61-
6259
# --- cluster.get_settings ---
6360
ClusterGetSettingsResp/defaults # map
6461
ClusterGetSettingsResp/persistent # map
@@ -88,9 +85,6 @@ DeleteByQueryResp/- # bare
8885
# --- explain ---
8986
ExplainRespBodyGet/_source # bare
9087

91-
# --- flow_framework.common ---
92-
FlowFrameworkCommonGetResp/workflows # bare
93-
9488
# --- flow_framework.create ---
9589
FlowFrameworkCommonFlowFrameworkCreate/workflows # bare
9690

@@ -100,6 +94,9 @@ GetResp/workflows # bare
10094
# --- flow_framework.get_status ---
10195
GetStatusResp/- # bare
10296

97+
# --- flow_framework.search ---
98+
FlowFrameworkCommonGetResp/workflows # bare
99+
103100
# --- flow_framework.update ---
104101
FlowFrameworkCommonFlowFrameworkUpdate/workflows # bare
105102

opensearchapi/api_document_lifecycle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func TestManual_DocumentUpdate(t *testing.T) {
193193
BodyReader: strings.NewReader(tt.body),
194194
})
195195
require.NoError(t, err)
196-
require.Equal(t, "updated", resp.Result)
196+
require.Equal(t, opensearchapi.ResultUpdated, resp.Result)
197197
require.Equal(t, index, resp.Index)
198198
require.Equal(t, tt.id, resp.ID)
199199
testutil.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response)

opensearchapi/cat-health_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensearchapi/cat-indices_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensearchapi/cat-nodes_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensearchapi/cat-pending_tasks_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensearchapi/cat-recovery_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensearchapi/cat-segment_replication_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensearchapi/cat-shards_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)