Skip to content

Commit

Permalink
Add max_primary_shard_docs condition to ILM rollover (elastic#845)
Browse files Browse the repository at this point in the history
* Add `max_primary_shard_docs` condition to rollover

* Update test for rollover `max_primary_shard_docs` condition

* Specify min version in the description

* Update CHANGELOG.md
  • Loading branch information
AR3E3B9N committed Oct 15, 2024
1 parent 1fa3e9b commit 3136fbc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Changes

- Add `max_primary_shard_docs` condition to ILM rollover ([#845](https://github.com/elastic/terraform-provider-elasticstack/pull/845))
- Fix boolean setting parsing for `elasticstack_elasticsearch_indices` data source. ([#842](https://github.com/elastic/terraform-provider-elasticstack/pull/842))

## [0.11.9] - 2024-10-14
Expand Down
1 change: 1 addition & 0 deletions docs/resources/elasticsearch_index_lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ Optional:

- `max_age` (String) Triggers rollover after the maximum elapsed time from index creation is reached.
- `max_docs` (Number) Triggers rollover after the specified maximum number of documents is reached.
- `max_primary_shard_docs` (Number) Triggers rollover when the largest primary shard in the index reaches a certain number of documents. Supported from Elasticsearch version **8.2**
- `max_primary_shard_size` (String) Triggers rollover when the largest primary shard in the index reaches a certain size.
- `max_size` (String) Triggers rollover when the index reaches a certain size.
- `min_age` (String) Prevents rollover until after the minimum elapsed time from index creation is reached. Supported from Elasticsearch version **8.4**
Expand Down
24 changes: 15 additions & 9 deletions internal/elasticsearch/index/ilm.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ var supportedActions = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"max_primary_shard_docs": {
Description: "Triggers rollover when the largest primary shard in the index reaches a certain number of documents. Supported from Elasticsearch version **8.2**",
Type: schema.TypeInt,
Optional: true,
},
"max_primary_shard_size": {
Description: "Triggers rollover when the largest primary shard in the index reaches a certain size.",
Type: schema.TypeString,
Expand All @@ -288,16 +293,16 @@ var supportedActions = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"min_primary_shard_size": {
Description: "Prevents rollover until the largest primary shard in the index reaches a certain size. Supported from Elasticsearch version **8.4**",
Type: schema.TypeString,
Optional: true,
},
"min_primary_shard_docs": {
Description: "Prevents rollover until the largest primary shard in the index reaches a certain number of documents. Supported from Elasticsearch version **8.4**",
Type: schema.TypeInt,
Optional: true,
},
"min_primary_shard_size": {
Description: "Prevents rollover until the largest primary shard in the index reaches a certain size. Supported from Elasticsearch version **8.4**",
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -529,7 +534,7 @@ func expandPhase(p map[string]interface{}, serverVersion *version.Version) (*mod
}
}
case "rollover":
actions[actionName], diags = expandAction(a, serverVersion, "max_age", "max_docs", "max_size", "max_primary_shard_size", "min_age", "min_docs", "min_size", "min_primary_shard_size", "min_primary_shard_docs")
actions[actionName], diags = expandAction(a, serverVersion, "max_age", "max_docs", "max_size", "max_primary_shard_docs", "max_primary_shard_size", "min_age", "min_docs", "min_size", "min_primary_shard_docs", "min_primary_shard_size")
case "searchable_snapshot":
actions[actionName], diags = expandAction(a, serverVersion, "snapshot_repository", "force_merge_index")
case "set_priority":
Expand Down Expand Up @@ -568,15 +573,16 @@ var ilmActionSettingOptions = map[string]struct {
def interface{}
minVersion *version.Version
}{
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
"number_of_replicas": {skipEmptyCheck: true},
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
"priority": {skipEmptyCheck: true},
"max_primary_shard_docs": {minVersion: version.Must(version.NewVersion("8.2.0"))},
"min_age": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
"min_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_primary_shard_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
}

func expandAction(a []interface{}, serverVersion *version.Version, settings ...string) (map[string]interface{}, diag.Diagnostics) {
Expand Down
6 changes: 4 additions & 2 deletions internal/elasticsearch/index/ilm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ func TestAccResourceILMRolloverConditions(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_age", "7d"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_docs", "10000"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_size", "100gb"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_docs", "5000"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_size", "50gb"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_age", "3d"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_docs", "1000"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_size", "50gb"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_size", "25gb"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_docs", "500"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_size", "25gb"),
),
},
},
Expand Down Expand Up @@ -273,12 +274,13 @@ resource "elasticstack_elasticsearch_index_lifecycle" "test_rollover" {
max_age = "7d"
max_docs = 10000
max_size = "100gb"
max_primary_shard_docs = 5000
max_primary_shard_size = "50gb"
min_age = "3d"
min_docs = 1000
min_size = "50gb"
min_primary_shard_size = "25gb"
min_primary_shard_docs = 500
min_primary_shard_size = "25gb"
}
readonly {}
Expand Down

0 comments on commit 3136fbc

Please sign in to comment.