diff --git a/CHANGELOG.md b/CHANGELOG.md index 132572896..c3daf661a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fixes empty request body on retry with compression enabled ([#543](https://github.com/opensearch-project/opensearch-go/pull/543)) +- Fixes `Conditions` in `PolicyStateTransition` of ISM plugin ([#556](https://github.com/opensearch-project/opensearch-go/pull/556)) ### Security @@ -118,7 +119,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Solves linting complains for opensearchtransport ([#353](https://github.com/opensearch-project/opensearch-go/pull/353)) - Updates Developer guide to include docker build instructions ([#385](https://github.com/opensearch-project/opensearch-go/pull/385)) - Tests against version 2.9.0, 2.10.0, run tests in all branches, changes integration tests to wait for OpenSearch to start ([#392](https://github.com/opensearch-project/opensearch-go/pull/392)) -- Makefile: uses docker golangci-lint, run integration test on `.` folder, change coverage generation ([#392](https://github.com/opensearch-project/opensearch-go/pull/392)) +- Makefile: uses docker golangci-lint, run integration test on `.` folder, change coverage generation ([#392](https://github.com/opensearch-project/opensearch-go/pull/392)) - golangci-lint: updates rules and fail when issues are found ([#421](https://github.com/opensearch-project/opensearch-go/pull/421)) - go: updates to golang version 1.20 ([#421](https://github.com/opensearch-project/opensearch-go/pull/421)) - guids: updates to work for the new opensearchapi ([#421](https://github.com/opensearch-project/opensearch-go/pull/421)) diff --git a/plugins/ism/api_policies.go b/plugins/ism/api_policies.go index 8c78f09a7..523cc1e6b 100644 --- a/plugins/ism/api_policies.go +++ b/plugins/ism/api_policies.go @@ -246,17 +246,23 @@ type PolicyStateRollup struct { } `json:"ism_rollup"` } -// PolicyStateTransition is a sub type of PolicyState containing information about transitios to other states +// PolicyStateTransitionCondition is a sub type of PolicyStateTransition containing conditions for a transition +type PolicyStateTransitionCondition struct { + MinIndexAge string `json:"min_index_age,omitempty"` + MinRolloverAge string `json:"min_rollover_age,omitempty"` + MinDocCount int `json:"min_doc_count,omitempty"` + MinSize string `json:"min_size,omitempty"` + Cron *PolicyStateTransitionConditionCron `json:"cron,omitempty"` +} + +// PolicyStateTransitionConditionCron is a sub type of PolicyStateTransitionCondition containing a cron expression and timezone +type PolicyStateTransitionConditionCron struct { + Expression string `json:"expression"` + Timezone string `json:"timezone"` +} + +// PolicyStateTransition is a sub type of PolicyState containing information about transition to other states type PolicyStateTransition struct { - StateName string `json:"state_name"` - Conditions []struct { - MinIndexAge string `json:"min_index_age,omitempty"` - MinRolloverAge string `json:"min_rollover_age,omitempty"` - MinDocCount int `json:"min_doc_count,omitempty"` - MinSize string `json:"min_size,omitempty"` - Cron *struct { - Expression string `json:"expression"` - Timezone string `json:"timezone"` - } `json:"cron,omitempty"` - } `json:"conditions"` + StateName string `json:"state_name"` + Conditions *PolicyStateTransitionCondition `json:"conditions"` } diff --git a/plugins/ism/api_test.go b/plugins/ism/api_test.go index a766e6f9a..0ff4f2b93 100644 --- a/plugins/ism/api_test.go +++ b/plugins/ism/api_test.go @@ -9,6 +9,7 @@ package ism_test import ( + "context" "testing" "time" @@ -257,4 +258,51 @@ func TestClient(t *testing.T) { }) }) + t.Run("Put Policy with Transitions Conditions", func(t *testing.T) { + testRetentionPolicy := "testRetentionPolicy" + t.Cleanup(func() { + client.Policies.Delete(context.Background(), ism.PoliciesDeleteReq{Policy: testRetentionPolicy}) + }) + transitions := []ism.PolicyStateTransition{ + { + StateName: "delete", + Conditions: &ism.PolicyStateTransitionCondition{ + MinIndexAge: "1h", + }, + }, + } + _, err = client.Policies.Put( + context.Background(), + ism.PoliciesPutReq{ + Policy: testRetentionPolicy, + Body: ism.PoliciesPutBody{ + Policy: ism.PolicyBody{ + Description: "test policy with transitions conditions", + DefaultState: "test-transitions", + States: []ism.PolicyState{ + { + Name: "test-transitions", + Transitions: &transitions, + }, + { + Name: "delete", + Actions: []ism.PolicyStateAction{ + { + Delete: &ism.PolicyStateDelete{}, + }, + }, + }, + }, + Template: []ism.Template{ + { + IndexPatterns: []string{"test-transitions"}, + Priority: 21, + }, + }, + }, + }, + }, + ) + require.Nil(t, err) + }) }