Skip to content

Commit

Permalink
Support slow logs in cluster settings
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Sep 16, 2024
1 parent 3e84564 commit f896157
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/data-sources/host.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data "opensearch_host" "test" {

- `id` (String) The ID of this resource.
- `url` (String) the url of the active cluster


5 changes: 1 addition & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ EOF
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `url` (String) OpenSearch URL

### Optional

- `aws_access_key` (String) The access key for use with AWS OpenSearch Service domains
Expand All @@ -87,6 +83,7 @@ EOF
- `sniff` (Boolean) Set the node sniffing option for the OpenSearch client. Client won't work with sniffing if nodes are not routable.
- `token` (String) A bearer token or ApiKey for an Authorization header, e.g. Active Directory API key.
- `token_name` (String) The type of token, usually ApiKey or Bearer
- `url` (String) OpenSearch URL
- `username` (String) Username to use to connect to OpenSearch using basic auth
- `version_ping_timeout` (Number) Version ping timeout in seconds

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/anomaly_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ EOF
### Read-Only

- `id` (String) The ID of this resource.


7 changes: 7 additions & 0 deletions docs/resources/cluster_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ resource "opensearch_cluster_settings" "global" {
- `cluster_routing_allocation_same_shard_host` (Boolean) Perform a check to prevent allocation of multiple instances of the same shard on a single host, if multiple nodes are started on the host
- `cluster_routing_allocation_total_shards_per_node` (Number) Maximum number of primary and replica shards allocated to each node
- `cluster_routing_rebalance_enable` (String) Allow rebalancing for specific kinds of shards (all, primaries, replicas, none)
- `cluster_search_request_slowlog_level` (String) Log level for search requests slowlog (TRACE, DEBUG, INFO, WARN)
- `cluster_search_request_slowlog_threshold_debug` (String) Slowlog threshold for DEBUG level search requests (e.g., 2s)
- `cluster_search_request_slowlog_threshold_info` (String) Slowlog threshold for INFO level search requests (e.g., 5s)
- `cluster_search_request_slowlog_threshold_trace` (String) Slowlog threshold for TRACE level search requests (e.g., 10ms)
- `cluster_search_request_slowlog_threshold_warn` (String) Slowlog threshold for WARN level search requests (e.g., 10s)
- `indices_breaker_fielddata_limit` (String) The percentage of memory above which if loading a field into the field data cache would cause the cache to exceed this limit, an error is returned
- `indices_breaker_fielddata_overhead` (Number) A constant that all field data estimations are multiplied by
- `indices_breaker_request_limit` (String) The percentabge of memory above which per-request data structures (e.g. calculating aggregations) are prevented from exceeding
Expand All @@ -67,3 +72,5 @@ resource "opensearch_cluster_settings" "global" {
### Read-Only

- `id` (String) The ID of this resource.


2 changes: 2 additions & 0 deletions docs/resources/dashboard_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ EOF
### Read-Only

- `id` (String) The ID of this resource.


2 changes: 2 additions & 0 deletions docs/resources/data_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ resource "opensearch_data_stream" "foo" {
### Read-Only

- `id` (String) The ID of this resource.


23 changes: 23 additions & 0 deletions examples/cluster-settings/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Configure the OpenSearch provider
terraform {
required_providers {
opensearch = {
source = "registry.terraform.io/opensearch-project/opensearch"
}
}
}

provider "opensearch" {
url = "http://127.0.0.1:9200"
username = "admin"
password = "myStrongPassword123@456"
}

resource "opensearch_cluster_settings" "persistent" {
cluster_max_shards_per_node = 10
cluster_search_request_slowlog_level = "WARN"
cluster_search_request_slowlog_threshold_warn = "10s"
cluster_search_request_slowlog_threshold_info = "5s"
cluster_search_request_slowlog_threshold_debug = "2s"
cluster_search_request_slowlog_threshold_trace = "100ms"
}
30 changes: 30 additions & 0 deletions provider/resource_opensearch_cluster_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var (
"search.default_search_timeout",
"action.auto_create_index",
"cluster.routing.allocation.enable",
"cluster.search.request.slowlog.level",
"cluster.search.request.slowlog.threshold.warn",
"cluster.search.request.slowlog.threshold.info",
"cluster.search.request.slowlog.threshold.debug",
"cluster.search.request.slowlog.threshold.trace",
}
intClusterSettings = []string{
"cluster.max_shards_per_node",
Expand Down Expand Up @@ -170,6 +175,31 @@ func resourceOpensearchClusterSettings() *schema.Resource {
Optional: true,
Description: "Enable or disable allocation for specific kinds of shards (all, primaries, new_primaries, none)",
},
"cluster_search_request_slowlog_level": {
Type: schema.TypeString,
Optional: true,
Description: "Log level for search requests slowlog (TRACE, DEBUG, INFO, WARN)",
},
"cluster_search_request_slowlog_threshold_warn": {
Type: schema.TypeString,
Optional: true,
Description: "Slowlog threshold for WARN level search requests (e.g., 10s)",
},
"cluster_search_request_slowlog_threshold_info": {
Type: schema.TypeString,
Optional: true,
Description: "Slowlog threshold for INFO level search requests (e.g., 5s)",
},
"cluster_search_request_slowlog_threshold_debug": {
Type: schema.TypeString,
Optional: true,
Description: "Slowlog threshold for DEBUG level search requests (e.g., 2s)",
},
"cluster_search_request_slowlog_threshold_trace": {
Type: schema.TypeString,
Optional: true,
Description: "Slowlog threshold for TRACE level search requests (e.g., 10ms)",
},
"cluster_routing_allocation_node_concurrent_incoming_recoveries": {
Type: schema.TypeInt,
Optional: true,
Expand Down
24 changes: 24 additions & 0 deletions provider/resource_opensearch_cluster_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func TestAccOpensearchClusterSettings(t *testing.T) {
})
}

func TestAccOpensearchClusterSettingsSlowLogs(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: checkOpensearchClusterSettingsDestroy,
Steps: []resource.TestStep{
{
Config: testAccOpensearchClusterSettingsSlowLog,
Check: resource.ComposeTestCheckFunc(
testCheckOpensearchClusterSettingInState("opensearch_cluster_settings.global"),
testCheckOpensearchClusterSettingExists("cluster.search.request.slowlog.level"),
),
},
},
})
}

func testCheckOpensearchClusterSettingInState(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -89,3 +106,10 @@ resource "opensearch_cluster_settings" "global" {
action_auto_create_index = "my-index-000001,index10,-index1*,+ind*,-.aws_cold_catalog*,+*"
}
`

var testAccOpensearchClusterSettingsSlowLog = `
resource "opensearch_cluster_settings" "global" {
cluster_search_request_slowlog_level = "WARN"
cluster_search_request_slowlog_threshold_warn = "10s"
}
`

0 comments on commit f896157

Please sign in to comment.