Skip to content

Conversation

xiangce
Copy link
Contributor

@xiangce xiangce commented Sep 29, 2025

  • New spec to collect command "/usr/share/ansible/telemetry/telemetry.py"
  • New AnsibleTelemetry to parse the command
  • Jira: RHINENG-20964

All Pull Requests:

Check all that apply:

  • Have you followed the guidelines in our Contributing document, including the instructions about commit messages?
  • No Sensitive Data in this change?
  • Is this PR to correct an issue?
  • Is this PR an enhancement?
  • Need backport to 3.0_egg? Yes, refer to RPM/Egg Delivery to open a new PR.
  • Is this a backport from master? Yes, this is a backport of #PR-ID

Complete Description of Additions/Changes:

Add your description here

Summary by Sourcery

Introduce a new AnsibleTelemetry spec and parser to collect and process Ansible telemetry data, along with associated tests and documentation.

New Features:

  • Add ansible_telemetry spec to collect output of "/usr/share/ansible/telemetry/telemetry.py"
  • Implement AnsibleTelemetry parser for JSON-formatted telemetry output
  • Include unit tests for the AnsibleTelemetry parser
  • Add documentation entry for the new AnsibleTelemetry parser

Enhancements:

  • Reformat certain RegistryPoint definitions in specs for consistency

- New spec to collect command "/usr/share/ansible/telemetry/telemetry.py"
- New AnsibleTelemetry to parse the command
- Jira: RHINENG-20964

Signed-off-by: Xiangce Liu <xiangceliu@redhat.com>
@xiangce xiangce added data collection Changes that would impact the data collection data processing Changes that would impact the data processing/analyzing RPM RPM package related only. labels Sep 29, 2025
Copy link
Contributor

sourcery-ai bot commented Sep 29, 2025

Reviewer's Guide

This PR implements full support for collecting and parsing Ansible telemetry data by registering a new spec, wiring it into the default specs, providing a JSON‐based parser, accompanying unit tests, and a documentation placeholder, along with small formatting refinements in existing spec definitions.

ER diagram for parsed Ansible telemetry data structure

erDiagram
    COLLECTIONS {
        string ansible_builtin
        string version
        JSON resources
    }
    RESOURCES {
        JSON action
        JSON connection
    }
    ACTION {
        int add_host
        int uri
        int set_fact
        int debug
        int find
        int file
        int template
        int command
    }
    CONNECTION {
        int local
        int ssh
    }
    ANSIBLE_CORE {
        string version
    }
    HOSTS {
        int count
    }
    COLLECTIONS ||--|{ RESOURCES : contains
    RESOURCES ||--|{ ACTION : contains
    RESOURCES ||--|{ CONNECTION : contains
    COLLECTIONS ||--|{ ANSIBLE_CORE : has
    COLLECTIONS ||--|{ HOSTS : has
Loading

Class diagram for the new AnsibleTelemetry parser

classDiagram
    class AnsibleTelemetry {
        <<CommandParser>>
        <<JSONParser>>
        +__init__()
        +parse()
        +data: dict
    }
    AnsibleTelemetry --|> CommandParser
    AnsibleTelemetry --|> JSONParser
    CommandParser <|-- JSONParser
Loading

File-Level Changes

Change Details Files
Add AnsibleTelemetry spec
  • Added a new RegistryPoint entry for ansible_telemetry in Specs
  • Mapped the ansible_telemetry spec to simple_command in DefaultSpecs
insights/specs/__init__.py
insights/specs/default.py
Standardize multi-line usage in spec definitions
  • Flattened multi-line RegistryPoint calls into single-line for consistency
  • Refactored filefrag simple_command call into a formatted multi-line invocation
insights/specs/__init__.py
insights/specs/default.py
Introduce AnsibleTelemetry parser
  • Created AnsibleTelemetry parser class combining CommandParser and JSONParser
  • Annotated the parser with @parser tied to Specs.ansible_telemetry
insights/parsers/ansible.py
Implement tests for AnsibleTelemetry parser
  • Added tests covering valid JSON parsing and error handling
  • Included doctest verification for parser examples
insights/tests/parsers/test_ansible.py
Add parser documentation stub
  • Created an RST placeholder for the AnsibleTelemetry parser in shared_parsers_catalog
docs/shared_parsers_catalog/ansible.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The new docs/shared_parsers_catalog/ansible.rst is empty; please populate it with usage and examples for the AnsibleTelemetry parser.
  • Consider adding convenience properties or helper methods to AnsibleTelemetry to simplify common lookups (e.g. retrieving collection versions or host counts) rather than relying solely on raw dict access.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new docs/shared_parsers_catalog/ansible.rst is empty; please populate it with usage and examples for the AnsibleTelemetry parser.
- Consider adding convenience properties or helper methods to AnsibleTelemetry to simplify common lookups (e.g. retrieving collection versions or host counts) rather than relying solely on raw dict access.

## Individual Comments

### Comment 1
<location> `insights/tests/parsers/test_ansible.py:45-50` </location>
<code_context>
+""".strip()
+
+
+def test_ansible_telemetry():
+    ret = ansible.AnsibleTelemetry(context_wrap(AT_INPUT))
+    assert ret['hosts']['count'] == 44
+
+    with pytest.raises(ContentException):
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for additional edge cases and malformed JSON input.

Tests currently focus on valid input and a specific error. Please add cases for empty input, malformed JSON, and unexpected structures to verify robust error handling.

```suggestion
def test_ansible_telemetry():
    ret = ansible.AnsibleTelemetry(context_wrap(AT_INPUT))
    assert ret['hosts']['count'] == 44

    with pytest.raises(ContentException):
        ansible.AnsibleTelemetry(context_wrap(AT_INPUT_NG))

def test_ansible_telemetry_empty_input():
    with pytest.raises(ContentException):
        ansible.AnsibleTelemetry(context_wrap(""))

def test_ansible_telemetry_malformed_json():
    malformed_json = "{'hosts': 44"  # missing closing brace, single quotes
    with pytest.raises(ContentException):
        ansible.AnsibleTelemetry(context_wrap(malformed_json))

def test_ansible_telemetry_unexpected_structure():
    unexpected_json = '{"unexpected_key": {"foo": "bar"}}'
    with pytest.raises(ContentException):
        ansible.AnsibleTelemetry(context_wrap(unexpected_json))
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.03%. Comparing base (3ce7845) to head (8d39575).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4589      +/-   ##
==========================================
- Coverage   89.03%   89.03%   -0.01%     
==========================================
  Files         722      723       +1     
  Lines       33310    33317       +7     
  Branches     4940     4940              
==========================================
+ Hits        29659    29664       +5     
- Misses       2922     2923       +1     
- Partials      729      730       +1     
Flag Coverage Δ
unittests 89.02% <100.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data collection Changes that would impact the data collection data processing Changes that would impact the data processing/analyzing RPM RPM package related only.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants