Add per_domain flag to report config
This commit is contained in:
parent
0bf67f6107
commit
e03c7bc434
3 changed files with 32 additions and 1 deletions
|
@ -38,6 +38,7 @@
|
||||||
- name: domain_traffic
|
- name: domain_traffic
|
||||||
label: Top Domains
|
label: Top Domains
|
||||||
chart: table
|
chart: table
|
||||||
|
per_domain: false
|
||||||
query: |
|
query: |
|
||||||
SELECT host AS bucket,
|
SELECT host AS bucket,
|
||||||
COUNT(*) AS value
|
COUNT(*) AS value
|
||||||
|
|
|
@ -133,6 +133,9 @@ def _generate_interval(interval: str, domain: Optional[str] = None) -> None:
|
||||||
if "{bucket}" not in definition["query"] or definition.get("global"):
|
if "{bucket}" not in definition["query"] or definition.get("global"):
|
||||||
# Global reports are generated separately
|
# Global reports are generated separately
|
||||||
continue
|
continue
|
||||||
|
if domain and not definition.get("per_domain", True):
|
||||||
|
# Skip reports marked as not applicable to per-domain runs
|
||||||
|
continue
|
||||||
|
|
||||||
name = definition["name"]
|
name = definition["name"]
|
||||||
query = definition["query"].replace("{bucket}", bucket)
|
query = definition["query"].replace("{bucket}", bucket)
|
||||||
|
|
|
@ -80,6 +80,21 @@ def sample_reports(tmp_path):
|
||||||
FROM logs
|
FROM logs
|
||||||
GROUP BY bucket
|
GROUP BY bucket
|
||||||
ORDER BY bucket
|
ORDER BY bucket
|
||||||
|
- name: domain_traffic
|
||||||
|
per_domain: false
|
||||||
|
query: |
|
||||||
|
SELECT host AS bucket,
|
||||||
|
COUNT(*) AS value
|
||||||
|
FROM logs
|
||||||
|
GROUP BY host
|
||||||
|
ORDER BY value DESC
|
||||||
|
- name: skip_report
|
||||||
|
per_domain: false
|
||||||
|
query: |
|
||||||
|
SELECT {bucket} AS bucket, COUNT(*) AS value
|
||||||
|
FROM logs
|
||||||
|
GROUP BY bucket
|
||||||
|
ORDER BY bucket
|
||||||
- name: domain_totals
|
- name: domain_totals
|
||||||
global: true
|
global: true
|
||||||
query: |
|
query: |
|
||||||
|
@ -113,7 +128,7 @@ def test_generate_interval(tmp_path, sample_reports, monkeypatch):
|
||||||
)
|
)
|
||||||
assert error_rate[0]["value"] == pytest.approx(50.0)
|
assert error_rate[0]["value"] == pytest.approx(50.0)
|
||||||
reports = json.loads((tmp_path / "output" / "hourly" / "reports.json").read_text())
|
reports = json.loads((tmp_path / "output" / "hourly" / "reports.json").read_text())
|
||||||
assert {r["name"] for r in reports} == {"hits", "error_rate"}
|
assert {r["name"] for r in reports} == {"hits", "error_rate", "skip_report"}
|
||||||
for r in reports:
|
for r in reports:
|
||||||
snippet = tmp_path / "output" / "hourly" / r["html"]
|
snippet = tmp_path / "output" / "hourly" / r["html"]
|
||||||
assert snippet.exists()
|
assert snippet.exists()
|
||||||
|
@ -136,6 +151,18 @@ def test_generate_interval_domain_filter(tmp_path, sample_reports, monkeypatch):
|
||||||
(tmp_path / "output" / "domains" / "example.com" / "hourly" / "hits.json").read_text()
|
(tmp_path / "output" / "domains" / "example.com" / "hourly" / "hits.json").read_text()
|
||||||
)
|
)
|
||||||
assert hits[0]["value"] == 2
|
assert hits[0]["value"] == 2
|
||||||
|
reports = json.loads(
|
||||||
|
(tmp_path / "output" / "domains" / "example.com" / "hourly" / "reports.json").read_text()
|
||||||
|
)
|
||||||
|
assert {r["name"] for r in reports} == {"hits", "error_rate"}
|
||||||
|
assert not (
|
||||||
|
tmp_path
|
||||||
|
/ "output"
|
||||||
|
/ "domains"
|
||||||
|
/ "example.com"
|
||||||
|
/ "hourly"
|
||||||
|
/ "skip_report.json"
|
||||||
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
def test_generate_root_index(tmp_path, sample_reports, monkeypatch):
|
def test_generate_root_index(tmp_path, sample_reports, monkeypatch):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue