Skip to content

Conversation

@bzwei
Copy link
Collaborator

@bzwei bzwei commented Mar 20, 2025

Merge feature branch analytics back to main

AAP-40319

bzwei and others added 19 commits March 19, 2025 14:06
Signed-off-by: Alex <aizquier@redhat.com>
Co-authored-by: Alex <aizquier@redhat.com>
Co-authored-by: Joe Shimkus <35382397+jshimkus-rh@users.noreply.github.com>
Co-authored-by: Elijah DeLee <kdelee@redhat.com>
Co-authored-by: Hui Song <hsong@redhat.com>
…ytics collection (#1207)

https://issues.redhat.com/browse/AAP-39884

This PR covers:
1. Add more Pytest cases to improve code coverage for analytics
collection
2. Fix errors when the audit_rule table is empty
```
Traceback (most recent call last):
  File "/home/runner/.cache/pypoetry/virtualenvs/aap-eda-mUpJWeoH-py3.11/lib/python3.11/site-packages/insights_analytics_collector/collection.py", line 59, in gather
    result = self.fnc_collecting(
             ^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/eda-server/eda-server/src/aap_eda/analytics/analytics_collectors.py", line 289, in audit_rules_table
    audit_rules = _get_audit_rule_qs(since, until).values(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pypoetry/virtualenvs/aap-eda-mUpJWeoH-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 1313, in values
    clone = self._values(*fields, **expressions)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pypoetry/virtualenvs/aap-eda-mUpJWeoH-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 1308, in _values
    clone.query.set_values(fields)
  File "/home/runner/.cache/pypoetry/virtualenvs/aap-eda-mUpJWeoH-py3.11/lib/python3.11/site-packages/django/db/models/sql/query.py", line 2463, in set_values
    self.add_fields(field_names, True)
  File "/home/runner/.cache/pypoetry/virtualenvs/aap-eda-mUpJWeoH-py3.11/lib/python3.11/site-packages/django/db/models/sql/query.py", line 2195, in add_fields
    raise FieldError(
django.core.exceptions.FieldError: Cannot resolve keyword 'created_at' into field. Choices are: activation, activation_id, activation_pod_id, activationinstancejobinstance, auditrule, ended_at, git_hash, id, log_read_at, name, organization, organization_id, parent_type, rulebookprocesslog, rulebookprocessqueue, started_at, status, status_message, updated_at
```
3. Fix the previous two failed Pytest cases:
```
FAILED tests/integration/analytics/test_gather_analytics.py::test_gather_analytics_invalid_settings[https://url-True-Analytics collection is done] - requests.exceptions.ConnectionError: HTTPSConnectionPool(host='url', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f9acaca9950>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
FAILED tests/integration/analytics/test_gather_analytics.py::test_gather_analytics_command[--ship-INFO-Analytics collection is done] - requests.exceptions.ConnectionError: HTTPSConnectionPool(host='url', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f9acb3f0a90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
====== 2 failed, 922 passed, 24 skipped, 15 warnings in 391.17s (0:06:31) ======
```
https://issues.redhat.com/browse/AAP-39892

This PR covers:
1. remove `payload` from audit event collection table,
2. reduce SQL parameter injection and memory overflow risks
AAP-39884 Test and improve code coverage for analytics collection
feature
Renames feature flag to be inline with naming convention
FEATURE_(FEATURE_NAME)_ENABLED
<!-- Mandatory: Provide a clear, concise description of the changes and
their purpose -->
Sets the default to False to align on feature requirements

Closes #XXX (if applicable)
Jira: [AAP-XXXXX](https://jira.aap.com/browse/AAP-XXXXX) (if applicable)

<!-- Mandatory: Check one or more boxes that apply -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update
- [ ] Test update
- [ ] Refactoring (no functional changes)
- [ ] Development environment change
- [ ] Configuration change
- [ ] CI change

<!-- These items help ensure quality - they complement our automated CI
checks -->
- [ ] I have performed a self-review of my code
- [ ] I have added relevant comments to complex code sections
- [ ] I have updated documentation where needed
- [ ] I have considered the security impact of these changes
- [ ] I have considered performance implications
- [ ] I have thought about error handling and edge cases
- [ ] I have tested the changes in my local environment
- [ ] I have run the linters and test suite locally
- [ ] I have tested the changes on integration environment

<!-- Optional for test-only changes. Mandatory for all other changes -->
<!-- Must be detailed enough for reviewers to reproduce -->
<!-- List any specific setup required -->

1.
2.
3.

<!-- Describe what should happen after following the steps -->

<!-- Optional but helpful information -->

<!-- Check if changes require work in other areas -->
<!-- Remove section if no external actions needed -->
- [ ] Requires documentation updates
  <!-- API docs, feature docs, deployment guides -->
- [ ] Requires downstream repository changes
  <!-- Specify repos: django-ansible-base, eda-server, etc. -->
- [ ] Requires infrastructure/deployment changes
  <!-- CI/CD, installer updates, new services -->
- [ ] Requires coordination with other teams
  <!-- UI team, platform services, infrastructure -->
- [ ] Blocked by PR/MR: #XXX |
<https://github.com/example/repo/pull/XXX>
  <!-- Reference blocking PRs/MRs with brief context -->

<!-- Add if relevant to demonstrate the changes -->
This PR contains:
1. change `activations_stats.csv` into `activations_stats_table.csv`
2. remove `created_by_id` and `modified_by_id` from `teams_table.csv`

https://issues.redhat.com/browse/AAP-41167
@bzwei bzwei requested a review from a team as a code owner March 20, 2025 19:54
@bzwei bzwei added the run-e2e label Mar 20, 2025
@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2025

Codecov Report

Attention: Patch coverage is 99.12506% with 17 lines in your changes missing coverage. Please review.

Project coverage is 94.55%. Comparing base (c15d2b9) to head (6366d47).

Files with missing lines Patch % Lines
tests/integration/tasks/test_analytics.py 89.09% 6 Missing ⚠️
src/aap_eda/analytics/analytics_collectors.py 98.38% 4 Missing ⚠️
src/aap_eda/conf/registry.py 96.82% 4 Missing ⚠️
src/aap_eda/api/metadata.py 92.59% 2 Missing ⚠️
src/aap_eda/tasks/analytics.py 96.66% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #1240      +/-   ##
==========================================
+ Coverage   93.90%   94.55%   +0.64%     
==========================================
  Files         290      309      +19     
  Lines       16123    18047    +1924     
==========================================
+ Hits        15141    17065    +1924     
  Misses        982      982              
Flag Coverage Δ
unit-int-tests-3.11 94.50% <99.12%> (+0.65%) ⬆️
unit-int-tests-3.12 94.55% <99.12%> (+0.64%) ⬆️

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

Files with missing lines Coverage Δ
src/aap_eda/analytics/collector.py 100.00% <100.00%> (ø)
src/aap_eda/analytics/package.py 100.00% <100.00%> (ø)
src/aap_eda/analytics/utils.py 100.00% <100.00%> (ø)
src/aap_eda/api/serializers/eda_credential.py 99.03% <100.00%> (+0.01%) ⬆️
src/aap_eda/conf/__init__.py 100.00% <100.00%> (ø)
src/aap_eda/conf/settings.py 100.00% <100.00%> (ø)
src/aap_eda/core/enums.py 100.00% <100.00%> (ø)
...da/core/management/commands/create_initial_data.py 98.98% <100.00%> (+0.03%) ⬆️
...p_eda/core/management/commands/gather_analytics.py 100.00% <100.00%> (ø)
src/aap_eda/core/migrations/0062_setting.py 100.00% <100.00%> (ø)
... and 20 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zkayyali812
zkayyali812 previously approved these changes Mar 21, 2025
hsong-rh
hsong-rh previously approved these changes Mar 21, 2025
@bzwei bzwei force-pushed the feature/analytics branch from 99b9bb5 to 6366d47 Compare March 21, 2025 18:35
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4 Security Hotspots

See analysis details on SonarQube Cloud

@bzwei bzwei merged commit 3bc5173 into main Mar 21, 2025
7 of 8 checks passed
@Alex-Izquierdo Alex-Izquierdo deleted the feature/analytics branch March 26, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants