Skip to content
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
128 changes: 83 additions & 45 deletions .ci/scripts/check_deprecated_terms.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,113 @@
#!/usr/bin/env python3

import os
import re
import sys

DEPRECATED_TERMS = [
# .ci/scripts/check_deprecated_terms.py

import os, re, sys, argparse

# ---- Term sets ----
# Block these when you're on the *2.x* branch (i.e., forbid legacy 1.x names):
TERMS_1X = [
"provision-configs",
"provision-config-instances",
"results-publishing",
"results-publisher",
"load-worker-coordinator-hosts",
"execute-test",
]

SKIP_DIRS = [".git", "venv", "__pycache__", ".pytest_cache"]

# Block these when you're on the *1.x* branch (i.e., forbid 2.x names):
TERMS_2X = [
"cluster-configs",
"reporting",
"worker-hosts",
"run-test",
"test-run",
]

SKIP_DIRS = {".git", "venv", "__pycache__", ".pytest_cache", ".ci", "tests"}
VALID_EXTENSIONS = (".py", ".yml", ".yaml", ".md", ".sh", ".json", ".txt")

VARIANT_PATTERNS = []

def generate_variants(term):

SUPRESS_MARKERS = {
"block-1x": "check-deprecated-terms-disable-1x",
"block-2x": "check-deprecated-terms-disable-2x"
}

def generate_variants(term: str) -> set[str]:
base = term.replace("-", " ").replace("_", " ")
words = base.split()
variants = set()

# kebab-case, snake_case, PascalCase, camelCase
# kebab, snake, Pascal, camel
variants.add("-".join(words))
variants.add("_".join(words))
variants.add("".join([w.capitalize() for w in words])) # PascalCase
variants.add("".join([w.capitalize() for w in words])) # PascalCase
variants.add(words[0] + "".join([w.capitalize() for w in words[1:]])) # camelCase

# Word order flip for 2-word terms
if len(words) == 2:
# Optional: flip order for 2-word terms, but avoid silly "-ip" flips creating noise
if len(words) == 2 and not words[1].lower() == "ip":
variants.add("-".join(words[::-1]))
variants.add("_".join(words[::-1]))
variants.add(words[1] + words[0].capitalize()) # camelCase reverse

return variants

for term in DEPRECATED_TERMS:
for variant in generate_variants(term):
VARIANT_PATTERNS.append(re.compile(re.escape(variant), re.IGNORECASE))

def should_check_file(filename):
return filename.endswith(VALID_EXTENSIONS)

def main():
error_found = False


def build_patterns(terms: list[str]) -> list[re.Pattern]:
pats = []
for t in terms:
for v in generate_variants(t):
pats.append(re.compile(re.escape(v), re.IGNORECASE))
return pats

def should_check_file(path: str) -> bool:
return path.endswith(VALID_EXTENSIONS)

def walk_and_check(patterns: list[re.Pattern], mode: str) -> int:
error_found = 0
suppress_marker = SUPRESS_MARKERS.get(mode)
for root, _, files in os.walk("."):
if any(skip in root for skip in SKIP_DIRS):
if any(skip in root.split(os.sep) for skip in SKIP_DIRS):
continue

for f in files:
full_path = os.path.join(root, f)
if not should_check_file(full_path):
continue

try:
with open(full_path, "r", encoding="utf-8") as file:
for i, line in enumerate(file, 1):
for pattern in VARIANT_PATTERNS:
if pattern.search(line):
print(f"[Deprecated Term] {full_path}:{i}: {line.strip()}")
error_found = True
with open(full_path, "r", encoding="utf-8") as fh:
previous_line = ""
for i, line in enumerate(fh, 1):
if suppress_marker in previous_line or suppress_marker in line:
previous_line = line
continue
for patt in patterns:
if patt.search(line):
print(f"[Forbidden Term] {full_path}:{i}: {line.strip()}")
error_found = 1
break
except Exception as e:
print(f"[Warning] Skipped file {full_path}: {e}")

if error_found:
print("\n❌ Deprecated terms found. Please remove or rename them.")
return error_found

def main():
p = argparse.ArgumentParser(description="Check forbidden term set by mode or env.")
p.add_argument("--mode", choices=["block-1x", "block-2x"], default=os.getenv("OSB_TERM_MODE"))
args = p.parse_args()

mode = args.mode
if not mode:
print("No mode provided (use --mode block-1x | block-2x or set OSB_TERM_MODE). Exiting 0.")
sys.exit(0)

if mode == "block-1x":
terms = TERMS_1X
banner = "❌ 1.x terms found in 2.x branch. Replace with 2.x names."
else:
terms = TERMS_2X
banner = "❌ 2.x terms found in 1.x branch. Replace with 1.x names."

patterns = build_patterns(terms)
failed = walk_and_check(patterns, mode)
if failed:
print("\n" + banner)
sys.exit(1)

print("✅ No deprecated terms found.")
print("✅ No forbidden terms found for", mode)
sys.exit(0)

if __name__ == "__main__":
main()
26 changes: 23 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ jobs:
- name: Run the CI build script
run: bash .ci/build.sh build_and_unit_test

- name: Run deprecated term lint checker
run: .ci/scripts/check_deprecated_terms.py
if: contains(github.event.pull_request.labels.*.name, '2.x-terms-only')
- name: Detect term-check mode from labels
id: detect_mode
shell: bash
run: |
labels='${{ toJson(github.event.pull_request.labels.*.name) }}'
echo "PR labels: $labels"
mode=""

if echo "$labels" | grep -qi '"check-1.x-terms"'; then
mode="block-1x"
elif echo "$labels" | grep -qi '"check-2.x-terms"'; then
mode="block-2x"
fi

echo "mode=$mode" >> "$GITHUB_OUTPUT"

# 2) Run the checker only if a mode was selected
- name: Run term lint checker
if: steps.detect_mode.outputs.mode != ''
env:
OSB_TERM_MODE: ${{ steps.detect_mode.outputs.mode }}
run: |
python3 .ci/scripts/check_deprecated_terms.py --mode "$OSB_TERM_MODE"
2 changes: 1 addition & 1 deletion RELEASE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Add backport labels to PRs and commits so that changes can be added to `main` br
3. Run `opensearch-benchmark --version` to ensure that it is the correct version
4. Run `opensearch-benchmark --help`
5. Run `opensearch-benchmark list workloads`
6. Run a basic workload on Linux and MacOS: `opensearch-benchmark execute-test --workload pmc --test-mode`
6. Run a basic workload on Linux and MacOS: `opensearch-benchmark run --workload pmc --test-mode`
7. If you are fastidious, you can check the installed source files at `` `python3 -m site --user-site`/osbenchmark `` to verify that a recent change is indeed present.

8. Verify Docker Hub Staging OSB Image Works:
Expand Down
1 change: 1 addition & 0 deletions osbenchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ def handle_command_suggestions():
Check for common command mistakes and provide helpful suggestions
Returns True if suggestion was provided, False otherwise
"""
# check-deprecated-terms-disable-1x
DEPRECATED_SUBCOMMANDS = ["execute-test", "execute"]
if len(sys.argv) > 1 and sys.argv[1] in DEPRECATED_SUBCOMMANDS:
console.info("Did you mean 'run'?")
Expand Down
4 changes: 2 additions & 2 deletions osbenchmark/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Throughput(Enum):
MEDIAN = "median"

def summarize(results, cfg):
SummaryResultsPublisher(results, cfg).publish()
SummaryResultsPublisher(results, cfg).publish() # check-deprecated-terms-disable-1x


def compare(cfg, baseline_id, contender_id):
Expand Down Expand Up @@ -115,7 +115,7 @@ def comma_separated_string_to_number_list(string_list):
return results



# check-deprecated-terms-disable-1x
class SummaryResultsPublisher:
def __init__(self, results, config):
self.results = results
Expand Down
6 changes: 3 additions & 3 deletions osbenchmark/utils/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ def println(msg, console_prefix=None, end="\n", flush=False, force=False, logger


def progress(width=90):
return CmdLineProgressResultsPublisher(width, plain_output=PLAIN)

return CmdLineProgressResultsPublisher(width, plain_output=PLAIN) # check-deprecated-terms-disable-1x

# check-deprecated-terms-disable-1x
class CmdLineProgressResultsPublisher:
"""
CmdLineProgressResultsPublisher supports displaying an updating progress indication together with an information message.
This class supports displaying an updating progress indication together with an information message.

:param printer: allow use of a different print method to assist with patching in unittests
"""
Expand Down
Loading