Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monitoring module for e2e tests #4959

Merged
merged 9 commits into from
Feb 23, 2024
Merged

Conversation

Rebits
Copy link
Member

@Rebits Rebits commented Feb 13, 2024

Description

This PR include a fix for the monitoring module in E2E tests

Testing performed

Testing
In [36]: monitoring_data =         {
In [36]: monitoring_data =         {
    ...:            "manager1":[
    ...:               {
    ...:                  "regex": r'(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}) .*? INFO: Testi
    ...: ng2',
    ...:                  "file":"/tmp/testing",
    ...:                  "timeout":10,
    ...:                  "n_iterations":1,
    ...:                  "greater_than_timestamp":"2024-02-20T17:12:22.33"
    ...:               }
    ...:            ]
    ...:         }

In [37]: monitoring_events_multihost(hm, monitoring_data)
Out[37]: 
{'manager1': {'not_found': [{'regex': '(\\d{4}\\/\\d{2}\\/\\d{2} \\d{2}:\\d{2}:\\d{2}) .*? INFO: Testing2',
    'file': '/tmp/testing',
    'timeout': 10,
    'n_iterations': 1,
    'greater_than_timestamp': '2024-02-20T17:12:22.33'}],
  'found': []}}

In [38]: monitoring_data =         {
    ...:            "manager1":[
    ...:               {
    ...:                  "regex": r'(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}) .*? INFO: Testi
    ...: ng',
    ...:                  "file":"/tmp/testing",
    ...:                  "timeout":10,
    ...:                  "n_iterations":1,
    ...:                  "greater_than_timestamp":"2024-02-20T17:12:22.33"
    ...:               }
    ...:            ]
    ...:         }

In [39]: monitoring_events_multihost(hm, monitoring_data)
Out[39]: {'manager1': {'not_found': [], 'found': ['2024/02/21 10:33:37']}}

In [40]: monitoring_data =         {
    ...:            "manager1":[
    ...:               {
    ...:                  "regex": r'Testing',
    ...:                  "file":"/tmp/testing",
    ...:                  "timeout":10,
    ...:                  "n_iterations":1,
    ...:                  "greater_than_timestamp":"2024-02-20T17:12:22.33"
    ...:               }
    ...:            ]
    ...:         }

In [41]: 

In [41]: monitoring_events_multihost(hm, monitoring_data)
---------------------------------------------------------------------------
ValueError           

In [42]: monitoring_data =         {
    ...:            "manager1":[
    ...:               {
    ...:                  "regex": r'Testing',
    ...:                  "file":"/tmp/testing",
    ...:                  "timeout":10,
    ...:                  "n_iterations":1,
    ...: 
    ...:               }
    ...:            ]
    ...:         }

In [43]: monitoring_events_multihost(hm, monitoring_data)
Out[43]: {'manager1': {'not_found': [], 'found': ['Testing', 'Testing', 'Testing']}}


In [44]: monitoring_data =         {
    ...:            "manager1":[
    ...:               {
    ...:                  "regex": r'(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}) .*? INFO: Testi
    ...: ng',
    ...:                  "file":"/tmp/testing",
    ...:                  "timeout":10,
    ...:                  "n_iterations":1,
    ...:                  "greater_than_timestamp":"2024-03-20T17:12:22.33"
    ...:               }
    ...:            ]
    ...:         }

In [45]: monitoring_events_multihost(hm, monitoring_data)
Out[45]: 
{'manager1': {'not_found': [{'regex': '(\\d{4}\\/\\d{2}\\/\\d{2} \\d{2}:\\d{2}:\\d{2}) .*? INFO: Testing',
    'file': '/tmp/testing',
    'timeout': 10,
    'n_iterations': 1,
    'greater_than_timestamp': '2024-03-20T17:12:22.33'}],
  'found': []}}


             

@Rebits Rebits self-assigned this Feb 13, 2024
@Rebits Rebits linked an issue Feb 13, 2024 that may be closed by this pull request
@Rebits Rebits force-pushed the fix/4937-monitoring-e2e branch from 2416c2a to e53a340 Compare February 14, 2024 18:35
@Rebits Rebits marked this pull request as ready for review February 21, 2024 17:50
Copy link
Member

@juliamagan juliamagan left a comment

Choose a reason for hiding this comment

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

GJ!

deps/wazuh_testing/wazuh_testing/end_to_end/monitoring.py Outdated Show resolved Hide resolved
deps/wazuh_testing/wazuh_testing/end_to_end/monitoring.py Outdated Show resolved Hide resolved
Comment on lines +100 to +106
try:
timestamp_datetime = datetime.strptime(timestamp_str, timestamp_format)
greater_than_timestamp_formatted = datetime.strptime(greater_than_timestamp,
timestamp_format_parameter)
except ValueError:
raise ValueError(f"Timestamp format not supported: {timestamp_str}."
'Do the regex includes the timestamp?')
Copy link
Member

Choose a reason for hiding this comment

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

If you already have the greater_than_timestamp field, is it necessary to add the timestamp regex to the regex field? Isn't it a bit repetitive?

Copy link
Member Author

Choose a reason for hiding this comment

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

To effectively compare with the time specified in the greater_than_timestamp parameters, we need to gather the timestamp from the event. Therefore, the specified regex should be designed to match at least one group, specifically tailored for capturing the timestamp.

Copy link
Member

Choose a reason for hiding this comment

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

We will revisit this in the future

Rebits and others added 2 commits February 22, 2024 17:06
Co-authored-by: Julia Magan <juliamgnr@gmail.com>
Co-authored-by: Julia Magan <juliamgnr@gmail.com>
juliamagan
juliamagan previously approved these changes Feb 22, 2024
Copy link
Member

@juliamagan juliamagan left a comment

Choose a reason for hiding this comment

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

LGTM

@davidjiglesias davidjiglesias merged commit a0d6afe into 4.8.0 Feb 23, 2024
2 of 4 checks passed
@davidjiglesias davidjiglesias deleted the fix/4937-monitoring-e2e branch February 23, 2024 07:45
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.

Monitoring remote E2E logs infinite loops when no timestamp is used
3 participants