Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ISM Plugin Transitions Conditions struct (#555) #556

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
30 changes: 18 additions & 12 deletions plugins/ism/api_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
48 changes: 48 additions & 0 deletions plugins/ism/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package ism_test

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -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)
})
}
Loading