Skip to content

Added support for DB Configurable Params #527

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

Merged
Show file tree
Hide file tree
Changes from 3 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
54 changes: 52 additions & 2 deletions linode_api4/groups/database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from typing import Any, Dict, Union

from linode_api4 import (
MySQLDatabaseConfigOptions,
PostgreSQLDatabaseConfigOptions,
)
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import (
Expand Down Expand Up @@ -63,6 +69,26 @@ def engines(self, *filters):
"""
return self.client._get_and_filter(DatabaseEngine, *filters)

def mysql_config_options(self):
"""
Returns a detailed list of all the configuration options for MySQL Databases.

API Documentation: TODO

:returns: The JSON configuration options for MySQL Databases.
"""
return self.client.get("databases/mysql/config", model=self)

def postgresql_config_options(self):
"""
Returns a detailed list of all the configuration options for PostgreSQL Databases.

API Documentation: TODO

:returns: The JSON configuration options for PostgreSQL Databases.
"""
return self.client.get("databases/postgresql/config", model=self)

def instances(self, *filters):
"""
Returns a list of Managed Databases active on this account.
Expand Down Expand Up @@ -93,7 +119,15 @@ def mysql_instances(self, *filters):
"""
return self.client._get_and_filter(MySQLDatabase, *filters)

def mysql_create(self, label, region, engine, ltype, **kwargs):
def mysql_create(
self,
label,
region,
engine,
ltype,
engine_config: Union[MySQLDatabaseConfigOptions, Dict[str, Any]] = None,
**kwargs,
):
"""
Creates an :any:`MySQLDatabase` on this account with
the given label, region, engine, and node type. For example::
Expand Down Expand Up @@ -123,13 +157,16 @@ def mysql_create(self, label, region, engine, ltype, **kwargs):
:type engine: str or Engine
:param ltype: The Linode Type to use for this cluster
:type ltype: str or Type
:param engine_config: The configuration options for this MySQL cluster
:type engine_config: Dict[str, Any] or MySQLDatabaseConfigOptions
"""

params = {
"label": label,
"region": region,
"engine": engine,
"type": ltype,
"engine_config": engine_config,
}
params.update(kwargs)

Expand Down Expand Up @@ -216,7 +253,17 @@ def postgresql_instances(self, *filters):
"""
return self.client._get_and_filter(PostgreSQLDatabase, *filters)

def postgresql_create(self, label, region, engine, ltype, **kwargs):
def postgresql_create(
self,
label,
region,
engine,
ltype,
engine_config: Union[
PostgreSQLDatabaseConfigOptions, Dict[str, Any]
] = None,
**kwargs,
):
"""
Creates an :any:`PostgreSQLDatabase` on this account with
the given label, region, engine, and node type. For example::
Expand Down Expand Up @@ -246,13 +293,16 @@ def postgresql_create(self, label, region, engine, ltype, **kwargs):
:type engine: str or Engine
:param ltype: The Linode Type to use for this cluster
:type ltype: str or Type
:param engine_config: The configuration options for this PostgreSQL cluster
:type engine_config: Dict[str, Any] or PostgreSQLDatabaseConfigOptions
"""

params = {
"label": label,
"region": region,
"engine": engine,
"type": ltype,
"engine_config": engine_config,
}
params.update(kwargs)

Expand Down
150 changes: 149 additions & 1 deletion linode_api4/objects/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from dataclasses import dataclass
from typing import Optional

from deprecated import deprecated

from linode_api4.objects import Base, DerivedBase, MappedObject, Property
from linode_api4.objects import (
Base,
DerivedBase,
JSONObject,
MappedObject,
Property,
)


class DatabaseType(Base):
Expand Down Expand Up @@ -128,6 +137,143 @@ class PostgreSQLDatabaseBackup(DatabaseBackup):
api_endpoint = "/databases/postgresql/instances/{database_id}/backups/{id}"


@dataclass
class MySQLDatabaseConfigMySQLOptions(JSONObject):
"""
MySQLDatabaseConfigMySQLOptions represents the fields in the mysql
field of the MySQLDatabaseConfigOptions class
"""

connect_timeout: Optional[int] = None
default_time_zone: Optional[str] = None
group_concat_max_len: Optional[float] = None
information_schema_stats_expiry: Optional[int] = None
innodb_change_buffer_max_size: Optional[int] = None
innodb_flush_neighbors: Optional[int] = None
innodb_ft_min_token_size: Optional[int] = None
innodb_ft_server_stopword_table: Optional[str] = None
innodb_lock_wait_timeout: Optional[int] = None
innodb_log_buffer_size: Optional[int] = None
innodb_online_alter_log_max_size: Optional[int] = None
innodb_print_all_deadlocks: Optional[bool] = None
innodb_read_io_threads: Optional[int] = None
innodb_rollback_on_timeout: Optional[bool] = None
innodb_thread_concurrency: Optional[int] = None
innodb_write_io_threads: Optional[int] = None
interactive_timeout: Optional[int] = None
internal_tmp_mem_storage_engine: Optional[str] = None
log_output: Optional[str] = None
long_query_time: Optional[float] = None
max_allowed_packet: Optional[int] = None
max_heap_table_size: Optional[int] = None
net_buffer_length: Optional[int] = None
net_read_timeout: Optional[int] = None
net_write_timeout: Optional[int] = None
slow_query_log: Optional[bool] = None
sort_buffer_size: Optional[int] = None
sql_mode: Optional[str] = None
sql_require_primary_key: Optional[bool] = None
tmp_table_size: Optional[int] = None
wait_timeout: Optional[int] = None
Copy link
Contributor

@lgarber-akamai lgarber-akamai Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these fields correspond to the fields returned by DatabaseGroup(...).mysql_config_options()?

I think having explicit fields is still the right call if so, but we also need to make sure (unit test?) users can access any fields added to that endpoint in the future. Typically I would think this is something we just update as we go, but there being a dedicated endpoint to return fields make me think these changes could happen outside of an API release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, yes, it is the same fields returned by mysql_config_options(). That endpoint returns additional information about the fields too (min, max, description, example, etc.). I would hope that new fields wouldn't be added outside of an API release but if you think that is a possibility, then I may have to rethink my design.



@dataclass
class MySQLDatabaseConfigOptions(JSONObject):
"""
MySQLDatabaseConfigOptions is used to specify
a MySQL Database Cluster's configuration options during its creation.
"""

mysql: Optional[MySQLDatabaseConfigMySQLOptions] = None
binlog_retention_period: Optional[int] = None
service_log: Optional[bool] = None


@dataclass
class PostgreSQLDatabaseConfigPGLookoutOptions(JSONObject):
"""
PostgreSQLDatabasePGLookoutConfigOptions represents the fields in the pglookout
field of the PostgreSQLDatabasePGConfigOptions class
"""

max_failover_replication_time_lag: Optional[int] = None


@dataclass
class PostgreSQLDatabaseConfigPGOptions(JSONObject):
"""
PostgreSQLDatabasePGConfigOptions represents the fields in the pg
field of the PostgreSQLDatabasePGConfigOptions class
"""

autovacuum_analyze_scale_factor: Optional[float] = None
autovacuum_analyze_threshold: Optional[int] = None
autovacuum_freeze_max_age: Optional[int] = None
autovacuum_max_workers: Optional[int] = None
autovacuum_naptime: Optional[int] = None
autovacuum_vacuum_cost_delay: Optional[int] = None
autovacuum_vacuum_cost_limit: Optional[int] = None
autovacuum_vacuum_scale_factor: Optional[float] = None
autovacuum_vacuum_threshold: Optional[int] = None
bgwriter_delay: Optional[int] = None
bgwriter_flush_after: Optional[int] = None
bgwriter_lru_maxpages: Optional[int] = None
bgwriter_lru_multiplier: Optional[float] = None
deadlock_timeout: Optional[int] = None
default_toast_compression: Optional[str] = None
idle_in_transaction_session_timeout: Optional[int] = None
jit: Optional[bool] = None
log_autovacuum_min_duration: Optional[int] = None
log_error_verbosity: Optional[str] = None
log_line_prefix: Optional[str] = None
log_min_duration_statement: Optional[int] = None
log_temp_files: Optional[int] = None
max_files_per_process: Optional[int] = None
max_locks_per_transaction: Optional[int] = None
max_logical_replication_workers: Optional[int] = None
max_parallel_workers: Optional[int] = None
max_parallel_workers_per_gather: Optional[int] = None
max_pred_locks_per_transaction: Optional[int] = None
max_prepared_transactions: Optional[int] = None
max_replication_slots: Optional[int] = None
max_slot_wal_keep_size: Optional[int] = None
max_stack_depth: Optional[int] = None
max_standby_archive_delay: Optional[int] = None
max_standby_streaming_delay: Optional[int] = None
max_wal_senders: Optional[int] = None
max_worker_processes: Optional[int] = None
password_encryption: Optional[str] = None
pg_partman_bgw_interval: Optional[int] = None
pg_partman_bgw_role: Optional[str] = None
pg_stat_monitor_pgsm_enable_query_plan: Optional[bool] = None
pg_stat_monitor_pgsm_max_buckets: Optional[int] = None
pg_stat_statements_track: Optional[str] = None
temp_file_limit: Optional[int] = None
timezone: Optional[str] = None
track_activity_query_size: Optional[int] = None
track_commit_timestamp: Optional[str] = None
track_functions: Optional[str] = None
track_io_timing: Optional[str] = None
wal_sender_timeout: Optional[int] = None
wal_writer_delay: Optional[int] = None


@dataclass
class PostgreSQLDatabaseConfigOptions(JSONObject):
"""
PostgreSQLDatabaseConfigOptions is used to specify
a PostgreSQL Database Cluster's configuration options during its creation.
"""

pg: Optional[PostgreSQLDatabaseConfigPGOptions] = None
pg_stat_monitor_enable: Optional[bool] = None
pglookout: Optional[PostgreSQLDatabaseConfigPGLookoutOptions] = None
service_log: Optional[bool] = None
shared_buffers_percentage: Optional[float] = None
synchronous_replication: Optional[str] = None
work_mem: Optional[int] = None


class MySQLDatabase(Base):
"""
An accessible Managed MySQL Database.
Expand Down Expand Up @@ -158,6 +304,7 @@ class MySQLDatabase(Base):
"updated": Property(volatile=True, is_datetime=True),
"updates": Property(mutable=True),
"version": Property(),
"engine_config": Property(mutable=True),
}

@property
Expand Down Expand Up @@ -321,6 +468,7 @@ class PostgreSQLDatabase(Base):
"updated": Property(volatile=True, is_datetime=True),
"updates": Property(mutable=True),
"version": Property(),
"engine_config": Property(mutable=True),
}

@property
Expand Down
Loading