Skip to content

Commit 54602ad

Browse files
ScottLinnncopybara-github
authored andcommitted
Support running DSQL with benchbase
PiperOrigin-RevId: 838952584
1 parent bf361c8 commit 54602ad

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

perfkitbenchmarker/linux_benchmarks/benchbase_benchmark.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from absl import flags
2525
from perfkitbenchmarker import benchmark_spec as bm_spec
2626
from perfkitbenchmarker import configs
27+
from perfkitbenchmarker import errors
2728
from perfkitbenchmarker import sample
2829
from perfkitbenchmarker import sql_engine_utils
2930
from perfkitbenchmarker.linux_packages import benchbase
@@ -75,7 +76,8 @@ def GetConfig(user_config: Dict[str, Any]) -> Dict[str, Any]:
7576
Returns:
7677
loaded benchmark configuration
7778
"""
78-
return configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)
79+
config = configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)
80+
return config
7981

8082

8183
# TODO(shuninglin): need to implement auth logic(automatic password gen)
@@ -96,6 +98,16 @@ def Prepare(benchmark_spec: bm_spec.BenchmarkSpec) -> None:
9698

9799
# Create the configuration file on the client VM
98100
benchbase.CreateConfigFile(client_vm)
101+
if FLAGS.db_engine == sql_engine_utils.AURORA_DSQL_POSTGRES:
102+
dsql: aws_aurora_dsql_db.AwsAuroraDsqlRelationalDb = (
103+
benchmark_spec.relational_db
104+
)
105+
# Ideally we want to use endpoint from get-cluster command but it's not
106+
# returning endpoint as documented. That said this hard-coded endpoint
107+
# construction is also documented so should be reliable.
108+
# https://docs.aws.amazon.com/aurora-dsql/latest/userguide/SECTION_authentication-token.html#authentication-token-cli
109+
endpoint: str = f'{dsql.cluster_id}.dsql.{dsql.region}.on.aws'
110+
benchbase.OverrideEndpoint(client_vm, endpoint)
99111
profile: str = (
100112
'postgres'
101113
if FLAGS.db_engine == sql_engine_utils.SPANNER_POSTGRES
@@ -107,6 +119,7 @@ def Prepare(benchmark_spec: bm_spec.BenchmarkSpec) -> None:
107119
f' {benchbase.CONFIG_FILE_NAME} --create=true --load=true'
108120
' --execute=false"'
109121
)
122+
110123
client_vm.RemoteCommand(load_command)
111124

112125

perfkitbenchmarker/linux_packages/benchbase.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ def CreateConfigFile(vm: virtual_machine.BaseVirtualMachine) -> None:
179179

180180
if db_engine == sql_engine_utils.AURORA_DSQL_POSTGRES:
181181
context['db_type'] = 'AURORADSQL'
182-
# For DSQL we use automatic username and password generation so comment out
183-
# the username and password elements.
184-
context['username_element'] = '<!--<username>admin</username>-->'
185-
context['password_element'] = '<!--<password>password</password>-->'
182+
# Following guide here to use automatic username and password generation:
183+
# https://github.com/amazon-contributing/aurora-dsql-benchbase-benchmarking/wiki#loading-data-and-running-tpc-c-against-an-aurora-dsql-cluster
184+
context['username_element'] = '<username>admin</username>'
185+
context['password_element'] = '<password></password>'
186186
else: # spanner by default
187187
context['db_type'] = 'POSTGRES'
188188
context['username_element'] = '<username>admin</username>'
@@ -209,6 +209,18 @@ def CreateConfigFile(vm: virtual_machine.BaseVirtualMachine) -> None:
209209
return
210210

211211

212+
def OverrideEndpoint(
213+
vm: virtual_machine.BaseVirtualMachine, endpoint: str
214+
) -> None:
215+
"""Overrides the endpoint in the Benchbase XML configuration file on the client VM.
216+
217+
Args:
218+
vm: The client virtual machine to create the file on.
219+
endpoint: The endpoint of the database.
220+
"""
221+
vm.RemoteCommand(f"sed -i 's/localhost/{endpoint}/g' {CONFIG_FILE_PATH}")
222+
223+
212224
def Uninstall(vm: virtual_machine.BaseVirtualMachine) -> None:
213225
"""Uninstalls the BenchBase package on the VM by removing the directory.
214226

perfkitbenchmarker/providers/aws/aws_aurora_dsql_db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class AwsAuroraDsqlRelationalDb(aws_relational_db.BaseAwsRelationalDb):
6969
def __init__(self, dsql_spec: AwsAuroraDsqlSpec):
7070
super().__init__(dsql_spec)
7171
self.cluster_id = None
72+
self.assigned_name = f'pkb-{FLAGS.run_uri}'
7273

7374
# DSQL has different format for tags:
7475
# https://docs.aws.amazon.com/cli/v1/reference/rds/create-db-cluster.html
@@ -77,7 +78,7 @@ def _MakeDsqlTags(self) -> list[str]:
7778
tags: dict[str, Any] = util.MakeDefaultTags()
7879
formatted_tags_list: list[str] = [
7980
'%s=%s' % (k, v) for k, v in sorted(tags.items())
80-
]
81+
] + ['Name=%s' % self.assigned_name]
8182
formatted_tags_str = ','.join(formatted_tags_list)
8283
return [formatted_tags_str]
8384

tests/linux_packages/benchbase_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def test_create_config_file_aurora_dsql(self, _):
100100
context = kwargs['context']
101101
self.assertEqual(context['db_type'], 'AURORADSQL')
102102
self.assertEqual(
103-
context['username_element'], '<!--<username>admin</username>-->'
103+
context['username_element'], '<username>admin</username>'
104104
)
105105
self.assertEqual(
106-
context['password_element'], '<!--<password>password</password>-->'
106+
context['password_element'], '<password></password>'
107107
)
108108
self.assertEqual(context['rate_element'], '<rate>unlimited</rate>')
109109
self.assertIn(

tests/providers/aws/aws_aurora_dsql_db_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def testMakeDsqlTags(self):
113113
):
114114
db = self.CreateDbFromSpec()
115115
tags = db._MakeDsqlTags()
116-
self.assertEqual(tags, ['tag1=value1,tag2=value2'])
116+
self.assertEqual(tags, ['tag1=value1,tag2=value2,Name=pkb-123'])
117117

118118
def testDescribeCluster(self):
119119
"""Tests that the describe cluster command is correct."""

0 commit comments

Comments
 (0)