Skip to content

feat(infrahubctl): add telemetry commands#937

Merged
fatih-acar merged 1 commit intoinfrahub-developfrom
fac-IFC-2284-telemetry-ctl
Apr 14, 2026
Merged

feat(infrahubctl): add telemetry commands#937
fatih-acar merged 1 commit intoinfrahub-developfrom
fac-IFC-2284-telemetry-ctl

Conversation

@fatih-acar
Copy link
Copy Markdown
Contributor

@fatih-acar fatih-acar commented Apr 10, 2026

Summary by CodeRabbit

  • New Features

    • Added a top-level telemetry CLI command group:
      • list — view telemetry snapshots with ISO 8601 start/end filters and limit; displays summaries and a message when no snapshots are found
      • export — export snapshots to JSON with output path and ISO 8601 date filters; handles full export across pages and confirms when complete
  • Documentation

    • Added telemetry CLI docs covering usage, options, defaults, and examples

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2735e0a2-c814-492f-b947-002cd2994da0

📥 Commits

Reviewing files that changed from the base of the PR and between ac67eb6 and 83edc00.

📒 Files selected for processing (3)
  • docs/docs/infrahubctl/infrahubctl-telemetry.mdx
  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/ctl/telemetry.py
✅ Files skipped from review due to trivial changes (1)
  • docs/docs/infrahubctl/infrahubctl-telemetry.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/ctl/telemetry.py

Walkthrough

Adds a new telemetry CLI command group to infrahubctl and registers it with the main Typer app. Introduces infrahub_sdk/ctl/telemetry.py implementing two async commands: list (queries /api/telemetry/snapshots, displays results in a Rich table, supports --start-date, --end-date, --limit) and export (paginates snapshots from the same endpoint, writes pretty-printed JSON to --output, exits with code 2 if none found). Adds documentation page docs/docs/infrahubctl/infrahubctl-telemetry.mdx describing the command group and subcommands.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is completely empty; no information about why, what changed, testing, or other required template sections was provided. Add a comprehensive PR description using the repository template, including Why, What changed, How to test, and Checklist sections to provide context for reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding telemetry commands to infrahubctl.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fatih-acar fatih-acar force-pushed the fac-IFC-2284-telemetry-ctl branch from eea7d24 to 95ab066 Compare April 10, 2026 09:04
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 10, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 83edc00
Status: ✅  Deploy successful!
Preview URL: https://5a765058.infrahub-sdk-python.pages.dev
Branch Preview URL: https://fac-ifc-2284-telemetry-ctl.infrahub-sdk-python.pages.dev

View logs

@fatih-acar fatih-acar force-pushed the fac-IFC-2284-telemetry-ctl branch from 95ab066 to 866cf4d Compare April 10, 2026 09:20
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 31.57895% with 52 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/ctl/telemetry.py 29.72% 52 Missing ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop     #937      +/-   ##
====================================================
- Coverage             82.63%   81.12%   -1.51%     
====================================================
  Files                   133      134       +1     
  Lines                 13250    11329    -1921     
  Branches               2306     1699     -607     
====================================================
- Hits                  10949     9191    -1758     
+ Misses                 1652     1594      -58     
+ Partials                649      544     -105     
Flag Coverage Δ
integration-tests 41.94% <31.57%> (-2.97%) ⬇️
python-3.10 54.10% <31.57%> (-2.61%) ⬇️
python-3.11 54.10% <31.57%> (-2.61%) ⬇️
python-3.12 54.09% <31.57%> (-2.65%) ⬇️
python-3.13 54.09% <31.57%> (-2.65%) ⬇️
python-3.14 55.71% <31.57%> (-2.87%) ⬇️
python-filler-3.12 22.73% <0.00%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/cli_commands.py 72.11% <100.00%> (+0.16%) ⬆️
infrahub_sdk/ctl/telemetry.py 29.72% <29.72%> (ø)

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fatih-acar fatih-acar force-pushed the fac-IFC-2284-telemetry-ctl branch from 866cf4d to 2b9f378 Compare April 10, 2026 09:47
@github-actions github-actions bot added the type/documentation Improvements or additions to documentation label Apr 10, 2026
@fatih-acar fatih-acar marked this pull request as ready for review April 10, 2026 09:51
@fatih-acar fatih-acar requested a review from a team as a code owner April 10, 2026 09:51
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
infrahub_sdk/ctl/telemetry.py (3)

31-40: Consider extracting shared API call logic into a helper function.

Both list_snapshots and export_snapshots share nearly identical code for building parameters and fetching from the telemetry endpoint. A helper would reduce duplication and centralize error handling.

Optional refactor
async def _fetch_telemetry_snapshots(
    client: InfrahubClient,
    start_date: str | None = None,
    end_date: str | None = None,
    limit: int = 50,
) -> dict:
    """Fetch telemetry snapshots from the API."""
    params: dict[str, str | int] = {"limit": limit}
    if start_date:
        params["start_date"] = start_date
    if end_date:
        params["end_date"] = end_date

    url = f"{client.address}/api/telemetry/snapshots?{urlencode(params)}"
    response = await client._get(url=url, timeout=client.default_timeout)
    response.raise_for_status()
    return response.json()

Also applies to: 78-87

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/ctl/telemetry.py` around lines 31 - 40, Extract the duplicated
request-building and fetching logic from list_snapshots and export_snapshots
into a new helper (suggest name _fetch_telemetry_snapshots) that accepts
(client, start_date=None, end_date=None, limit=50), constructs the params dict,
builds the URL, performs client._get with client.default_timeout, calls
response.raise_for_status() and returns response.json(); then update
list_snapshots and export_snapshots to call this helper and handle any
result-specific processing so error handling and parameter construction are
centralized.

78-78: Hardcoded limit may silently truncate large exports.

The limit: 10000 is hardcoded, but if more snapshots exist, the export will be incomplete without warning. Consider:

  1. Adding a warning if len(snapshots) == 10000 (indicating possible truncation)
  2. Extracting this as a named constant
  3. Comparing against data.get('count') to detect truncation
Suggested improvement
+EXPORT_MAX_LIMIT = 10000
+
 `@app.command`(name="export")
 `@catch_exception`(console=console)
 async def export_snapshots(
     output: str = typer.Option("telemetry-export.json", help="Output file path"),
     start_date: str | None = typer.Option(None, help="Start date filter (ISO 8601)"),
     end_date: str | None = typer.Option(None, help="End date filter (ISO 8601)"),
     _: str = CONFIG_PARAM,
 ) -> None:
     """Export telemetry snapshots to a JSON file."""
     client = initialize_client()

-    params: dict[str, str | int] = {"limit": 10000}
+    params: dict[str, str | int] = {"limit": EXPORT_MAX_LIMIT}
     # ... rest of function ...

     snapshots = data.get("snapshots", [])
+    total_count = data.get("count", len(snapshots))
+    if len(snapshots) < total_count:
+        console.print(f"[yellow]Warning: Exported {len(snapshots)} of {total_count} total snapshots (limit reached)[/yellow]")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/ctl/telemetry.py` at line 78, The hardcoded params: dict with
"limit": 10000 can silently truncate exports; extract that magic number into a
named constant (e.g., MAX_SNAPSHOT_LIMIT), use it when constructing params, and
after fetching snapshots compare len(snapshots) to MAX_SNAPSHOT_LIMIT and also
compare against data.get('count') when available; if len(snapshots) ==
MAX_SNAPSHOT_LIMIT or data.get('count', 0) > len(snapshots) emit a clear warning
via the module logger so callers know the export may be incomplete (update the
code paths around the params variable and the snapshot-fetching function in
telemetry.py).

37-40: The telemetry commands use client._get() to access raw HTTP endpoints (/api/telemetry/snapshots). While _get() is private, there is currently no public client method available for raw HTTP GET requests. The telemetry functionality requires direct HTTP access that isn't exposed through the GraphQL or node-based public API.

Recommendation: If telemetry becomes a core SDK feature, consider either (a) adding public telemetry accessor methods to InfrahubClient or (b) providing a public HTTP utility method for endpoints that require raw HTTP access. For now, document this usage pattern to clarify why the private method is necessary.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/ctl/telemetry.py` around lines 37 - 40, Telemetry code is using
the private client._get() to call raw HTTP endpoints (e.g., in
infrahub_sdk/ctl/telemetry.py building url and calling client._get), which
should be exposed or documented; add a public accessor on InfrahubClient (e.g.,
a method named http_get or raw_get that accepts url, timeout, params and
forwards to the underlying HTTP client) and update telemetry code to call that
public method (or alternatively add explicit public telemetry methods on
InfrahubClient such as get_telemetry_snapshots to encapsulate the URL), and
include a short docstring noting intended use for raw HTTP endpoint access so
future callers avoid using _get directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@infrahub_sdk/ctl/telemetry.py`:
- Around line 31-40: Extract the duplicated request-building and fetching logic
from list_snapshots and export_snapshots into a new helper (suggest name
_fetch_telemetry_snapshots) that accepts (client, start_date=None,
end_date=None, limit=50), constructs the params dict, builds the URL, performs
client._get with client.default_timeout, calls response.raise_for_status() and
returns response.json(); then update list_snapshots and export_snapshots to call
this helper and handle any result-specific processing so error handling and
parameter construction are centralized.
- Line 78: The hardcoded params: dict with "limit": 10000 can silently truncate
exports; extract that magic number into a named constant (e.g.,
MAX_SNAPSHOT_LIMIT), use it when constructing params, and after fetching
snapshots compare len(snapshots) to MAX_SNAPSHOT_LIMIT and also compare against
data.get('count') when available; if len(snapshots) == MAX_SNAPSHOT_LIMIT or
data.get('count', 0) > len(snapshots) emit a clear warning via the module logger
so callers know the export may be incomplete (update the code paths around the
params variable and the snapshot-fetching function in telemetry.py).
- Around line 37-40: Telemetry code is using the private client._get() to call
raw HTTP endpoints (e.g., in infrahub_sdk/ctl/telemetry.py building url and
calling client._get), which should be exposed or documented; add a public
accessor on InfrahubClient (e.g., a method named http_get or raw_get that
accepts url, timeout, params and forwards to the underlying HTTP client) and
update telemetry code to call that public method (or alternatively add explicit
public telemetry methods on InfrahubClient such as get_telemetry_snapshots to
encapsulate the URL), and include a short docstring noting intended use for raw
HTTP endpoint access so future callers avoid using _get directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7acedf3-46b5-462e-8e41-679d9478a32a

📥 Commits

Reviewing files that changed from the base of the PR and between 91d7c77 and 2b9f378.

📒 Files selected for processing (3)
  • docs/docs/infrahubctl/infrahubctl-telemetry.mdx
  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/ctl/telemetry.py

@fatih-acar fatih-acar force-pushed the fac-IFC-2284-telemetry-ctl branch from 2b9f378 to ac67eb6 Compare April 13, 2026 17:38
Signed-off-by: Fatih Acar <fatih@opsmill.com>
@fatih-acar fatih-acar changed the base branch from develop to infrahub-develop April 13, 2026 19:40
@fatih-acar fatih-acar force-pushed the fac-IFC-2284-telemetry-ctl branch from ac67eb6 to 83edc00 Compare April 13, 2026 19:40
@fatih-acar fatih-acar merged commit f9249a7 into infrahub-develop Apr 14, 2026
36 of 37 checks passed
@fatih-acar fatih-acar deleted the fac-IFC-2284-telemetry-ctl branch April 14, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants