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

Perf workflow: Added index codec and better exception handling #385

Merged
merged 2 commits into from
Apr 29, 2022
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
93 changes: 47 additions & 46 deletions perf_workflow/run_perf_suite/ccr_perf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import random
import shutil
import string
import sys

import requests
from git.git_repository import GitRepository
Expand All @@ -32,6 +31,9 @@ class CcrPerfTest:
MAX_ALLOWED_REPLICATION_LAG_SECONDS = 60
# TODO: Make credentials configurable/randomized
CREDS = HTTPBasicAuth("admin", "admin")
RETRIES = 3
DELAY = 15
BACKOFF = 2

def __init__(
self, test_config: dict, config, bundle_manifest, tests_result_dir, security
Expand All @@ -57,7 +59,6 @@ def get_infra_repo_url(self):
return "https://github.com/opensearch-project/opensearch-infra.git"

def run(self):
self.setup_logging()
if self.tests_result_dir is not None:
tests_dir = self.tests_result_dir + "/" + str(self.test_num)
else:
Expand Down Expand Up @@ -105,38 +106,33 @@ def run(self):
"default": [leaderCluster.endpoint_with_port],
"follower": [followerCluster.endpoint_with_port],
}
workload_options = self.workload_options(
leaderCluster, followerCluster
)
workload_options = self.workload_options()
args = PerfSuiteArgs(
self.test_config["Workload"], workload_options, 1, 0
)
try:
logging.info(
f"Starting test {self.description}, Leader: {leaderCluster.endpoint}, Follower: {followerCluster.endpoint}"
)
# Execute the suite.
perf_test_suite = PerfTestSuite(
self.bundle_manifest,
target_hosts,
self.security,
current_workspace,
tests_dir,
args,
self.TEST_OWNER,
self.CCR_SCENARIO,
)
perf_test_suite.execute()

# Get test results and validate the metrics.
result_json_file_path = max(
glob.glob(tests_dir + "/*.json"), key=os.path.getmtime
)
with open(result_json_file_path, "r") as file:
self.verify_result(json.load(file), leaderCluster, followerCluster)
except Exception as e:
self.failure_reason = str(e)
logging.error(f"Test failed for {self.description}: {e}")
logging.info(
f"Starting test {self.description}, Leader: {leaderCluster.endpoint}, Follower: {followerCluster.endpoint}"
)
# Execute the suite.
perf_test_suite = PerfTestSuite(
self.bundle_manifest,
target_hosts,
self.security,
current_workspace,
tests_dir,
args,
self.TEST_OWNER,
self.CCR_SCENARIO,
)
perf_test_suite.execute()

# Get test results and validate the metrics.
result_json_file_path = max(
glob.glob(tests_dir + "/*.json"), key=os.path.getmtime
)
with open(result_json_file_path, "r") as file:
self.verify_result(json.load(file), leaderCluster, followerCluster)

def create_cluster(self, bundle_manifest, config, stack_name, cluster_config, current_workspace):
if cluster_config.is_single_node_cluster:
Expand All @@ -145,9 +141,9 @@ def create_cluster(self, bundle_manifest, config, stack_name, cluster_config, cu
return PerfMultiNodeCluster.create(bundle_manifest, config, stack_name, cluster_config, current_workspace)

def verify_result(self, result, leaderCluster, followerCluster):
self.execution_id = result["testExecutionId"]
self.verify_checkpoints(followerCluster)
self.verify_doc_count(leaderCluster, followerCluster)
self.execution_id = result["testExecutionId"]
for telemetry_result in result["testResults"]["customTelemetryData"]["overall"]:
if (
telemetry_result["telemetryDevice"] == "ccr-stats"
Expand All @@ -168,43 +164,48 @@ def verify_doc_count(self, leaderCluster, followerCluster):
path = f"/{index_name}/_count?format=json"

leader_url = "".join([leaderCluster.endpoint_with_port, path])
leader_resp = requests.get(url=leader_url, auth=self.CREDS, verify=False)
leader_resp = retry_call(requests.get, fkwargs={"url": leader_url, "auth": self.CREDS, "verify": False},
tries=self.RETRIES, delay=self.DELAY, backoff=self.BACKOFF)
leader_doc_count = leader_resp.json()['count']

follower_url = "".join([followerCluster.endpoint_with_port, path])
follower_resp = requests.get(url=follower_url, auth=self.CREDS, verify=False)
follower_resp = retry_call(requests.get, fkwargs={"url": follower_url, "auth": self.CREDS, "verify": False},
tries=self.RETRIES, delay=self.DELAY, backoff=self.BACKOFF)
follower_doc_count = follower_resp.json()['count']

assert leader_doc_count == follower_doc_count, "Doc count on leader doesnt match with follower"
assert leader_doc_count == follower_doc_count, "Doc count on leader doesn't match with follower"

def verify_checkpoints(self, followerCluster):
index_name = self.test_config["Workload"]
path = f"/_plugins/_replication/{index_name}/_status?pretty"

url = "".join([followerCluster.endpoint_with_port, path])
follower_resp = requests.get(url=url, auth=self.CREDS, verify=False)
follower_resp = retry_call(requests.get, fkwargs={"url": url, "auth": self.CREDS, "verify": False},
tries=3, delay=15, backoff=2)
assert follower_resp.json()['status'] == "SYNCING", "Replication status is not syncing"
leader_checkpoint = follower_resp.json()['syncing_details']['leader_checkpoint']
follower_checkpoint = follower_resp.json()['syncing_details']['follower_checkpoint']

assert leader_checkpoint == follower_checkpoint, "Follower is not at same checkpoint as leader"

def setup_logging(self):
root = logging.getLogger()
root.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
root.addHandler(handler)

def workload_options(self, leaderCluster, followerCluster):
def workload_options(self):
workload_param = {
"ingest_percentage": 100,
"index_settings": {
"index": {
"number_of_shards": self.test_config.get("Shards", 1),
"number_of_replicas": self.test_config.get("Replica", 0),
"codec": "default"
}
}
}
telemetry_options = {
"ccr-stats-sample-interval": 1,
"ccr-stats-indices": {"follower": [self.test_config["Workload"]]},
}
workload_options = {
"telemetry-params": json.dumps(telemetry_options),
"workload-params": "number_of_shards:{},number_of_replicas:{}".format(
self.test_config.get("Shards", 1), self.test_config.get("Replica", 0)
),
"workload-params": json.dumps(workload_param)
}
if self.security:
# TODO: Move to configurable auth username and pwd.
Expand Down
15 changes: 13 additions & 2 deletions perf_workflow/run_perf_suite/perf_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import logging
import sys
import traceback

from ccr_perf_test import CcrPerfTest

class PerfRunner:
@classmethod
def run(cls, test: CcrPerfTest):
cls.setup_logging()
try:
test.run()
except Exception:
except Exception as e:
logging.error(f"Test failed for {test.description}: {e}")
test.failure_reason = e
traceback.print_exc()
# Not raising the exception as we're already logging the failure in the test result.
pass
Expand All @@ -27,6 +31,13 @@ def run(cls, test: CcrPerfTest):
test.failure_reason,
)

@classmethod
def setup_logging(cls):
root = logging.getLogger()
root.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
root.addHandler(handler)

class PerfTestResult:
def __init__(self, test_num, test_description, success, execution_id, failure_reason):
Expand Down