Skip to content
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

Support alloydbomni service type #389

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
80 changes: 46 additions & 34 deletions aiven/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,20 @@ def _get_privatelink_connection_id_from_args(self) -> object | str:
raise argx.UserError(f"-p/--privatelink-connection-id cannot be used with route {self.args.route}")
return privatelink_connection_id

def _get_connection_info_pg(self, service_name: str) -> PGConnectionInfo:
"""PostgreSQL connection info"""
service = self.client.get_service(project=self.get_project(), service=service_name)

return PGConnectionInfo.from_service(
service,
route=self._get_route_from_args(),
usage=self._get_usage_from_args(),
privatelink_connection_id=self._get_privatelink_connection_id_from_args(),
username=self.args.username,
dbname=self.args.dbname,
sslmode=self.args.sslmode,
)

@arg.project
@arg.service_name
@arg("-r", "--route", choices=("dynamic", "privatelink", "public"))
Expand All @@ -1482,17 +1496,7 @@ def _get_privatelink_connection_id_from_args(self) -> object | str:
@arg("--sslmode", default="require", choices=("require", "verify-ca", "verify-full", "disable", "allow", "prefer"))
def service__connection_info__psql(self) -> None:
"""psql command string"""
service = self.client.get_service(project=self.get_project(), service=self.args.service_name)

ci = PGConnectionInfo.from_service(
service,
route=self._get_route_from_args(),
usage=self._get_usage_from_args(),
privatelink_connection_id=self._get_privatelink_connection_id_from_args(),
username=self.args.username,
dbname=self.args.dbname,
sslmode=self.args.sslmode,
)
ci = self._get_connection_info_pg(self.args.service_name)
cmd = ci.psql()
print(" ".join(cmd))

Expand All @@ -1507,17 +1511,7 @@ def service__connection_info__psql(self) -> None:
@arg("--sslmode", default="require", choices=("require", "verify-ca", "verify-full", "disable", "allow", "prefer"))
def service__connection_info__pg__uri(self) -> None:
"""PostgreSQL service URI"""
service = self.client.get_service(project=self.get_project(), service=self.args.service_name)

ci = PGConnectionInfo.from_service(
service,
route=self._get_route_from_args(),
usage=self._get_usage_from_args(),
privatelink_connection_id=self._get_privatelink_connection_id_from_args(),
username=self.args.username,
dbname=self.args.dbname,
sslmode=self.args.sslmode,
)
ci = self._get_connection_info_pg(self.args.service_name)
print(ci.uri())

@arg.project
Expand All @@ -1531,17 +1525,35 @@ def service__connection_info__pg__uri(self) -> None:
@arg("--sslmode", default="require", choices=("require", "verify-ca", "verify-full", "disable", "allow", "prefer"))
def service__connection_info__pg__string(self) -> None:
"""PostgreSQL connection string"""
service = self.client.get_service(project=self.get_project(), service=self.args.service_name)
ci = self._get_connection_info_pg(self.args.service_name)
print(ci.connection_string())

ci = PGConnectionInfo.from_service(
service,
route=self._get_route_from_args(),
usage=self._get_usage_from_args(),
privatelink_connection_id=self._get_privatelink_connection_id_from_args(),
username=self.args.username,
dbname=self.args.dbname,
sslmode=self.args.sslmode,
)
@arg.project
@arg.service_name
@arg("-r", "--route", choices=("dynamic", "privatelink", "public"))
@arg("--usage", choices=("primary", "replica"))
@arg("-p", "--privatelink-connection-id")
@arg("--replica", action="store_true")
@arg("-u", "--username", default="avnadmin")
@arg("-d", "--dbname", default="defaultdb")
@arg("--sslmode", default="require", choices=("require", "verify-ca", "verify-full", "disable", "allow", "prefer"))
def service__connection_info__alloydbomni__uri(self) -> None:
"""AlloyDB Omni service URI"""
ci = self._get_connection_info_pg(self.args.service_name)
print(ci.uri())

@arg.project
@arg.service_name
@arg("-r", "--route", choices=("dynamic", "privatelink", "public"))
@arg("--usage", choices=("primary", "replica"))
@arg("-p", "--privatelink-connection-id")
@arg("--replica", action="store_true")
@arg("-u", "--username", default="avnadmin")
@arg("-d", "--dbname", default="defaultdb")
@arg("--sslmode", default="require", choices=("require", "verify-ca", "verify-full", "disable", "allow", "prefer"))
def service__connection_info__alloydbomni__string(self) -> None:
"""AlloyDB Omni connection string"""
ci = self._get_connection_info_pg(self.args.service_name)
print(ci.connection_string())

@arg.project
Expand Down Expand Up @@ -2437,7 +2449,7 @@ def service__queries(self) -> None:
"total_time",
]
]
if service_type == "pg"
if service_type in ("pg", "alloydbomni")
else [
[
"digest_text",
Expand Down Expand Up @@ -2469,7 +2481,7 @@ def service__queries(self) -> None:
"temp_blks_read",
"temp_blks_written",
]
if service_type == "pg"
if service_type in ("pg", "alloydbomni")
else [
"digest",
"first_seen",
Expand Down
5 changes: 5 additions & 0 deletions aiven/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,11 @@ def get_service_query_stats(
) -> Sequence[dict[str, Any]]:
if service_type is None:
service_type = self.get_service(project, service)["service_type"]

# Currently, `alloydbomni` query stats are also exposed under `/pg/query/stats`.
if service_type == "alloydbomni":
service_type = "pg"

path = self.build_path("project", project, "service", service, service_type, "query", "stats")
return self.verify(
self.post,
Expand Down
2 changes: 1 addition & 1 deletion aiven/client/connection_info/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def from_service(
dbname: str,
sslmode: str,
) -> PGConnectionInfo:
if service["service_type"] != "pg":
if service["service_type"] not in ("pg", "alloydbomni"):
raise ConnectionInfoError("Cannot format pg connection info for service type {service_type}".format_map(service))

info = find_component(
Expand Down
Loading