Skip to content

Commit

Permalink
setting application name to track the usage of Workload Replicator (#137
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DevanathanSabapathy1 authored Jan 8, 2024
1 parent 9673e86 commit 084e141
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 3 additions & 1 deletion common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def db_connect(
database=None,
odbc_driver=None,
drop_return=False,
app_name=None
):
if interface == "psql":
conn = redshift_connector.connect(
user=username, password=password, host=host, port=port, database=database
user=username, password=password, host=host, port=port,
database=database, application_name=app_name
)

# if drop_return is set, monkey patch driver to not store result set in memory
Expand Down
23 changes: 22 additions & 1 deletion core/extract/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import common.config as config_helper
import common.log as log_helper
from common import aws_service as aws_service_helper
from common.util import cluster_dict
from common.util import cluster_dict, db_connect
import core.extract.extractor as extractor

logger = logging.getLogger("WorkloadReplicatorLogger")
Expand Down Expand Up @@ -62,6 +62,27 @@ def main():
if not e.load_driver():
sys.exit("Failed to load driver")

# setting application name for tracking
application = "WorkloadReplicator-Extract"

host = config.get("source_cluster_endpoint").split(".")[0]
port = int(config.get("source_cluster_endpoint").split(":")[-1].split("/")[0])
DbUser = config.get("master_username")
DbName = config.get("source_cluster_endpoint").split("/")[-1]
region = config.get("region")
endpoint = config.get('source_cluster_endpoint').split(":")[0]

response = aws_service_helper.redshift_get_cluster_credentials(
user=DbUser,
database_name=DbName,
cluster_id=host,
region=region)
db_connect(host=endpoint,
port=port,
database=DbName,
password=response['DbPassword'],
username=response['DbUser'], app_name=application)

# Run extract job
(
extraction_name,
Expand Down
22 changes: 22 additions & 0 deletions core/replay/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
is_serverless,
CredentialsException,
bucket_dict,
db_connect
)
import report_gen
from unload_sys_table import UnloadSysTable
Expand Down Expand Up @@ -95,6 +96,27 @@ def main():
logger.info("No logs to replay, nothing to do.")
sys.exit()

# setting application name for tracking
application = "WorkloadReplicator-Replay"

host = config.get("target_cluster_endpoint").split(".")[0]
port = int(config.get("target_cluster_endpoint").split(":")[-1].split("/")[0])
DbUser = config.get("master_username")
DbName = config.get("target_cluster_endpoint").split("/")[-1]
region = config.get("target_cluster_region")
endpoint = config.get('target_cluster_endpoint').split(":")[0]

response = aws_service_helper.redshift_get_cluster_credentials(
user=DbUser,
database_name=DbName,
cluster_id=host,
region=region)
db_connect(host=endpoint,
port=port,
database=DbName,
password=response['DbPassword'],
username=response['DbUser'], app_name=application)

# Actual replay
logger.debug("Starting replay")
complete = False
Expand Down

0 comments on commit 084e141

Please sign in to comment.