Skip to content

Commit 76f29c3

Browse files
Merge pull request #3 from jaseci-labs/fix-issue-cli-auth
Add local version of Chart.js
2 parents 5e6570e + a6159c7 commit 76f29c3

5 files changed

Lines changed: 36 additions & 8 deletions

File tree

jac_loadtest_cli/jac.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ issues = "https://github.com/SahanUday/jac-loadtest/issues"
1818
packages = ["jac_loadtest_cli"]
1919

2020
[project.include.data]
21-
jac_loadtest_cli = ["templates/*.html"]
21+
jac_loadtest_cli = ["templates/*.html", "templates/vendor/*"]
2222

2323
[dependencies]
2424
jac-scale = ">=0.2.16"

jac_loadtest_cli/jac_loadtest_cli/output/reporter.jac

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ glob _LATENCY_THRESHOLDS: dict[str, dict[str, int]] = {
1414
};
1515

1616
glob _TEMPLATE_PATH: object = __import__("pathlib").Path(__file__).parent.parent / "templates" / "reporter_template.html";
17+
glob _CHARTJS_VENDOR_PATH: object = __import__("pathlib").Path(__file__).parent.parent / "templates" / "vendor" / "chart.umd.min.js";
1718

1819
def _latency_rating(value_ms: float, metric: str) -> tuple[str, str] {
1920
t = _LATENCY_THRESHOLDS[metric];
@@ -286,6 +287,7 @@ def render_html(
286287
) -> str {
287288
import json;
288289
import string;
290+
import html as _html;
289291
duration_s = actual_duration_s if actual_duration_s is not None else 0.0;
290292

291293
total_reqs = sum(s.total_requests for s in stats);
@@ -312,7 +314,7 @@ def render_html(
312314
endpoint_rows = "";
313315
for s in stats {
314316
ok_class = "ok" if s.success_rate_pct >= 99 else ("warn" if s.success_rate_pct >= 95 else "err");
315-
svc_cell = f"<td>{s.service}</td>" if is_microservice else "";
317+
svc_cell = f"<td>{_html.escape(s.service)}</td>" if is_microservice else "";
316318
_p50r = _latency_rating(s.p50_ms, "p50");
317319
_p95r = _latency_rating(s.p95_ms, "p95");
318320
_p99r = _latency_rating(s.p99_ms, "p99");
@@ -322,7 +324,7 @@ def render_html(
322324
endpoint_rows += (
323325
"<tr>"
324326
f"{svc_cell}"
325-
f"<td class='mono'>{s.endpoint}</td>"
327+
f"<td class='mono'>{_html.escape(s.endpoint)}</td>"
326328
f"<td class='num'>{s.total_requests}</td>"
327329
f"<td class='num'>{rps_str}</td>"
328330
f"<td class='num {ok_class}'>{s.success_rate_pct:.1f}%</td>"
@@ -347,9 +349,10 @@ def render_html(
347349
label = (
348350
f"{s.service}{s.endpoint}" if s.endpoint.startswith("/") else f"{s.service}/{s.endpoint}"
349351
) if is_microservice else s.endpoint;
352+
label = _html.escape(label);
350353
_bd_parts = [];
351354
for _bd in s.error_breakdown.items() {
352-
_bd_parts.append(f"<span class='err-tag'>{_bd[0]}: {_bd[1]}</span>");
355+
_bd_parts.append(f"<span class='err-tag'>{_html.escape(str(_bd[0]))}: {_bd[1]}</span>");
353356
}
354357
breakdown_cells = "".join(_bd_parts);
355358
error_rows += f"<tr><td class='mono'>{label}</td><td>{breakdown_cells}</td></tr>\n";
@@ -370,8 +373,8 @@ def render_html(
370373
_apdex_cls = _apdex_class(global_apdex);
371374

372375
template = string.Template(_TEMPLATE_PATH.read_text(encoding="utf-8"));
373-
return template.substitute(
374-
har_file=config.har_file,
376+
rendered = template.substitute(
377+
har_file=_html.escape(config.har_file or ""),
375378
mode=config.mode,
376379
vus=config.vus,
377380
duration_s=f"{duration_s:.0f}",
@@ -407,7 +410,7 @@ def render_html(
407410
workers=config.workers,
408411
ramp_up=config.ramp_up,
409412
timeout=config.timeout,
410-
url_meta=f"<span>URL: {config.url}</span>" if config.url else "",
413+
url_meta=f"<span>URL: {_html.escape(config.url)}</span>" if config.url else "",
411414
has_timeseries="true" if snaps else "false",
412415
ts_labels=json.dumps([f"{snap.timestamp:.0f}s" for snap in snaps]),
413416
ts_p50=json.dumps([round(snap.p50_ms, 1) for snap in snaps]),
@@ -420,4 +423,6 @@ def render_html(
420423
ep_p99=json.dumps([round(s.p99_ms, 1) for s in stats]),
421424
ep_p999=json.dumps([round(s.p999_ms, 1) for s in stats]),
422425
);
426+
chartjs_src = _CHARTJS_VENDOR_PATH.read_text(encoding="utf-8");
427+
return rendered.replace("__CHARTJS_INLINE__", chartjs_src, 1);
423428
}

jac_loadtest_cli/jac_loadtest_cli/templates/reporter_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>jac loadtest report</title>
7-
<script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
7+
<script>__CHARTJS_INLINE__</script>
88
<style>
99
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
1010
body { font-family: system-ui, sans-serif; background: #0f1117; color: #e2e8f0; padding: 24px; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014-2024 Chart.js Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jac_loadtest_cli/jac_loadtest_cli/templates/vendor/chart.umd.min.js

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)