diff --git a/tests/broker-engine/big-metrics.robot b/tests/broker-engine/big-metrics.robot new file mode 100644 index 00000000000..0911713889c --- /dev/null +++ b/tests/broker-engine/big-metrics.robot @@ -0,0 +1,99 @@ +*** Settings *** +Documentation There tests are about big metric values + +Resource ../resources/import.resource + +Suite Setup Ctn Clean Before Suite +Suite Teardown Ctn Clean After Suite +Test Setup Ctn Stop Processes +Test Teardown Ctn Test Clean + + +*** Test Cases *** +EBBM1 + [Documentation] A service status contains metrics that do not fit in a float number. + [Tags] broker engine services unified_sql + Ctn Config Engine ${1} ${1} ${1} + # We want all the services to be passive to avoid parasite checks during our test. + Ctn Set Services Passive ${0} service_.* + Ctn Config Broker rrd + Ctn Config Broker central + Ctn Config Broker module ${1} + Ctn Config BBDO3 1 + Ctn Broker Config Log central core info + Ctn Broker Config Log central tcp error + Ctn Broker Config Log central sql trace + Ctn Broker Config Log central perfdata trace + Ctn Config Broker Sql Output central unified_sql + Ctn Clear Retention + ${start} Get Current Date + ${start_broker} Get Current Date + Ctn Start Broker + Ctn Start engine + Ctn Wait For Engine To Be Ready ${1} + + FOR ${i} IN RANGE ${10} + Ctn Process Service Check Result With Big Metrics + ... host_1 service_1 1 + ... Big Metrics ${10} + END + ${content} Create List + ... Out of range value for column 'current_value' + ${result} Ctn Find In Log With Timeout ${centralLog} ${start} ${content} 30 + Should Be True ${not result} Big metric cannot be stored in the database. + +# Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} +# ${date} Get Current Date result_format=epoch +# Log To Console date=${date} +# FOR ${index} IN RANGE 60 +# ${output} Query +# ... SELECT count(*) FROM resources WHERE name like 'service\_%%' and parent_name='host_1' and status <> 1 +# Log To Console ${output} +# Sleep 1s +# IF "${output}" == "((0,),)" BREAK +# END +# Should Be Equal As Strings ${output} ((0,),) +# +# FOR ${i} IN RANGE ${1000} +# Ctn Process Service Check Result host_1 service_${i+1} 2 warning${i} +# IF ${i} % 200 == 0 +# ${first_service_status_content} Create List unified_sql service_status processing +# ${result} Ctn Find In Log With Timeout +# ... ${centralLog} +# ... ${start_broker} +# ... ${first_service_status_content} +# ... 30 +# Should Be True ${result} No service_status processing found. +# Log To Console Stopping Broker +# Ctn Kindly Stop Broker +# Log To Console Waiting for 5s +# Sleep 5s +# Log To Console Restarting Broker +# ${start_broker} Get Current Date +# Ctn Start Broker +# END +# END +# ${content} Create List +# ... connected to 'MariaDB' Server +# ... it supports column-wise binding in prepared statements +# ${result} Ctn Find In Log With Timeout ${centralLog} ${start} ${content} 30 +# Should Be True ${result} Prepared statements should be supported with this version of MariaDB. +# +# Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} +# ${date} Get Current Date result_format=epoch +# Log To Console date=${date} +# FOR ${index} IN RANGE 120 +# ${output} Query +# ... SELECT count(*) FROM resources WHERE name like 'service\_%%' and parent_name='host_1' and status <> 2 +# Log To Console ${output} +# Sleep 1s +# IF "${output}" == "((0,),)" BREAK +# END +# Should Be Equal As Strings ${output} ((0,),) + + +*** Keywords *** +Ctn Test Clean + Ctn Stop Engine + Ctn Kindly Stop Broker + Ctn Save Logs If Failed diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index b95617aa091..b30ef3a99e6 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -2757,6 +2757,33 @@ def ctn_process_service_check_result_with_metrics(hst: str, svc: str, state: int ctn_process_service_check_result(hst, svc, state, full_output, config) +def ctn_process_service_check_result_with_big_metrics(hst: str, svc: str, state: int, output: str, metrics: int, config='config0', metric_name='metric'): + """ + Send a service check result with metrics but their values are to big to fit into a float. + + Args: + hst (str): Host name of the service. + svc (str): Service description of the service. + state (int): State of the check to set. + output (str): An output message for the check. + metrics (int): The number of metrics that should appear in the result. + config (str, optional): Defaults to 'config0' (useful in case of several Engine running). + metric_name (str): The base name of metrics. They will appear followed by an integer (for example metric0, metric1, metric2, ...). + + Returns: + 0 on success. + """ + now = int(time.time()) + pd = [output + " | "] + for m in range(metrics): + mx = 3.40282e+039 + v = mx + abs(math.sin((now + m) / 1000) * 5) + pd.append(f"{metric_name}{m}={v}") + logger.trace(f"{metric_name}{m}={v}") + full_output = " ".join(pd) + ctn_process_service_check_result(hst, svc, state, full_output, config) + + def ctn_process_service_check_result(hst: str, svc: str, state: int, output: str, config='config0', use_grpc=0, nb_check=1): """ Send a service check result.