Skip to content

Commit 1edf393

Browse files
authored
[databases]: add support for Opensearch advanced configuration (#729)
* [databases]: add support for Opensearch advanced configuration * move OpensearchConfig upper in a file * fix formatting in tests * minor renaming in a test
1 parent 086839e commit 1edf393

File tree

2 files changed

+213
-0
lines changed

2 files changed

+213
-0
lines changed

databases.go

+79
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ type DatabasesService interface {
154154
GetRedisConfig(context.Context, string) (*RedisConfig, *Response, error)
155155
GetMySQLConfig(context.Context, string) (*MySQLConfig, *Response, error)
156156
GetMongoDBConfig(context.Context, string) (*MongoDBConfig, *Response, error)
157+
GetOpensearchConfig(context.Context, string) (*OpensearchConfig, *Response, error)
157158
GetKafkaConfig(context.Context, string) (*KafkaConfig, *Response, error)
158159
UpdatePostgreSQLConfig(context.Context, string, *PostgreSQLConfig) (*Response, error)
159160
UpdateRedisConfig(context.Context, string, *RedisConfig) (*Response, error)
160161
UpdateMySQLConfig(context.Context, string, *MySQLConfig) (*Response, error)
161162
UpdateMongoDBConfig(context.Context, string, *MongoDBConfig) (*Response, error)
163+
UpdateOpensearchConfig(context.Context, string, *OpensearchConfig) (*Response, error)
162164
UpdateKafkaConfig(context.Context, string, *KafkaConfig) (*Response, error)
163165
ListOptions(todo context.Context) (*DatabaseOptions, *Response, error)
164166
UpgradeMajorVersion(context.Context, string, *UpgradeVersionRequest) (*Response, error)
@@ -683,6 +685,47 @@ type KafkaConfig struct {
683685
AutoCreateTopicsEnable *bool `json:"auto_create_topics_enable,omitempty"`
684686
}
685687

688+
// OpensearchConfig holds advanced configurations for Opensearch database clusters.
689+
type OpensearchConfig struct {
690+
HttpMaxContentLengthBytes *int `json:"http_max_content_length_bytes,omitempty"`
691+
HttpMaxHeaderSizeBytes *int `json:"http_max_header_size_bytes,omitempty"`
692+
HttpMaxInitialLineLengthBytes *int `json:"http_max_initial_line_length_bytes,omitempty"`
693+
IndicesQueryBoolMaxClauseCount *int `json:"indices_query_bool_max_clause_count,omitempty"`
694+
IndicesFielddataCacheSizePercentage *int `json:"indices_fielddata_cache_size_percentage,omitempty"`
695+
IndicesMemoryIndexBufferSizePercentage *int `json:"indices_memory_index_buffer_size_percentage,omitempty"`
696+
IndicesMemoryMinIndexBufferSizeMb *int `json:"indices_memory_min_index_buffer_size_mb,omitempty"`
697+
IndicesMemoryMaxIndexBufferSizeMb *int `json:"indices_memory_max_index_buffer_size_mb,omitempty"`
698+
IndicesQueriesCacheSizePercentage *int `json:"indices_queries_cache_size_percentage,omitempty"`
699+
IndicesRecoveryMaxMbPerSec *int `json:"indices_recovery_max_mb_per_sec,omitempty"`
700+
IndicesRecoveryMaxConcurrentFileChunks *int `json:"indices_recovery_max_concurrent_file_chunks,omitempty"`
701+
ThreadPoolSearchSize *int `json:"thread_pool_search_size,omitempty"`
702+
ThreadPoolSearchThrottledSize *int `json:"thread_pool_search_throttled_size,omitempty"`
703+
ThreadPoolGetSize *int `json:"thread_pool_get_size,omitempty"`
704+
ThreadPoolAnalyzeSize *int `json:"thread_pool_analyze_size,omitempty"`
705+
ThreadPoolWriteSize *int `json:"thread_pool_write_size,omitempty"`
706+
ThreadPoolForceMergeSize *int `json:"thread_pool_force_merge_size,omitempty"`
707+
ThreadPoolSearchQueueSize *int `json:"thread_pool_search_queue_size,omitempty"`
708+
ThreadPoolSearchThrottledQueueSize *int `json:"thread_pool_search_throttled_queue_size,omitempty"`
709+
ThreadPoolGetQueueSize *int `json:"thread_pool_get_queue_size,omitempty"`
710+
ThreadPoolAnalyzeQueueSize *int `json:"thread_pool_analyze_queue_size,omitempty"`
711+
ThreadPoolWriteQueueSize *int `json:"thread_pool_write_queue_size,omitempty"`
712+
IsmEnabled *bool `json:"ism_enabled,omitempty"`
713+
IsmHistoryEnabled *bool `json:"ism_history_enabled,omitempty"`
714+
IsmHistoryMaxAgeHours *int `json:"ism_history_max_age_hours,omitempty"`
715+
IsmHistoryMaxDocs *uint64 `json:"ism_history_max_docs,omitempty"`
716+
IsmHistoryRolloverCheckPeriodHours *int `json:"ism_history_rollover_check_period_hours,omitempty"`
717+
IsmHistoryRolloverRetentionPeriodDays *int `json:"ism_history_rollover_retention_period_days,omitempty"`
718+
SearchMaxBuckets *int `json:"search_max_buckets,omitempty"`
719+
ActionAutoCreateIndexEnabled *bool `json:"action_auto_create_index_enabled,omitempty"`
720+
EnableSecurityAudit *bool `json:"enable_security_audit,omitempty"`
721+
ActionDestructiveRequiresName *bool `json:"action_destructive_requires_name,omitempty"`
722+
ClusterMaxShardsPerNode *int `json:"cluster_max_shards_per_node,omitempty"`
723+
OverrideMainResponseVersion *bool `json:"override_main_response_version,omitempty"`
724+
ScriptMaxCompilationsRate *string `json:"script_max_compilations_rate,omitempty"`
725+
ClusterRoutingAllocationNodeConcurrentRecoveries *int `json:"cluster_routing_allocation_node_concurrent_recoveries,omitempty"`
726+
ReindexRemoteWhitelist []string `json:"reindex_remote_whitelist,omitempty"`
727+
}
728+
686729
type databaseUserRoot struct {
687730
User *DatabaseUser `json:"user"`
688731
}
@@ -727,6 +770,10 @@ type databaseMongoDBConfigRoot struct {
727770
Config *MongoDBConfig `json:"config"`
728771
}
729772

773+
type databaseOpensearchConfigRoot struct {
774+
Config *OpensearchConfig `json:"config"`
775+
}
776+
730777
type databaseKafkaConfigRoot struct {
731778
Config *KafkaConfig `json:"config"`
732779
}
@@ -1606,6 +1653,38 @@ func (svc *DatabasesServiceOp) UpdateKafkaConfig(ctx context.Context, databaseID
16061653
return resp, nil
16071654
}
16081655

1656+
// GetOpensearchConfig retrieves the config for a Opensearch database cluster.
1657+
func (svc *DatabasesServiceOp) GetOpensearchConfig(ctx context.Context, databaseID string) (*OpensearchConfig, *Response, error) {
1658+
path := fmt.Sprintf(databaseConfigPath, databaseID)
1659+
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
1660+
if err != nil {
1661+
return nil, nil, err
1662+
}
1663+
root := new(databaseOpensearchConfigRoot)
1664+
resp, err := svc.client.Do(ctx, req, root)
1665+
if err != nil {
1666+
return nil, resp, err
1667+
}
1668+
return root.Config, resp, nil
1669+
}
1670+
1671+
// UpdateOpensearchConfig updates the config for a Opensearch database cluster.
1672+
func (svc *DatabasesServiceOp) UpdateOpensearchConfig(ctx context.Context, databaseID string, config *OpensearchConfig) (*Response, error) {
1673+
path := fmt.Sprintf(databaseConfigPath, databaseID)
1674+
root := &databaseOpensearchConfigRoot{
1675+
Config: config,
1676+
}
1677+
req, err := svc.client.NewRequest(ctx, http.MethodPatch, path, root)
1678+
if err != nil {
1679+
return nil, err
1680+
}
1681+
resp, err := svc.client.Do(ctx, req, nil)
1682+
if err != nil {
1683+
return resp, err
1684+
}
1685+
return resp, nil
1686+
}
1687+
16091688
// ListOptions gets the database options available.
16101689
func (svc *DatabasesServiceOp) ListOptions(ctx context.Context) (*DatabaseOptions, *Response, error) {
16111690
root := new(databaseOptionsRoot)

databases_test.go

+134
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,140 @@ func TestDatabases_UpdateConfigKafka(t *testing.T) {
31623162
require.NoError(t, err)
31633163
}
31643164

3165+
func TestDatabases_GetConfigOpensearch(t *testing.T) {
3166+
setup()
3167+
defer teardown()
3168+
3169+
var (
3170+
dbSvc = client.Databases
3171+
dbID = "da4e0206-d019-41d7-b51f-deadbeefbb8f"
3172+
path = fmt.Sprintf("/v2/databases/%s/config", dbID)
3173+
3174+
opensearchConfigJSON = `{
3175+
"config": {
3176+
"ism_enabled": true,
3177+
"ism_history_enabled": true,
3178+
"ism_history_max_age_hours": 24,
3179+
"ism_history_max_docs": 2500000,
3180+
"ism_history_rollover_check_period_hours": 8,
3181+
"ism_history_rollover_retention_period_days": 30,
3182+
"http_max_content_length_bytes": 100000000,
3183+
"http_max_header_size_bytes": 8192,
3184+
"http_max_initial_line_length_bytes": 4096,
3185+
"indices_query_bool_max_clause_count": 1024,
3186+
"search_max_buckets": 10000,
3187+
"indices_fielddata_cache_size_percentage": 0,
3188+
"indices_memory_index_buffer_size_percentage": 10,
3189+
"indices_memory_min_index_buffer_size_mb": 48,
3190+
"indices_memory_max_index_buffer_size_mb": 0,
3191+
"indices_queries_cache_size_percentage": 10,
3192+
"indices_recovery_max_mb_per_sec": 40,
3193+
"indices_recovery_max_concurrent_file_chunks": 2,
3194+
"action_auto_create_index_enabled": true,
3195+
"action_destructive_requires_name": false,
3196+
"plugins_alerting_filter_by_backend_roles_enabled": false,
3197+
"enable_security_audit": false,
3198+
"thread_pool_search_size": 0,
3199+
"thread_pool_search_throttled_size": 0,
3200+
"thread_pool_search_throttled_queue_size": 0,
3201+
"thread_pool_search_queue_size": 0,
3202+
"thread_pool_get_size": 0,
3203+
"thread_pool_get_queue_size": 0,
3204+
"thread_pool_analyze_size": 0,
3205+
"thread_pool_analyze_queue_size": 0,
3206+
"thread_pool_write_size": 0,
3207+
"thread_pool_write_queue_size": 0,
3208+
"thread_pool_force_merge_size": 0,
3209+
"override_main_response_version": false,
3210+
"script_max_compilations_rate": "use-context",
3211+
"cluster_max_shards_per_node": 0,
3212+
"cluster_routing_allocation_node_concurrent_recoveries": 2
3213+
}
3214+
}`
3215+
3216+
opensearchConfig = OpensearchConfig{
3217+
HttpMaxContentLengthBytes: PtrTo(100000000),
3218+
HttpMaxHeaderSizeBytes: PtrTo(8192),
3219+
HttpMaxInitialLineLengthBytes: PtrTo(4096),
3220+
IndicesQueryBoolMaxClauseCount: PtrTo(1024),
3221+
IndicesFielddataCacheSizePercentage: PtrTo(0),
3222+
IndicesMemoryIndexBufferSizePercentage: PtrTo(10),
3223+
IndicesMemoryMinIndexBufferSizeMb: PtrTo(48),
3224+
IndicesMemoryMaxIndexBufferSizeMb: PtrTo(0),
3225+
IndicesQueriesCacheSizePercentage: PtrTo(10),
3226+
IndicesRecoveryMaxMbPerSec: PtrTo(40),
3227+
IndicesRecoveryMaxConcurrentFileChunks: PtrTo(2),
3228+
ThreadPoolSearchSize: PtrTo(0),
3229+
ThreadPoolSearchThrottledSize: PtrTo(0),
3230+
ThreadPoolGetSize: PtrTo(0),
3231+
ThreadPoolAnalyzeSize: PtrTo(0),
3232+
ThreadPoolWriteSize: PtrTo(0),
3233+
ThreadPoolForceMergeSize: PtrTo(0),
3234+
ThreadPoolSearchQueueSize: PtrTo(0),
3235+
ThreadPoolSearchThrottledQueueSize: PtrTo(0),
3236+
ThreadPoolGetQueueSize: PtrTo(0),
3237+
ThreadPoolAnalyzeQueueSize: PtrTo(0),
3238+
ThreadPoolWriteQueueSize: PtrTo(0),
3239+
IsmEnabled: PtrTo(true),
3240+
IsmHistoryEnabled: PtrTo(true),
3241+
IsmHistoryMaxAgeHours: PtrTo(24),
3242+
IsmHistoryMaxDocs: PtrTo(uint64(2500000)),
3243+
IsmHistoryRolloverCheckPeriodHours: PtrTo(8),
3244+
IsmHistoryRolloverRetentionPeriodDays: PtrTo(30),
3245+
SearchMaxBuckets: PtrTo(10000),
3246+
ActionAutoCreateIndexEnabled: PtrTo(true),
3247+
EnableSecurityAudit: PtrTo(false),
3248+
ActionDestructiveRequiresName: PtrTo(false),
3249+
ClusterMaxShardsPerNode: PtrTo(0),
3250+
OverrideMainResponseVersion: PtrTo(false),
3251+
ScriptMaxCompilationsRate: PtrTo("use-context"),
3252+
ClusterRoutingAllocationNodeConcurrentRecoveries: PtrTo(2),
3253+
ReindexRemoteWhitelist: nil,
3254+
}
3255+
)
3256+
3257+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
3258+
testMethod(t, r, http.MethodGet)
3259+
fmt.Fprint(w, opensearchConfigJSON)
3260+
})
3261+
3262+
got, _, err := dbSvc.GetOpensearchConfig(ctx, dbID)
3263+
require.NoError(t, err)
3264+
require.Equal(t, &opensearchConfig, got)
3265+
}
3266+
3267+
func TestDatabases_UpdateConfigOpensearch(t *testing.T) {
3268+
setup()
3269+
defer teardown()
3270+
3271+
var (
3272+
dbID = "deadbeef-dead-4aa5-beef-deadbeef347d"
3273+
path = fmt.Sprintf("/v2/databases/%s/config", dbID)
3274+
opensearchConfig = &OpensearchConfig{
3275+
HttpMaxContentLengthBytes: PtrTo(1),
3276+
HttpMaxHeaderSizeBytes: PtrTo(0),
3277+
}
3278+
)
3279+
3280+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
3281+
testMethod(t, r, http.MethodPatch)
3282+
3283+
var b databaseOpensearchConfigRoot
3284+
decoder := json.NewDecoder(r.Body)
3285+
err := decoder.Decode(&b)
3286+
require.NoError(t, err)
3287+
3288+
assert.Equal(t, b.Config, opensearchConfig)
3289+
assert.Equal(t, 0, *b.Config.HttpMaxHeaderSizeBytes, "pointers to zero value should be sent")
3290+
assert.Nil(t, b.Config.HttpMaxInitialLineLengthBytes, "excluded value should not be sent")
3291+
3292+
w.WriteHeader(http.StatusNoContent)
3293+
})
3294+
3295+
_, err := client.Databases.UpdateOpensearchConfig(ctx, dbID, opensearchConfig)
3296+
require.NoError(t, err)
3297+
}
3298+
31653299
func TestDatabases_UpgradeMajorVersion(t *testing.T) {
31663300
setup()
31673301
defer teardown()

0 commit comments

Comments
 (0)