-
Notifications
You must be signed in to change notification settings - Fork 831
add Benchmark update & cleanup mise tasks #1664
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
47e2988
add bench
zeitlinger dd5f9c3
update benchmark
zeitlinger d74e3c9
update benchmark
zeitlinger 52722d2
update benchmark
zeitlinger 8d00766
improve mise tasks
zeitlinger b57ef39
use python
zeitlinger 2103314
update benchmark
zeitlinger f49854c
update benchmark
zeitlinger 9fa1038
update benchmark
zeitlinger e21400b
cleanup mise and use JDK 25 for release build as well
zeitlinger a57d8d0
format
zeitlinger 89037da
format
zeitlinger c963d4a
format
zeitlinger e660b76
format
zeitlinger f8569e3
format
zeitlinger b6b4701
format
zeitlinger 145d908
Update .github/workflows/test-release-build.yml
zeitlinger 9f4dce1
Update .mise/tasks/update_benchmarks.py
zeitlinger 27df093
spelling
zeitlinger b37b9ec
update bench
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,4 @@ max_line_length = 110 | |
| [*.py] | ||
| # checked by black | ||
| indent_size = 4 | ||
| max_line_length = 120 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| #MISE description="Build release package" | ||
| #USAGE arg "<tag>" env="TAG" default="1.5.0-SNAPSHOT" | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # shellcheck disable=SC2154 # is set by mise | ||
| VERSION=${usage_tag#v} | ||
|
|
||
| mise run set-version "$VERSION" | ||
| mvn -B package -P 'release,!default' -Dmaven.test.skip=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # [MISE] description="Make sure the BOM has all necessary modules" | ||
|
|
||
| import difflib | ||
| import re | ||
| import sys | ||
| from fnmatch import fnmatch | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[2] # repo root (.. from .mise/tasks) | ||
| IGNORE_DIRS = {"prometheus-metrics-parent"} | ||
| MODULE_PREFIX = "prometheus-metrics" | ||
| BOM_POM = ROOT / "prometheus-metrics-bom" / "pom.xml" | ||
|
|
||
|
|
||
| def first_artifact_id(pom_file: Path) -> str: | ||
| """Return the second <artifactId> value from the given pom.xml (matches original script). | ||
|
|
||
| The original shell function greps all <artifactId> lines and returns the second one | ||
| (head -n 2 | tail -n 1). We replicate that behavior exactly. | ||
| """ | ||
| if not pom_file.is_file(): | ||
| raise FileNotFoundError(f"File {pom_file} does not exist.") | ||
|
|
||
| text = pom_file.read_text(encoding="utf-8") | ||
| matches = re.findall(r"<artifactId>\s*(.*?)\s*</artifactId>", text) | ||
| if len(matches) < 2: | ||
| return "" | ||
| return matches[1].strip() | ||
|
|
||
|
|
||
| def add_dir(dir_path: Path, want: List[str]): | ||
| if not dir_path.is_dir(): | ||
| raise FileNotFoundError(f"Directory {dir_path} does not exist.") | ||
|
|
||
| if any(dir_path.name == ig for ig in IGNORE_DIRS): | ||
| print(f"Skipping {dir_path}") | ||
| return | ||
|
|
||
| pom = dir_path / "pom.xml" | ||
| if not pom.is_file(): | ||
| raise FileNotFoundError(f"File {pom} does not exist.") | ||
|
|
||
| artifact_id = first_artifact_id(pom) | ||
| if not artifact_id: | ||
| raise RuntimeError(f"No artifactId found in {pom}") | ||
|
|
||
| print(f"Found artifactId '{artifact_id}' in {pom}") | ||
| want.append(artifact_id) | ||
|
|
||
|
|
||
| def collect_want(root: Path) -> List[str]: | ||
| want: List[str] = [] | ||
| # top-level prometheus-metrics* | ||
| for entry in sorted(root.iterdir()): | ||
| if entry.is_dir() and fnmatch(entry.name, f"{MODULE_PREFIX}*"): | ||
| add_dir(entry, want) | ||
|
|
||
| # prometheus-metrics-tracer/prometheus-metrics* | ||
| tracer_dir = root / "prometheus-metrics-tracer" | ||
| if tracer_dir.is_dir(): | ||
| for entry in sorted(tracer_dir.iterdir()): | ||
| if entry.is_dir() and fnmatch(entry.name, f"{MODULE_PREFIX}*"): | ||
| add_dir(entry, want) | ||
|
|
||
| # deduplicate and sort | ||
| want_unique = sorted(set(want)) | ||
| return want_unique | ||
|
|
||
|
|
||
| def collect_have(bom_pom: Path) -> List[str]: | ||
| if not bom_pom.is_file(): | ||
| raise FileNotFoundError(f"BOM file {bom_pom} does not exist.") | ||
|
|
||
| text = bom_pom.read_text(encoding="utf-8") | ||
| # find artifactId values that start with MODULE_PREFIX | ||
| matches = re.findall( | ||
| r"<artifactId>\s*(%s[^<\s]*)\s*</artifactId>" % re.escape(MODULE_PREFIX), text | ||
| ) | ||
| return sorted(matches) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| try: | ||
| want = collect_want(ROOT) | ||
| have = collect_have(BOM_POM) | ||
|
|
||
| want_text = "\n".join(want) | ||
| have_text = "\n".join(have) | ||
|
|
||
| if want_text != have_text: | ||
| print( | ||
| "The BOM file prometheus-metrics-bom/bom.xml does not match the current directory contents." | ||
| ) | ||
| print("Expected:") | ||
| print(want_text) | ||
| print("Found:") | ||
| print(have_text) | ||
| print() | ||
| diff = difflib.unified_diff( | ||
| have_text.splitlines(keepends=True), | ||
| want_text.splitlines(keepends=True), | ||
| fromfile="found", | ||
| tofile="expected", | ||
| ) | ||
| sys.stdout.writelines(diff) | ||
| return 1 | ||
| else: | ||
| print("BOM file is up to date.") | ||
| return 0 | ||
|
|
||
| except Exception as e: | ||
| print(e, file=sys.stderr) | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
2 changes: 2 additions & 0 deletions
2
scripts/set-release-version-github-pages.sh → ...tasks/set-release-version-github-pages.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| #MISE description="Update version in all pom.xml files" | ||
| #USAGE arg "<version>" help="new version" | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # replace all occurrences '<version>1.5.0-SNAPSHOT</version>' with | ||
| # '<version>$usage_version</version>' in all pom.xml files in the current directory and | ||
| # subdirectories | ||
|
|
||
| # shellcheck disable=SC2154 # is set by mise | ||
| find . -name 'pom.xml' -exec \ | ||
| sed -i "s/<version>1.5.0-SNAPSHOT<\/version>/<version>$usage_version<\/version>/g" {} + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import os | ||
| import re | ||
| import sys | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| from update_benchmarks import update_pre_blocks_under_module | ||
|
|
||
| # Ensure the tasks directory is importable when running the test directly | ||
| here = os.path.dirname(__file__) | ||
| if here not in sys.path: | ||
| sys.path.insert(0, here) | ||
|
|
||
|
|
||
| class TestRunBenchmarksFiltering(unittest.TestCase): | ||
| def setUp(self): | ||
| # sample JMH table with mixed-class lines | ||
| self.table = ( | ||
| "Benchmark Mode Cnt Score Error Units\n" | ||
| "CounterBenchmark.codahaleIncNoLabels thrpt 57881.585 ops/s\n" | ||
| "HistogramBenchmark.prometheusNative thrpt 2385.134 ops/s\n" | ||
| "TextFormatUtilBenchmark.prometheusWriteToNull thrpt 885331.328 ops/s\n" | ||
| "CounterBenchmark.prometheusInc thrpt 54090.469 ops/s\n" | ||
| ) | ||
|
|
||
| # create temp dir to act as module path | ||
| self.tmpdir = tempfile.TemporaryDirectory() | ||
| self.module_path = self.tmpdir.name | ||
|
|
||
| # Create three files with a javadoc <pre> block that contains mixed results | ||
| self.files = {} | ||
| javadoc_pre = ( | ||
| "/**\n" | ||
| " * Example javadoc\n" | ||
| " * <pre>\n" | ||
| " * Benchmark Mode Cnt Score Error Units\n" | ||
| " * CounterBenchmark.codahaleIncNoLabels thrpt 57881.585 ops/s\n" | ||
| " * HistogramBenchmark.prometheusNative thrpt 2385.134 ops/s\n" | ||
| " * TextFormatUtilBenchmark.prometheusWriteToNull thrpt 885331.328 ops/s\n" | ||
| " * CounterBenchmark.prometheusInc thrpt 54090.469 ops/s\n" | ||
| " * </pre>\n" | ||
| " */\n" | ||
| ) | ||
|
|
||
| for cls in ( | ||
| "CounterBenchmark", | ||
| "HistogramBenchmark", | ||
| "TextFormatUtilBenchmark", | ||
| ): | ||
| fname = os.path.join(self.module_path, f"{cls}.java") | ||
| with open(fname, "w", encoding="utf-8") as f: | ||
| f.write(javadoc_pre) | ||
| f.write(f"public class {cls} {{}}\n") | ||
| self.files[cls] = fname | ||
|
|
||
| def tearDown(self): | ||
| self.tmpdir.cleanup() | ||
|
|
||
| def _read_pre_contents(self, path): | ||
| with open(path, "r", encoding="utf-8") as f: | ||
| content = f.read() | ||
| m = re.search(r"<pre>\n([\s\S]*?)</pre>", content) | ||
| return m.group(1) if m else "" | ||
|
|
||
| def test_update_only_inserts_matching_class_lines(self): | ||
| updated = update_pre_blocks_under_module(self.module_path, self.table) | ||
| # All three files should be updated | ||
| self.assertEqual( | ||
| set(os.path.basename(p) for p in updated), | ||
| { | ||
| os.path.basename(self.files["CounterBenchmark"]), | ||
| os.path.basename(self.files["HistogramBenchmark"]), | ||
| os.path.basename(self.files["TextFormatUtilBenchmark"]), | ||
| }, | ||
| ) | ||
|
|
||
| # Verify CounterBenchmark file contains only CounterBenchmark lines | ||
| cb_pre = self._read_pre_contents(self.files["CounterBenchmark"]) | ||
| self.assertIn("CounterBenchmark.codahaleIncNoLabels", cb_pre) | ||
| self.assertIn("CounterBenchmark.prometheusInc", cb_pre) | ||
| self.assertNotIn("HistogramBenchmark.prometheusNative", cb_pre) | ||
| self.assertNotIn("TextFormatUtilBenchmark.prometheusWriteToNull", cb_pre) | ||
|
|
||
| # Verify HistogramBenchmark contains only its line | ||
| hb_pre = self._read_pre_contents(self.files["HistogramBenchmark"]) | ||
| self.assertIn("HistogramBenchmark.prometheusNative", hb_pre) | ||
| self.assertNotIn("CounterBenchmark.codahaleIncNoLabels", hb_pre) | ||
| self.assertNotIn("TextFormatUtilBenchmark.prometheusWriteToNull", hb_pre) | ||
|
|
||
| # Verify TextFormatUtilBenchmark contains only its line | ||
| tf_pre = self._read_pre_contents(self.files["TextFormatUtilBenchmark"]) | ||
| self.assertIn("TextFormatUtilBenchmark.prometheusWriteToNull", tf_pre) | ||
| self.assertNotIn("CounterBenchmark.prometheusInc", tf_pre) | ||
| self.assertNotIn("HistogramBenchmark.prometheusNative", tf_pre) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.