Skip to content

Commit

Permalink
enh(tests): big metrics do not fail anymore when inserted in database
Browse files Browse the repository at this point in the history
  • Loading branch information
bouda1 committed Jun 11, 2024
1 parent 449fdaa commit bdef391
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
99 changes: 99 additions & 0 deletions tests/broker-engine/big-metrics.robot
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/resources/Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

3 comments on commit bdef391

@github-actions
Copy link

Choose a reason for hiding this comment

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

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
0 1 0 1 0 40.222148s

Failed Tests

Name Message ⏱️ Duration Suite
EBBM1 Variable '${not result}' not found. Did you mean: ${result} 40.222 s Big-Metrics

@github-actions
Copy link

Choose a reason for hiding this comment

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

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
0 2 0 2 0 1m20.432533s

Failed Tests

Name Message ⏱️ Duration Suite
EBBM1 Variable '${not result}' not found. Did you mean: ${result} 40.222 s Big-Metrics
EBBM1 Variable '${not result}' not found. Did you mean: ${result} 40.210 s Big-Metrics

@github-actions
Copy link

Choose a reason for hiding this comment

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

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
0 1 0 1 0 40.296319s

Failed Tests

Name Message ⏱️ Duration Suite
EBBM1 Variable '${not result}' not found. Did you mean: ${result} 40.296 s Big-Metrics

Please sign in to comment.