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

issue:#4043165: Create a new telemetry_collector class #235

Merged
merged 30 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c729b59
replace dynamic telmetry with the secondary telemetry
egershonNvidia Aug 14, 2024
6eb60da
fixed vitaly comment
egershonNvidia Aug 14, 2024
0e3eebf
fixed CI issue and
egershonNvidia Aug 14, 2024
58c2b9d
fix CI and adding constants
egershonNvidia Aug 14, 2024
651c51a
move get_telemetry to it's own class
egershonNvidia Aug 14, 2024
5e8ce58
added comments and fixed dror comments
egershonNvidia Aug 14, 2024
e388ac5
added fix for the connection between runner and machine
egershonNvidia Aug 14, 2024
65982e2
rename file telemetry collector
egershonNvidia Aug 14, 2024
dad6b6b
removed Telemetry collector
egershonNvidia Aug 15, 2024
f28263f
put telemetry collection in it own class
egershonNvidia Aug 19, 2024
d15a14e
added the class
egershonNvidia Aug 19, 2024
bd0147b
Merge branch 'main' into pdr_telemetry
egershonNvidia Sep 4, 2024
b4ad16d
add save location
egershonNvidia Sep 4, 2024
0729ecb
added data store and telemetry collector classes
egershonNvidia Sep 10, 2024
46120dc
Merge branch 'main' into pdr_telemetry
egershonNvidia Sep 10, 2024
8eb2577
replace the ufm client get telemetry
egershonNvidia Sep 10, 2024
0e7c507
fixed crashes
egershonNvidia Sep 10, 2024
63f38c3
remove constant changes
egershonNvidia Sep 10, 2024
df3bbb3
added a test getting the file
egershonNvidia Sep 16, 2024
99dbffd
Merge branch 'main' into pdr_telemetry
egershonNvidia Sep 16, 2024
4769aca
added a test to insure that we have maximum logs.
egershonNvidia Sep 17, 2024
94b9705
fixed creation of log
egershonNvidia Sep 17, 2024
88f823b
another edit for the test
egershonNvidia Sep 17, 2024
b8011ef
copying only abs
egershonNvidia Sep 17, 2024
3e94cce
fixed test
egershonNvidia Sep 17, 2024
cef733a
the length of file is 0
egershonNvidia Sep 17, 2024
4e8e662
the len of files it 0
egershonNvidia Sep 17, 2024
416c00d
revert the sort order to take the last item
egershonNvidia Sep 17, 2024
c204de5
fixed the maximum log test
egershonNvidia Sep 17, 2024
4709eba
fixed grammer mistake
egershonNvidia Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions plugins/pdr_deterministic_plugin/tests/simulation_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
from collections import OrderedDict
import requests
from utils.utils import Utils
import pandas as pd
from pathlib import Path
from datetime import datetime
from datetime import datetime,timedelta

lock = Lock()

Expand All @@ -34,6 +35,8 @@
RCV_REMOTE_PHY_ERROR_COUNTER = "PortRcvRemotePhysicalErrors"
TEMP_COUNTER = "Module_Temperature"
FEC_MODE = "fec_mode_active"
TELEMETRY_DATASTORE_LOCATION = "/opt/ufm/ufm_plugin_pdr_deterministic/datastore"
MAX_LOG_FILES = 10
ENDPOINT_CONFIG = {}

EXCLUDE_PORT_LONG_TIME = "ExcludePortForLongTime"
Expand Down Expand Up @@ -72,6 +75,8 @@ def do_GET(self): # pylint: disable=invalid-name
data = endpoint['data']
self.wfile.write(data.encode())

OUTPUT_FILE_FORMAT = "%Y_%m_%d_%H_%M_%S.csv"

DIFFERENT_DEFAULT_VALUES = {
# because the plugin reads the meta data to know the first temperature and we cannot stream the metadata.
TEMP_COUNTER:"5",
Expand Down Expand Up @@ -196,6 +201,7 @@ def start_server(port:str,changes_intervals:int, run_forever:bool):
counters_names = list(counters.keys())
header = ['timestamp', 'source_id,tag,Node_GUID,port_guid,Port_Number'] + counters_names
endpoint['data'] = ""
setup_log_test = False
while True:
# lock.acquire()
data = []
Expand All @@ -219,8 +225,29 @@ def start_server(port:str,changes_intervals:int, run_forever:bool):
if not run_forever and ENDPOINT_CONFIG["ITERATION_TIME"] > MAX_ITERATIONS:
# after all the tests are done, we need to stop the simulator and check the logs
return
if not setup_log_test:
setup_log_test = create_telemetries_logs()
time.sleep(changes_intervals)

def create_telemetries_logs():
"""
create up to double of the amount of logs that can be in the folder. this is a setup for test.
"""
successful = True
for option_location in ['abs','delta']:
input_path_dir = Path(join(TELEMETRY_DATASTORE_LOCATION,option_location))
files = list(input_path_dir.glob("*.csv"))
if len(files)==0:
print("didnt create files because there are no files in the folder")
egershonNvidia marked this conversation as resolved.
Show resolved Hide resolved
successful = False
continue
df = pd.read_csv(files[0])
for day in range(1,MAX_LOG_FILES*2):
# we put days back to make sure the logs that the server creates are recent, we have a test for recent logs.
file_name_year_ago = (datetime.now() - timedelta(days=day)).strftime(OUTPUT_FILE_FORMAT)
df.to_csv(file_name_year_ago)
return successful

def excluded_ports_simulation(endpoint):
"""
Perform operations on exclusion port for current iteration
Expand All @@ -231,7 +258,6 @@ def excluded_ports_simulation(endpoint):
for port_index in range(len(rows)):
port_name = endpoint["Ports_names"][port_index]
iteration = ENDPOINT_CONFIG["ITERATION_TIME"]

# Process remove operation
if find_value(port_index, INCLUDE_PORT, iteration, None) is not None:
# Remove from exclusion list
Expand Down Expand Up @@ -344,22 +370,25 @@ def check_logs(config):
return 1

saved_files_tests = True
locations_telemetry_csv = "/opt/ufm/ufm_plugin_pdr_deterministic/datastore"
OUTPUT_FILE_FORMAT = "%Y_%m_%d_%H_%M_%S.csv"


for option_location in ['abs','delta']:
input_path_dir = Path(join(locations_telemetry_csv,option_location))
input_path_dir = Path(join(TELEMETRY_DATASTORE_LOCATION,option_location))
files = list(input_path_dir.glob("*.csv"))

if len(files) == 0: # testing we have files there
print(f"There is no files in the datastore location:{join(locations_telemetry_csv,option_location)}")
print(f"There is no files in the datastore location:{join(TELEMETRY_DATASTORE_LOCATION,option_location)}")
egershonNvidia marked this conversation as resolved.
Show resolved Hide resolved
saved_files_tests = False
continue
print_test_result("there are only 10 items in the set, The test copy in each iterations more logs.",
egershonNvidia marked this conversation as resolved.
Show resolved Hide resolved
len(files), MAX_LOG_FILES)
if len(files) != MAX_LOG_FILES:
saved_files_tests = False
files.sort(key=lambda p: p.name)
latest_file = files[0].name
saved_time = datetime.strptime(latest_file,OUTPUT_FILE_FORMAT)
different_time = datetime.now() - saved_time
print_test_result(f"the latest file saved at {join(locations_telemetry_csv,option_location)} before test running, more than 5 minutes {different_time.total_seconds() > 300}",
print_test_result(f"the latest file saved at {join(TELEMETRY_DATASTORE_LOCATION,option_location)}\
before test running, more than 5 minutes {different_time.total_seconds() > 300}",
different_time.total_seconds() > 300, False)
if different_time.total_seconds() > 300:
egershonNvidia marked this conversation as resolved.
Show resolved Hide resolved
saved_files_tests = False
Expand Down Expand Up @@ -441,7 +470,7 @@ def main():

if not validate_simulation_data():
return 1

port = args.endpoint_port
url = f'http://0.0.0.0:{port}{args.url_suffix}'
print(f'---Starting endpoint {url}')
Expand Down
Loading