Skip to content

Commit 6804c7d

Browse files
authored
[databases]: add support for Opensearch advanced configuration (#1588)
* [databases]: add support for Opensearch advanced configuration * add PluginsAlertingFilterByBackendRolesEnabled to displayers
1 parent de1fb73 commit 6804c7d

File tree

11 files changed

+552
-16
lines changed

11 files changed

+552
-16
lines changed

commands/databases.go

+30-12
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,7 @@ This command functions as a PATCH request, meaning that only the specified field
24442444
displayerType(&displayers.RedisConfiguration{}),
24452445
displayerType(&displayers.MongoDBConfiguration{}),
24462446
displayerType(&displayers.KafkaConfiguration{}),
2447+
displayerType(&displayers.OpensearchConfiguration{}),
24472448
)
24482449
AddStringFlag(
24492450
getDatabaseCfgCommand,
@@ -2498,14 +2499,15 @@ func RunDatabaseConfigurationGet(c *CmdConfig) error {
24982499
}
24992500

25002501
allowedEngines := map[string]any{
2501-
"mysql": nil,
2502-
"pg": nil,
2503-
"redis": nil,
2504-
"mongodb": nil,
2505-
"kafka": nil,
2502+
"mysql": nil,
2503+
"pg": nil,
2504+
"redis": nil,
2505+
"mongodb": nil,
2506+
"kafka": nil,
2507+
"opensearch": nil,
25062508
}
25072509
if _, ok := allowedEngines[engine]; !ok {
2508-
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'mysql', 'redis', 'mongodb', 'kafka'", c.NS)
2510+
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'mysql', 'redis', 'mongodb', 'kafka', opensearch", c.NS)
25092511
}
25102512

25112513
dbId := args[0]
@@ -2559,6 +2561,16 @@ func RunDatabaseConfigurationGet(c *CmdConfig) error {
25592561
KafkaConfig: *config,
25602562
}
25612563
return c.Display(&displayer)
2564+
} else if engine == "opensearch" {
2565+
config, err := c.Databases().GetOpensearchConfiguration(dbId)
2566+
if err != nil {
2567+
return err
2568+
}
2569+
2570+
displayer := displayers.OpensearchConfiguration{
2571+
OpensearchConfig: *config,
2572+
}
2573+
return c.Display(&displayer)
25622574
}
25632575

25642576
return nil
@@ -2579,14 +2591,15 @@ func RunDatabaseConfigurationUpdate(c *CmdConfig) error {
25792591
}
25802592

25812593
allowedEngines := map[string]any{
2582-
"mysql": nil,
2583-
"pg": nil,
2584-
"redis": nil,
2585-
"mongodb": nil,
2586-
"kafka": nil,
2594+
"mysql": nil,
2595+
"pg": nil,
2596+
"redis": nil,
2597+
"mongodb": nil,
2598+
"kafka": nil,
2599+
"opensearch": nil,
25872600
}
25882601
if _, ok := allowedEngines[engine]; !ok {
2589-
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'mysql', 'redis', 'mongodb', 'kafka'", c.NS)
2602+
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'mysql', 'redis', 'mongodb', 'kafka', 'opensearch'", c.NS)
25902603
}
25912604

25922605
configJson, err := c.Doit.GetString(c.NS, doctl.ArgDatabaseConfigJson)
@@ -2620,6 +2633,11 @@ func RunDatabaseConfigurationUpdate(c *CmdConfig) error {
26202633
if err != nil {
26212634
return err
26222635
}
2636+
} else if engine == "opensearch" {
2637+
err := c.Databases().UpdateOpensearchConfiguration(dbId, configJson)
2638+
if err != nil {
2639+
return err
2640+
}
26232641
}
26242642

26252643
return nil

commands/databases_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ var (
219219
KafkaConfig: &godo.KafkaConfig{},
220220
}
221221

222+
testOpensearchConfiguration = do.OpensearchConfig{
223+
OpensearchConfig: &godo.OpensearchConfig{},
224+
}
225+
222226
topicReplicationFactor = uint32(3)
223227
testKafkaTopic = do.DatabaseTopic{
224228
DatabaseTopic: &godo.DatabaseTopic{
@@ -1680,6 +1684,16 @@ func TestDatabaseConfigurationGet(t *testing.T) {
16801684
assert.NoError(t, err)
16811685
})
16821686

1687+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
1688+
tm.databases.EXPECT().GetOpensearchConfiguration(testDBCluster.ID).Return(&testOpensearchConfiguration, nil)
1689+
config.Args = append(config.Args, testDBCluster.ID)
1690+
config.Doit.Set(config.NS, doctl.ArgDatabaseEngine, "opensearch")
1691+
1692+
err := RunDatabaseConfigurationGet(config)
1693+
1694+
assert.NoError(t, err)
1695+
})
1696+
16831697
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
16841698
err := RunDatabaseConfigurationGet(config)
16851699

@@ -1754,6 +1768,16 @@ func TestDatabaseConfigurationUpdate(t *testing.T) {
17541768
assert.NoError(t, err)
17551769
})
17561770

1771+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
1772+
tm.databases.EXPECT().UpdateOpensearchConfiguration(testDBCluster.ID, "").Return(nil)
1773+
config.Args = append(config.Args, testDBCluster.ID)
1774+
config.Doit.Set(config.NS, doctl.ArgDatabaseEngine, "opensearch")
1775+
1776+
err := RunDatabaseConfigurationUpdate(config)
1777+
1778+
assert.NoError(t, err)
1779+
})
1780+
17571781
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
17581782
err := RunDatabaseConfigurationUpdate(config)
17591783

commands/displayers/database.go

+259
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,265 @@ func (dc *KafkaConfiguration) KV() []map[string]any {
18721872
return o
18731873
}
18741874

1875+
type OpensearchConfiguration struct {
1876+
OpensearchConfig do.OpensearchConfig
1877+
}
1878+
1879+
var _ Displayable = &OpensearchConfiguration{}
1880+
1881+
func (dc *OpensearchConfiguration) JSON(out io.Writer) error {
1882+
return writeJSON(dc.OpensearchConfig, out)
1883+
}
1884+
1885+
func (dc *OpensearchConfiguration) Cols() []string {
1886+
return []string{
1887+
"key",
1888+
"value",
1889+
}
1890+
}
1891+
1892+
func (dc *OpensearchConfiguration) ColMap() map[string]string {
1893+
return map[string]string{
1894+
"key": "key",
1895+
"value": "value",
1896+
}
1897+
}
1898+
1899+
func (dc *OpensearchConfiguration) KV() []map[string]any {
1900+
c := dc.OpensearchConfig
1901+
o := []map[string]any{}
1902+
if c.HttpMaxContentLengthBytes != nil {
1903+
o = append(o, map[string]any{
1904+
"key": "HttpMaxContentLengthBytes",
1905+
"value": *c.HttpMaxContentLengthBytes,
1906+
})
1907+
}
1908+
if c.HttpMaxHeaderSizeBytes != nil {
1909+
o = append(o, map[string]any{
1910+
"key": "HttpMaxHeaderSizeBytes",
1911+
"value": *c.HttpMaxHeaderSizeBytes,
1912+
})
1913+
}
1914+
if c.HttpMaxInitialLineLengthBytes != nil {
1915+
o = append(o, map[string]any{
1916+
"key": "HttpMaxInitialLineLengthBytes",
1917+
"value": *c.HttpMaxInitialLineLengthBytes,
1918+
})
1919+
}
1920+
if c.IndicesQueryBoolMaxClauseCount != nil {
1921+
o = append(o, map[string]any{
1922+
"key": "IndicesQueryBoolMaxClauseCount",
1923+
"value": *c.IndicesQueryBoolMaxClauseCount,
1924+
})
1925+
}
1926+
if c.IndicesFielddataCacheSizePercentage != nil {
1927+
o = append(o, map[string]any{
1928+
"key": "IndicesFielddataCacheSizePercentage",
1929+
"value": *c.IndicesFielddataCacheSizePercentage,
1930+
})
1931+
}
1932+
if c.IndicesMemoryIndexBufferSizePercentage != nil {
1933+
o = append(o, map[string]any{
1934+
"key": "IndicesMemoryIndexBufferSizePercentage",
1935+
"value": *c.IndicesMemoryIndexBufferSizePercentage,
1936+
})
1937+
}
1938+
if c.IndicesMemoryMinIndexBufferSizeMb != nil {
1939+
o = append(o, map[string]any{
1940+
"key": "IndicesMemoryMinIndexBufferSizeMb",
1941+
"value": *c.IndicesMemoryMinIndexBufferSizeMb,
1942+
})
1943+
}
1944+
if c.IndicesMemoryMaxIndexBufferSizeMb != nil {
1945+
o = append(o, map[string]any{
1946+
"key": "IndicesMemoryMaxIndexBufferSizeMb",
1947+
"value": *c.IndicesMemoryMaxIndexBufferSizeMb,
1948+
})
1949+
}
1950+
if c.IndicesQueriesCacheSizePercentage != nil {
1951+
o = append(o, map[string]any{
1952+
"key": "IndicesQueriesCacheSizePercentage",
1953+
"value": *c.IndicesQueriesCacheSizePercentage,
1954+
})
1955+
}
1956+
if c.IndicesRecoveryMaxMbPerSec != nil {
1957+
o = append(o, map[string]any{
1958+
"key": "IndicesRecoveryMaxMbPerSec",
1959+
"value": *c.IndicesRecoveryMaxMbPerSec,
1960+
})
1961+
}
1962+
if c.IndicesRecoveryMaxConcurrentFileChunks != nil {
1963+
o = append(o, map[string]any{
1964+
"key": "IndicesRecoveryMaxConcurrentFileChunks",
1965+
"value": *c.IndicesRecoveryMaxConcurrentFileChunks,
1966+
})
1967+
}
1968+
if c.ThreadPoolSearchSize != nil {
1969+
o = append(o, map[string]any{
1970+
"key": "ThreadPoolSearchSize",
1971+
"value": *c.ThreadPoolSearchSize,
1972+
})
1973+
}
1974+
if c.ThreadPoolSearchThrottledSize != nil {
1975+
o = append(o, map[string]any{
1976+
"key": "ThreadPoolSearchThrottledSize",
1977+
"value": *c.ThreadPoolSearchThrottledSize,
1978+
})
1979+
}
1980+
if c.ThreadPoolGetSize != nil {
1981+
o = append(o, map[string]any{
1982+
"key": "ThreadPoolGetSize",
1983+
"value": *c.ThreadPoolGetSize,
1984+
})
1985+
}
1986+
if c.ThreadPoolAnalyzeSize != nil {
1987+
o = append(o, map[string]any{
1988+
"key": "ThreadPoolAnalyzeSize",
1989+
"value": *c.ThreadPoolAnalyzeSize,
1990+
})
1991+
}
1992+
if c.ThreadPoolWriteSize != nil {
1993+
o = append(o, map[string]any{
1994+
"key": "ThreadPoolWriteSize",
1995+
"value": *c.ThreadPoolWriteSize,
1996+
})
1997+
}
1998+
if c.ThreadPoolForceMergeSize != nil {
1999+
o = append(o, map[string]any{
2000+
"key": "ThreadPoolForceMergeSize",
2001+
"value": *c.ThreadPoolForceMergeSize,
2002+
})
2003+
}
2004+
if c.ThreadPoolSearchQueueSize != nil {
2005+
o = append(o, map[string]any{
2006+
"key": "ThreadPoolSearchQueueSize",
2007+
"value": *c.ThreadPoolSearchQueueSize,
2008+
})
2009+
}
2010+
if c.ThreadPoolSearchThrottledQueueSize != nil {
2011+
o = append(o, map[string]any{
2012+
"key": "ThreadPoolSearchThrottledQueueSize",
2013+
"value": *c.ThreadPoolSearchThrottledQueueSize,
2014+
})
2015+
}
2016+
if c.ThreadPoolGetQueueSize != nil {
2017+
o = append(o, map[string]any{
2018+
"key": "ThreadPoolGetQueueSize",
2019+
"value": *c.ThreadPoolGetQueueSize,
2020+
})
2021+
}
2022+
if c.ThreadPoolAnalyzeQueueSize != nil {
2023+
o = append(o, map[string]any{
2024+
"key": "ThreadPoolAnalyzeQueueSize",
2025+
"value": *c.ThreadPoolAnalyzeQueueSize,
2026+
})
2027+
}
2028+
if c.ThreadPoolWriteQueueSize != nil {
2029+
o = append(o, map[string]any{
2030+
"key": "ThreadPoolWriteQueueSize",
2031+
"value": *c.ThreadPoolWriteQueueSize,
2032+
})
2033+
}
2034+
if c.IsmEnabled != nil {
2035+
o = append(o, map[string]any{
2036+
"key": "IsmEnabled",
2037+
"value": *c.IsmEnabled,
2038+
})
2039+
}
2040+
if c.IsmHistoryEnabled != nil {
2041+
o = append(o, map[string]any{
2042+
"key": "IsmHistoryEnabled",
2043+
"value": *c.IsmHistoryEnabled,
2044+
})
2045+
}
2046+
if c.IsmHistoryMaxAgeHours != nil {
2047+
o = append(o, map[string]any{
2048+
"key": "IsmHistoryMaxAgeHours",
2049+
"value": *c.IsmHistoryMaxAgeHours,
2050+
})
2051+
}
2052+
if c.IsmHistoryMaxDocs != nil {
2053+
o = append(o, map[string]any{
2054+
"key": "IsmHistoryMaxDocs",
2055+
"value": *c.IsmHistoryMaxDocs,
2056+
})
2057+
}
2058+
if c.IsmHistoryRolloverCheckPeriodHours != nil {
2059+
o = append(o, map[string]any{
2060+
"key": "IsmHistoryRolloverCheckPeriodHours",
2061+
"value": *c.IsmHistoryRolloverCheckPeriodHours,
2062+
})
2063+
}
2064+
if c.IsmHistoryRolloverRetentionPeriodDays != nil {
2065+
o = append(o, map[string]any{
2066+
"key": "IsmHistoryRolloverRetentionPeriodDays",
2067+
"value": *c.IsmHistoryRolloverRetentionPeriodDays,
2068+
})
2069+
}
2070+
if c.SearchMaxBuckets != nil {
2071+
o = append(o, map[string]any{
2072+
"key": "SearchMaxBuckets",
2073+
"value": *c.SearchMaxBuckets,
2074+
})
2075+
}
2076+
if c.ActionAutoCreateIndexEnabled != nil {
2077+
o = append(o, map[string]any{
2078+
"key": "ActionAutoCreateIndexEnabled",
2079+
"value": *c.ActionAutoCreateIndexEnabled,
2080+
})
2081+
}
2082+
if c.EnableSecurityAudit != nil {
2083+
o = append(o, map[string]any{
2084+
"key": "EnableSecurityAudit",
2085+
"value": *c.EnableSecurityAudit,
2086+
})
2087+
}
2088+
if c.ActionDestructiveRequiresName != nil {
2089+
o = append(o, map[string]any{
2090+
"key": "ActionDestructiveRequiresName",
2091+
"value": *c.ActionDestructiveRequiresName,
2092+
})
2093+
}
2094+
if c.ClusterMaxShardsPerNode != nil {
2095+
o = append(o, map[string]any{
2096+
"key": "ClusterMaxShardsPerNode",
2097+
"value": *c.ClusterMaxShardsPerNode,
2098+
})
2099+
}
2100+
if c.OverrideMainResponseVersion != nil {
2101+
o = append(o, map[string]any{
2102+
"key": "OverrideMainResponseVersion",
2103+
"value": *c.OverrideMainResponseVersion,
2104+
})
2105+
}
2106+
if c.ScriptMaxCompilationsRate != nil {
2107+
o = append(o, map[string]any{
2108+
"key": "ScriptMaxCompilationsRate",
2109+
"value": *c.ScriptMaxCompilationsRate,
2110+
})
2111+
}
2112+
if c.ClusterRoutingAllocationNodeConcurrentRecoveries != nil {
2113+
o = append(o, map[string]any{
2114+
"key": "ClusterRoutingAllocationNodeConcurrentRecoveries",
2115+
"value": *c.ClusterRoutingAllocationNodeConcurrentRecoveries,
2116+
})
2117+
}
2118+
if c.ReindexRemoteWhitelist != nil {
2119+
o = append(o, map[string]any{
2120+
"key": "ReindexRemoteWhitelist",
2121+
"value": c.ReindexRemoteWhitelist,
2122+
})
2123+
}
2124+
if c.PluginsAlertingFilterByBackendRolesEnabled != nil {
2125+
o = append(o, map[string]any{
2126+
"key": "PluginsAlertingFilterByBackendRolesEnabled",
2127+
"value": *c.PluginsAlertingFilterByBackendRolesEnabled,
2128+
})
2129+
}
2130+
2131+
return o
2132+
}
2133+
18752134
type DatabaseEvents struct {
18762135
DatabaseEvents do.DatabaseEvents
18772136
}

0 commit comments

Comments
 (0)