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

Add support to run benchmark against min distribution #3684

Merged
merged 1 commit into from
Jun 28, 2023
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
5 changes: 4 additions & 1 deletion src/run_benchmark_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# compatible open source license.

import sys
from typing import Union

from manifests.build_manifest import BuildManifest
from manifests.bundle_manifest import BundleManifest
from system import console
from test_workflow.benchmark_test.benchmark_args import BenchmarkArgs
Expand All @@ -20,7 +22,8 @@ def main() -> int:
"""
benchmark_args = BenchmarkArgs()
console.configure(level=benchmark_args.logging_level)
manifest = BundleManifest.from_file(benchmark_args.bundle_manifest)
manifest: Union[BundleManifest, BuildManifest] = BundleManifest.from_file(benchmark_args.bundle_manifest) if not benchmark_args.min_distribution else \
BuildManifest.from_file(benchmark_args.bundle_manifest)
BenchmarkTestRunners.from_args(benchmark_args, manifest).run()
return 0

Expand Down
11 changes: 7 additions & 4 deletions src/test_workflow/benchmark_test/benchmark_test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
import os
import subprocess
from contextlib import contextmanager
from typing import Any, Generator
from typing import Any, Generator, Union

import requests
from requests.auth import HTTPBasicAuth
from retry.api import retry_call # type: ignore

from manifests.build_manifest import BuildManifest
from manifests.bundle_manifest import BundleManifest
from test_workflow.benchmark_test.benchmark_args import BenchmarkArgs


class BenchmarkTestCluster:
manifest: BundleManifest
manifest: Union[BundleManifest, BuildManifest]
work_dir: str
current_workspace: str
args: BenchmarkArgs
Expand All @@ -39,7 +40,7 @@ class BenchmarkTestCluster:

def __init__(
self,
bundle_manifest: BundleManifest,
bundle_manifest: Union[BundleManifest, BuildManifest],
config: dict,
args: BenchmarkArgs,
current_workspace: str
Expand Down Expand Up @@ -121,7 +122,9 @@ def setup_cdk_params(self, config: dict) -> dict:
else:
suffix = self.manifest.build.id + '-' + self.manifest.build.architecture
return {
"distributionUrl": self.manifest.build.location,
"distributionUrl": self.manifest.build.location if isinstance(self.manifest, BundleManifest) else
f"https://artifacts.opensearch.org/snapshots/core/opensearch/{self.manifest.build.version}/opensearch-min-"
f"{self.manifest.build.version}-linux-{self.manifest.build.architecture}-latest.tar.gz",
Comment on lines +126 to +127
Copy link
Member

Choose a reason for hiding this comment

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

Not really liking this but does build manifest not providing any of this information?
If so I would seriously thinking about Prudhvi suggestion to just assemble raw min without plugin before pushing to artifact.opensearch.org.

Copy link
Member

Choose a reason for hiding this comment

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

Probably create an issue related to this as a later improvements?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@rishabh6788 rishabh6788 Jun 28, 2023

Choose a reason for hiding this comment

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

As of now the BuildManifest doesn't have location field in the manifest therefore had to format the url to download the min distribution. It is also not supported in the schema.
I will create an issue to track this and update once the field becomes available.

Copy link
Member

Choose a reason for hiding this comment

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

I believe what we are saying is today snapshots min is created same way as we build distribution but just with 1 component OpenSearch. So it has all the things that distribution does. Regarding commit id that you want, we can get that if we also upload the manifest.yml to artifacts.opensearch.org in the same way as we upload min tarball.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gaiksaya Peter's change uploads the min-snapshot manifest too, it is of type BuildManifest which doesn't have location field in it as per schema.
min-snapshot manifest https://artifacts.opensearch.org/snapshots/core/opensearch/2.9.0-SNAPSHOT/opensearch-min-2.9.0-SNAPSHOT-linux-arm64-latest.tar.gz.build-manifest.yml
@peterzhuamazon

Copy link
Member

@peterzhuamazon peterzhuamazon Jun 28, 2023

Choose a reason for hiding this comment

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

Hi @gaiksaya we are creating with build, not assemble after build, this means only build manifest is present which seems that does not have the location information.

By running another round of assemble without plugin would just repackage min into a tar with a startup script and bundle manifest. The reason I am hesitate because that startup script will break due to no SEC and PA plugins.

Therefore, I would say put this as a later improvement in an issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bundling min with startup script is not the right way forward as it will fail due to lack of security plugin.

Copy link
Member

Choose a reason for hiding this comment

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

I see what you mean! Yeah we need to add check if plugin exists in start up scripts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created issue #3686 to track above mentioned requirements. @gaiksaya @peterzhuamazon

"vpcId": config["Constants"]["VpcId"],
"account": config["Constants"]["AccountId"],
"region": config["Constants"]["Region"],
Expand Down
6 changes: 4 additions & 2 deletions src/test_workflow/benchmark_test/benchmark_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

import abc
import os
from typing import Union

from manifests.build_manifest import BuildManifest
from manifests.bundle_manifest import BundleManifest
from test_workflow.benchmark_test.benchmark_args import BenchmarkArgs


class BenchmarkTestRunner(abc.ABC):
args: BenchmarkArgs
test_manifest: BundleManifest
test_manifest: Union[BundleManifest, BuildManifest]
security: bool
tests_dir: str

def __init__(self, args: BenchmarkArgs, test_manifest: BundleManifest) -> None:
def __init__(self, args: BenchmarkArgs, test_manifest: Union[BundleManifest, BuildManifest]) -> None:
self.args = args
self.test_manifest = test_manifest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import logging
import os
from typing import Union

import yaml
from retry.api import retry_call # type: ignore

from git.git_repository import GitRepository
from manifests.build_manifest import BuildManifest
from manifests.bundle_manifest import BundleManifest
from system.temporary_directory import TemporaryDirectory
from system.working_directory import WorkingDirectory
Expand All @@ -25,7 +27,7 @@ class BenchmarkTestRunnerOpenSearch(BenchmarkTestRunner):
"""
Runner to execute the performance tests for opensearch.
"""
def __init__(self, args: BenchmarkArgs, test_manifest: BundleManifest) -> None:
def __init__(self, args: BenchmarkArgs, test_manifest: Union[BundleManifest, BuildManifest]) -> None:
super().__init__(args, test_manifest)
logging.info("Running opensearch tests")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
from typing import Union


from manifests.build_manifest import BuildManifest
from manifests.bundle_manifest import BundleManifest
from test_workflow.benchmark_test.benchmark_args import BenchmarkArgs
from test_workflow.benchmark_test.benchmark_test_runner import BenchmarkTestRunner
Expand All @@ -18,7 +19,7 @@ class BenchmarkTestRunnerOpenSearchPlugins(BenchmarkTestRunner):
"""
Runner to execute the performance tests for opensearch plugins. The plugins need to define the test suite
"""
def __init__(self, args: BenchmarkArgs, test_manifest: BundleManifest) -> None:
def __init__(self, args: BenchmarkArgs, test_manifest: Union[BundleManifest, BuildManifest]) -> None:
super().__init__(args, test_manifest)

def get_plugin_repo_url(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
from typing import Union

from manifests.build_manifest import BuildManifest
from manifests.bundle_manifest import BundleManifest
from test_workflow.benchmark_test.benchmark_args import BenchmarkArgs
from test_workflow.benchmark_test.benchmark_test_runner import BenchmarkTestRunner
Expand All @@ -19,5 +21,5 @@ class BenchmarkTestRunners:
}

@classmethod
def from_args(cls, args: BenchmarkArgs, test_manifest: BundleManifest) -> BenchmarkTestRunner:
def from_args(cls, args: BenchmarkArgs, test_manifest: Union[BundleManifest, BuildManifest]) -> BenchmarkTestRunner:
return cls.RUNNERS.get(args.component, BenchmarkTestRunnerOpenSearchPlugins)(args, test_manifest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
schema-version: '1.2'
build:
name: OpenSearch
version: 2.9.0-SNAPSHOT
platform: linux
architecture: arm64
distribution: tar
id: '8042'
components:
- name: OpenSearch
repository: https://github.com/opensearch-project/OpenSearch.git
ref: 2.x
commit_id: 2c013429a028291b6136e3df4b0eb3d5759eaa06
artifacts:
maven:
- maven/org/opensearch/rest-api-spec/maven-metadata.xml
- maven/org/opensearch/rest-api-spec/maven-metadata.xml.sha1
- maven/org/opensearch/rest-api-spec/maven-metadata.xml.md5
dist:
- dist/opensearch-min-2.9.0-SNAPSHOT-linux-arm64.tar.gz
core-plugins:
- core-plugins/analysis-icu-2.9.0-SNAPSHOT.zip
- core-plugins/analysis-kuromoji-2.9.0-SNAPSHOT.zip
- core-plugins/analysis-nori-2.9.0-SNAPSHOT.zip
- core-plugins/analysis-phonetic-2.9.0-SNAPSHOT.zip
- core-plugins/analysis-smartcn-2.9.0-SNAPSHOT.zip
- core-plugins/analysis-stempel-2.9.0-SNAPSHOT.zip
- core-plugins/analysis-ukrainian-2.9.0-SNAPSHOT.zip
- core-plugins/discovery-azure-classic-2.9.0-SNAPSHOT.zip
- core-plugins/discovery-ec2-2.9.0-SNAPSHOT.zip
- core-plugins/discovery-gce-2.9.0-SNAPSHOT.zip
- core-plugins/identity-shiro-2.9.0-SNAPSHOT.zip
- core-plugins/ingest-attachment-2.9.0-SNAPSHOT.zip
- core-plugins/mapper-annotated-text-2.9.0-SNAPSHOT.zip
- core-plugins/mapper-murmur3-2.9.0-SNAPSHOT.zip
- core-plugins/mapper-size-2.9.0-SNAPSHOT.zip
- core-plugins/repository-azure-2.9.0-SNAPSHOT.zip
- core-plugins/repository-gcs-2.9.0-SNAPSHOT.zip
- core-plugins/repository-hdfs-2.9.0-SNAPSHOT.zip
- core-plugins/repository-s3-2.9.0-SNAPSHOT.zip
- core-plugins/store-smb-2.9.0-SNAPSHOT.zip
- core-plugins/transport-nio-2.9.0-SNAPSHOT.zip
version: 2.9.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def test_create_single_node_secure(self, mock_wait_for_processing: Optional[Mock
self.assertTrue("securityDisabled=false" in self.benchmark_test_cluster.params)
self.assertTrue("singleNodeCluster=true" in self.benchmark_test_cluster.params)
self.assertTrue("isInternal=true" in self.benchmark_test_cluster.params)
self.assertTrue("distributionUrl=https://artifacts.opensearch.org/bundles/1.0.0/41d5ae25183d4e699e92debfbe3f83bd/opensearch-1.0.0-linux-x64.tar.gz" in self.benchmark_test_cluster.params)
self.assertTrue(isinstance(self.manifest, BundleManifest))
with patch("subprocess.check_call") as mock_check_call:
self.benchmark_test_cluster.terminate()
self.assertEqual(mock_check_call.call_count, 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import os
import unittest
from typing import Optional
from unittest.mock import MagicMock, Mock, patch

from manifests.build_manifest import BuildManifest
from test_workflow.benchmark_test.benchmark_test_cluster import BenchmarkTestCluster


class TestBenchmarkTestClusterMin(unittest.TestCase):
DATA = os.path.join(os.path.dirname(__file__), "data")
MIN_MANIFEST = os.path.join(DATA, "min_distribution_manifest.yml")

def setUp(self, args: Optional[Mock] = None) -> None:
self.args = Mock()

self.args.workload = "nyc_taxis"
self.args.stack_suffix = "test-suffix"
self.args.insecure = True
self.args.single_node = False
self.args.min_distribution = True
self.manifest = BuildManifest.from_path(self.MIN_MANIFEST)
self.stack_name = "stack"
self.security = True
self.config = {"Constants": {"SecurityGroupId": "sg-00000000", "VpcId": "vpc-12345", "AccountId": "12345678",
"Region": "us-west-2", "Role": "role-arn", "serverAccessType": "prefixList", "restrictServerAccessTo": "pl-1234",
"isInternal": "true"}}
self.benchmark_test_cluster = BenchmarkTestCluster(bundle_manifest=self.manifest, config=self.config, args=self.args, current_workspace="current_workspace")

@patch("test_workflow.benchmark_test.benchmark_test_cluster.BenchmarkTestCluster.wait_for_processing")
def test_create_min_cluster(self, mock_wait_for_processing: Optional[Mock]) -> None:
mock_file = MagicMock(side_effect=[{"opensearch-infra-stack-test-suffix-8042-arm64": {"loadbalancerurl": "www.example.com"}}])
with patch("subprocess.check_call") as mock_check_call:
with patch("builtins.open", MagicMock()):
with patch("json.load", mock_file):
self.benchmark_test_cluster.start()
self.assertEqual(mock_check_call.call_count, 1)
self.assertTrue(isinstance(self.manifest, BuildManifest))
self.assertTrue("securityDisabled=true" in self.benchmark_test_cluster.params)
self.assertTrue("minDistribution=true" in self.benchmark_test_cluster.params)
self.assertTrue("distributionUrl=https://artifacts.opensearch.org/snapshots/core/opensearch/2.9.0-SNAPSHOT/"
"opensearch-min-2.9.0-SNAPSHOT-linux-arm64-latest.tar.gz" in self.benchmark_test_cluster.params)