Skip to content

Commit 1f435ae

Browse files
committed
test: add Micrometer compatibility workflow
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent cc4f0c1 commit 1f435ae

7 files changed

Lines changed: 279 additions & 0 deletions

File tree

.github/renovate-tracked-deps.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
"mise"
3737
]
3838
},
39+
".github/workflows/micrometer-compatibility.yml": {
40+
"regex": [
41+
"mise"
42+
]
43+
},
3944
".github/workflows/lint.yml": {
4045
"regex": [
4146
"mise"
@@ -125,6 +130,7 @@
125130
"hugo",
126131
"java",
127132
"lychee",
133+
"maven",
128134
"node",
129135
"npm:renovate",
130136
"protoc",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: Micrometer Compatibility
3+
4+
on:
5+
pull_request:
6+
workflow_dispatch:
7+
inputs:
8+
micrometer-repository:
9+
description: Micrometer repository to test, in owner/name form
10+
required: false
11+
default: micrometer-metrics/micrometer
12+
micrometer-ref:
13+
description: Micrometer branch, tag, or commit to test
14+
required: false
15+
default: main
16+
17+
permissions: {}
18+
19+
jobs:
20+
micrometer-compatibility:
21+
runs-on: ubuntu-24.04
22+
steps:
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
24+
with:
25+
persist-credentials: false
26+
- uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1
27+
with:
28+
version: v2026.5.5
29+
sha256: 3aaab5c05a8a94a93b42b4f581779bbd5c44ddb251e7f3639fc671ec5c6aab8a
30+
- name: Cache local Maven repository
31+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
32+
with:
33+
path: ~/.m2/repository
34+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
35+
restore-keys: |
36+
${{ runner.os }}-maven-
37+
- name: Run Micrometer compatibility tests
38+
run: |
39+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
40+
export MICROMETER_REPOSITORY="${{ github.event.inputs.micrometer-repository }}"
41+
export MICROMETER_REF="${{ github.event.inputs.micrometer-ref }}"
42+
fi
43+
mise run micrometer:test

.mise/lib/micrometer_compat.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
import os
6+
import subprocess
7+
import xml.etree.ElementTree as ET
8+
from pathlib import Path
9+
from typing import Optional
10+
11+
12+
DEFAULT_MICROMETER_DIR = Path(
13+
os.environ.get("MICROMETER_DIR", "/tmp/micrometer-compat")
14+
)
15+
DEFAULT_MICROMETER_REPOSITORY = os.environ.get(
16+
"MICROMETER_REPOSITORY", "micrometer-metrics/micrometer"
17+
)
18+
DEFAULT_MICROMETER_REMOTE = os.environ.get("MICROMETER_REMOTE", "origin")
19+
DEFAULT_MICROMETER_REF = os.environ.get("MICROMETER_REF", "main")
20+
DEFAULT_INIT_SCRIPT = Path(
21+
os.environ.get("MICROMETER_INIT_SCRIPT", "/tmp/micrometer-prom-local.init.gradle")
22+
)
23+
DEFAULT_PROM_VERSION = os.environ.get("PROM_VERSION")
24+
25+
26+
def run_cmd(cmd: list[str], cwd: Optional[Path] = None) -> None:
27+
subprocess.run(cmd, cwd=cwd, check=True)
28+
29+
30+
def micrometer_repository_url(repository: str) -> str:
31+
return f"https://github.com/{repository}.git"
32+
33+
34+
def check_clean_worktree(micrometer_dir: Path) -> None:
35+
result = subprocess.run(
36+
["git", "status", "--short"],
37+
cwd=micrometer_dir,
38+
check=True,
39+
capture_output=True,
40+
text=True,
41+
)
42+
if result.stdout.strip():
43+
raise RuntimeError(
44+
f"{micrometer_dir} has uncommitted changes; use a clean clone or set MICROMETER_DIR"
45+
)
46+
47+
48+
def get_prom_version(root_dir: Path = Path.cwd()) -> str:
49+
configured_version = DEFAULT_PROM_VERSION
50+
if configured_version:
51+
return configured_version
52+
pom = ET.parse(root_dir / "pom.xml")
53+
root = pom.getroot()
54+
version = root.findtext("./{*}version")
55+
if not version:
56+
version = root.findtext("./{*}parent/{*}version")
57+
if not version:
58+
raise RuntimeError("could not determine Prometheus version from pom.xml")
59+
return version
60+
61+
62+
def write_init_script(
63+
init_script: Path = DEFAULT_INIT_SCRIPT, prom_version: Optional[str] = None
64+
) -> None:
65+
if prom_version is None:
66+
prom_version = get_prom_version()
67+
init_script.write_text(
68+
f"""allprojects {{
69+
repositories {{
70+
mavenLocal()
71+
mavenCentral()
72+
gradlePluginPortal()
73+
}}
74+
configurations.configureEach {{
75+
resolutionStrategy.eachDependency {{ details ->
76+
if (details.requested.group == 'io.prometheus') {{
77+
details.useVersion('{prom_version}')
78+
details.because(
79+
'Use local prom_client_java artifacts for downstream compatibility testing'
80+
)
81+
}}
82+
}}
83+
}}
84+
}}
85+
""",
86+
encoding="utf-8",
87+
)
88+
89+
90+
def prepare_repo(
91+
micrometer_dir: Path = DEFAULT_MICROMETER_DIR,
92+
repository: str = DEFAULT_MICROMETER_REPOSITORY,
93+
remote: str = DEFAULT_MICROMETER_REMOTE,
94+
ref: str = DEFAULT_MICROMETER_REF,
95+
) -> None:
96+
repository_url = micrometer_repository_url(repository)
97+
if (micrometer_dir / ".git").is_dir():
98+
check_clean_worktree(micrometer_dir)
99+
run_cmd(
100+
["git", "remote", "set-url", remote, repository_url], cwd=micrometer_dir
101+
)
102+
run_cmd(["git", "fetch", remote, ref], cwd=micrometer_dir)
103+
else:
104+
run_cmd(
105+
[
106+
"git",
107+
"clone",
108+
repository_url,
109+
str(micrometer_dir),
110+
]
111+
)
112+
run_cmd(["git", "fetch", remote, ref], cwd=micrometer_dir)
113+
run_cmd(
114+
["git", "checkout", "-B", "codex-micrometer-compat", "FETCH_HEAD"],
115+
cwd=micrometer_dir,
116+
)
117+
118+
119+
def install_local_artifacts(root_dir: Path = Path.cwd()) -> None:
120+
run_cmd(
121+
[
122+
"./mvnw",
123+
"install",
124+
"-DskipTests",
125+
"-Dcoverage.skip=true",
126+
"-Dcheckstyle.skip=true",
127+
"-Dwarnings=-nowarn",
128+
],
129+
cwd=root_dir,
130+
)
131+
132+
133+
def run_gradle_test(
134+
test_selector: Optional[str] = None,
135+
micrometer_dir: Path = DEFAULT_MICROMETER_DIR,
136+
init_script: Path = DEFAULT_INIT_SCRIPT,
137+
) -> None:
138+
cmd = [
139+
"./gradlew",
140+
"--no-daemon",
141+
"-I",
142+
str(init_script),
143+
":micrometer-registry-prometheus:test",
144+
]
145+
if test_selector:
146+
cmd.extend(["--tests", test_selector])
147+
run_cmd(cmd, cwd=micrometer_dir)

.mise/tasks/micrometer/prepare.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
# [MISE] description="Install local artifacts and check out a target Micrometer ref"
4+
# [MISE] alias="micrometer:prepare"
5+
6+
import sys
7+
8+
9+
sys.path.insert(0, ".mise/lib")
10+
11+
12+
def main() -> int:
13+
from micrometer_compat import (
14+
install_local_artifacts,
15+
prepare_repo,
16+
write_init_script,
17+
)
18+
19+
install_local_artifacts()
20+
prepare_repo()
21+
write_init_script()
22+
return 0
23+
24+
25+
if __name__ == "__main__":
26+
raise SystemExit(main())
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
# [MISE] description="Run Micrometer PrometheusMeterRegistryTest against a target Micrometer ref"
4+
# [MISE] alias="micrometer:test-class"
5+
6+
import sys
7+
8+
9+
sys.path.insert(0, ".mise/lib")
10+
11+
12+
def main() -> int:
13+
from micrometer_compat import (
14+
install_local_artifacts,
15+
prepare_repo,
16+
run_gradle_test,
17+
write_init_script,
18+
)
19+
20+
install_local_artifacts()
21+
prepare_repo()
22+
write_init_script()
23+
run_gradle_test("io.micrometer.prometheusmetrics.PrometheusMeterRegistryTest")
24+
return 0
25+
26+
27+
if __name__ == "__main__":
28+
raise SystemExit(main())

.mise/tasks/micrometer/test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
# [MISE] description="Run Micrometer Prometheus registry tests against a target Micrometer ref"
4+
# [MISE] alias="micrometer:test"
5+
6+
import sys
7+
8+
9+
sys.path.insert(0, ".mise/lib")
10+
11+
12+
def main() -> int:
13+
from micrometer_compat import (
14+
install_local_artifacts,
15+
prepare_repo,
16+
run_gradle_test,
17+
write_init_script,
18+
)
19+
20+
install_local_artifacts()
21+
prepare_repo()
22+
write_init_script()
23+
run_gradle_test()
24+
return 0
25+
26+
27+
if __name__ == "__main__":
28+
raise SystemExit(main())

mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"go:github.com/grafana/oats" = "0.6.1"
33
hugo = "0.161.1"
44
java = "temurin-25.0.3+9.0.LTS"
5+
maven = "3.9.15"
56
node = "24.15.0"
67
protoc = "34.1"
78

0 commit comments

Comments
 (0)