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

[Benchmark] Add mechanism to retreive the logs from test-execution.json #4686

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ruamel-yaml = "~=0.17.21"
markdownify = "~=0.12.1"
mistune = "~=3.0.1"
semver = ">=3,<4"
pandas = "~=2.2.2"

[dev-packages]

Expand Down
132 changes: 110 additions & 22 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions jenkins/opensearch/benchmark-test-endpoint.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ parameters {
password: PASSWORD,
workload: TEST_WORKLOAD,
userTag: USER_TAGS.isEmpty() ? "security-enabled:${SECURITY_ENABLED}" : "${USER_TAGS},security-enabled:${SECURITY_ENABLED}",
suffix: "${BUILD_NUMBER}",
workloadParams: WORKLOAD_PARAMS,
testProcedure: TEST_PROCEDURE,
excludeTasks: EXCLUDE_TASKS,
Expand All @@ -129,10 +130,14 @@ parameters {
captureSegmentReplicationStat: CAPTURE_SEGMENT_REPLICATION_STAT,
telemetryParams: TELEMETRY_PARAMS
)
stash includes: 'test_execution.*', name: "benchmark"

}
}
post {
always {
unstash "benchmark"
archiveArtifacts artifacts: 'test_execution.*'
postCleanup()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging
import os
import subprocess
from typing import Union

import yaml
Expand Down Expand Up @@ -42,8 +43,10 @@ def run_tests(self) -> None:
cluster = BenchmarkTestCluster(self.args)
cluster.start()
benchmark_test_suite = BenchmarkTestSuite(cluster.endpoint_with_port, self.security, self.args, cluster.fetch_password())
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)

try:
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)
finally:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we move the docker rm command to BenchmarkTestSuite class to a method like remove_container or whatever you like and then use that?

else:
config = yaml.safe_load(self.args.config)

Expand All @@ -53,4 +56,7 @@ def run_tests(self) -> None:
with WorkingDirectory(current_workspace):
with BenchmarkCreateCluster.create(self.args, self.test_manifest, config, current_workspace) as test_cluster:
benchmark_test_suite = BenchmarkTestSuite(test_cluster.endpoint_with_port, self.security, self.args, test_cluster.fetch_password())
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)
try:
benchmark_test_suite.execute()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why remove retry_call?

finally:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
26 changes: 24 additions & 2 deletions src/test_workflow/benchmark_test/benchmark_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import glob
import json
import logging
import os
import shutil
import subprocess
from typing import Any

import pandas as pd

from system.temporary_directory import TemporaryDirectory
from test_workflow.benchmark_test.benchmark_args import BenchmarkArgs


Expand Down Expand Up @@ -37,7 +43,7 @@ def __init__(
self.password = password

# Pass the cluster endpoints with -t for multi-cluster use cases(e.g. cross-cluster-replication)
self.command = 'docker run --rm'
self.command = f'docker run --name docker-container-{self.args.stack_suffix}'
if self.args.benchmark_config:
self.command += f" -v {args.benchmark_config}:/opensearch-benchmark/.benchmark/benchmark.ini"
self.command += f" opensearchproject/opensearch-benchmark:latest execute-test --workload={self.args.workload} " \
Expand Down Expand Up @@ -67,11 +73,27 @@ def __init__(
if self.args.telemetry_params:
self.command += f" --telemetry-params '{self.args.telemetry_params}'"

def execute(self) -> None:
if self.security:
self.command += f' --client-options="timeout:300,use_ssl:true,verify_certs:false,basic_auth_user:\'{self.args.username}\',basic_auth_password:\'{self.password}\'"'
else:
self.command += ' --client-options="timeout:300"'

def execute(self) -> None:
log_info = f"Executing {self.command.replace(self.endpoint, len(self.endpoint) * '*').replace(self.args.username, len(self.args.username) * '*')}"
logging.info(log_info.replace(self.password, len(self.password) * '*') if self.password else log_info)
subprocess.check_call(f"{self.command}", cwd=os.getcwd(), shell=True)
with TemporaryDirectory() as work_dir:
Copy link
Collaborator

@rishabh6788 rishabh6788 May 8, 2024

Choose a reason for hiding this comment

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

move this file processing logic a new method and call that method only in the case endpoint is provided. This way the existing nightly runs will not be affected and we can enable it whenever we are ready.

subprocess.check_call(f"docker cp docker-container-{self.args.stack_suffix}:opensearch-benchmark/. {str(work_dir.path)}", cwd=os.getcwd(), shell=True)
file_path = glob.glob(os.path.join(str(work_dir.path), "test_executions", "*", "test_execution.json"))
self.convert(file_path[0])

def convert(self, results: str) -> None:
with open(results) as file:
data = json.load(file)
formatted_data = pd.json_normalize(data["results"]["op_metrics"])
formatted_data.to_csv(os.path.join(os.getcwd(), "test_execution.csv"), index=False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename the csv file to test_execution_<suffix>.json

df = pd.read_csv(os.path.join(os.getcwd(), "test_execution.csv"))
pd.set_option('display.width', int(2 * shutil.get_terminal_size().columns))
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
logging.info(f"\n{df}")
Loading
Loading