Skip to content

feat: add Stats (database) functions - #89

Merged
mikemadeja merged 3 commits into
mainfrom
develop
Sep 19, 2026
Merged

mikemadeja merged 3 commits into
mainfrom
develop

Conversation

@mikemadeja

Copy link
Copy Markdown
Owner

Summary

Fills in the "Stats (database)" gap from the earlier API coverage audit: 6 new functions in Metrics.

  • Get-PiHoleStatsUpstream — the live /stats/upstreams endpoint (the only live stat that had no function yet)
  • Get-PiHoleStatsDatabaseUpstream, Get-PiHoleStatsDatabaseSummary, Get-PiHoleStatsDatabaseTopDomain, Get-PiHoleStatsDatabaseTopClient, Get-PiHoleStatsDatabaseQueryType — long-term (on-disk) equivalents of the existing live stats functions, each requiring mandatory From/Until Unix-timestamp parameters per the API spec

All follow the module's standard try/catch/finally + session-cleanup pattern, are registered in the export list, and the README command reference has been regenerated to include them.

Also fixed: a module-wide output-leak bug

Remove-PiHoleCurrentAuthSession (called from every public function's finally block) never suppressed its own Invoke-RestMethod result, so that response leaked into the calling function's output stream — turning every function's return value into a 2-element array (real result + a trailing empty string) instead of a single object. Affected the whole module, not just the new functions; confirmed by reproducing it on the pre-existing Get-PiHoleStatsSummary too. Fixed with a one-line $null = suppression.

Test plan

  • Ran all 6 new functions directly against a real Pi-hole v6 server
  • 6 new integration test files (18 tests total) — all pass against the real server
  • Reproduced the output-leak bug on both a new function and the pre-existing Get-PiHoleStatsSummary, confirmed the fix resolves both
  • Invoke-ScriptAnalyzer -Path .\PiHoleShell -Recurse — no findings
  • Full Invoke-Pester -Path .\tests run — 29 passed, only the pre-existing unrelated Set-PiHoleDnsBlocking failure remains

🤖 Generated with Claude Code

mikemadeja and others added 3 commits September 19, 2026 12:30
Remove-PiHoleCurrentAuthSession (called from every public function's
finally block to close its session) called Invoke-RestMethod without
suppressing its result, so whatever that DELETE call returned became
an extra element appended to the calling function's own output. This
turned every function's return value into a 2-element array (the real
result plus an empty string) instead of the single object the API
docs describe.

Property access on the result silently filtered it out (accessing a
missing property across a collection drops elements that lack it), so
existing formatted output looked fine by accident, but RawOutput
consumers and anything checking result shape got the polluted array.
Discovered while writing tests for the new database-stats functions,
where -RawOutput $result.PSObject.Properties.Name exposed the leak.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds the six missing "Stats (database)" API operations identified
earlier: the live /stats/upstreams endpoint (the only live stat that
had no function yet) plus the five long-term-database equivalents of
the existing live stats functions (summary, upstreams, top domains,
top clients, query types). The database-backed endpoints require
mandatory From/Until Unix-timestamp parameters, matching the API spec
(fetched directly from the server's /api/docs/specs/stats.yaml).

New functions:
  - Get-PiHoleStatsUpstream
  - Get-PiHoleStatsDatabaseUpstream
  - Get-PiHoleStatsDatabaseSummary
  - Get-PiHoleStatsDatabaseTopDomain
  - Get-PiHoleStatsDatabaseTopClient
  - Get-PiHoleStatsDatabaseQueryType

All follow the module's standard try/catch/finally + session cleanup
pattern and are registered in the export list. Regenerated the README
command reference to include them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
feat: add Stats (database) functions
@mikemadeja
mikemadeja merged commit d194844 into main Sep 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant