From 56b8953c5edf38682bf18f2497fed3463448a4bd Mon Sep 17 00:00:00 2001 From: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:49:08 +0100 Subject: [PATCH] MON-20431 Add metrics name tests size (#839) (#998) REFS:MON-32950 * Add metrics name tests size * Update library installation * fix tests --------- Co-authored-by: NITCHEU B --- resources/centreon_storage.sql | 2 +- .../services-and-bulk-stmt.robot | 56 +++++++++++++++++++ tests/broker-engine/services-increased.robot | 2 +- tests/resources/Engine.py | 27 ++++++--- tests/update-doc.py | 2 +- 5 files changed, 77 insertions(+), 12 deletions(-) diff --git a/resources/centreon_storage.sql b/resources/centreon_storage.sql index 1d31e093377..72a2576675b 100644 --- a/resources/centreon_storage.sql +++ b/resources/centreon_storage.sql @@ -765,7 +765,7 @@ DROP TABLE IF EXISTS `metrics`; CREATE TABLE `metrics` ( `metric_id` int(11) NOT NULL AUTO_INCREMENT, `index_id` bigint unsigned DEFAULT NULL, - `metric_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `metric_name` varchar(1021) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `data_source_type` enum('0','1','2','3') DEFAULT NULL, `unit_name` varchar(32) DEFAULT NULL, `current_value` float DEFAULT NULL, diff --git a/tests/broker-engine/services-and-bulk-stmt.robot b/tests/broker-engine/services-and-bulk-stmt.robot index 266348822fa..39bac82afc4 100644 --- a/tests/broker-engine/services-and-bulk-stmt.robot +++ b/tests/broker-engine/services-and-bulk-stmt.robot @@ -392,6 +392,62 @@ metric_mapping ${grep_res} Grep File /tmp/test.log name: metric1 corresponds to metric id Should Not Be Empty ${grep_res} metric name "metric1" not found +Services_and_bulks_${id} + [Documentation] One service is configured with one metric with a name of 150 to 1021 characters. + [Tags] broker engine services unified_sql benchmark + Clear Metrics + Config Engine ${1} ${1} ${1} + # We want all the services to be passive to avoid parasite checks during our test. + ${random_string} Generate Random String ${metric_num_char} [LOWER] + Set Services passive ${0} service_.* + Config Broker central + Config Broker rrd + Config Broker module ${1} + Broker Config Add Item module0 bbdo_version 3.0.1 + Broker Config Add Item central bbdo_version 3.0.1 + Broker Config Log central core error + Broker Config Log central tcp error + Broker Config Log central sql debug + Config Broker Sql Output central unified_sql + Broker Config Source Log central 1 + + Config Broker Remove Rrd Output central + Clear Retention + Clear Db metrics + + ${start} Get Current Date + Start Broker + Start Engine + Broker Set Sql Manager Stats 51001 5 5 + + # Let's wait for the external command check start + ${content} Create List check_for_external_commands() + ${result} Find In Log with Timeout ${engineLog0} ${start} ${content} 60 + Should Be True ${result} A message telling check_for_external_commands() should be available. + + ${start_1} Get Round Current Date + + Process Service Check result with metrics + ... host_1 + ... service_${1} + ... ${1} + ... warning${0} + ... 1 + ... config0 + ... ${random_string} + + ${content} Create List perfdata on connection + ${log} Catenate SEPARATOR= ${BROKER_LOG} /central-broker-master.log + ${result} Find In Log With Timeout ${log} ${start_1} ${content} 60 + Should Be True ${result} A message fail to handle a metric with ${metric_num_char} characters. + + ${metrics} Get Metrics For Service 1 ${random_string}0 + Should Not Be Equal ${metrics} ${None} no metric found for service + + Examples: id metric_num_char -- + ... 1 1020 + ... 2 150 + *** Keywords *** Test Clean diff --git a/tests/broker-engine/services-increased.robot b/tests/broker-engine/services-increased.robot index 1c74f874318..5d7beb6abac 100644 --- a/tests/broker-engine/services-increased.robot +++ b/tests/broker-engine/services-increased.robot @@ -140,7 +140,7 @@ Service_increased_huge_check_interval ${metrics} Get Metrics For Service ${new_service_id} - Should Not Be Equal ${metrics} None no metric found for service ${new_service_id} + Should Not Be Equal ${metrics} ${None} no metric found for service ${new_service_id} FOR ${m} IN @{metrics} ${result} Wait Until File Modified ${VarRoot}/lib/centreon/metrics/${m}.rrd ${start} diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index 7f1bce7ddfa..3eaed2f61ad 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -1881,23 +1881,32 @@ def wrapper(*args): return wrapper -def process_service_check_result_with_metrics(hst: str, svc: str, state: int, output: str, metrics: int, config='config0'): +def process_service_check_result_with_metrics(hst: str, svc: str, state: int, output: str, metrics: int, config='config0', metric_name='metric'): now = int(time.time()) pd = [output + " | "] for m in range(metrics): v = math.sin((now + m) / 1000) * 5 - pd.append(f"metric{m}={v}") + pd.append(f"{metric_name}{m}={v}") + logger.trace(f"{metric_name}{m}={v}") full_output = " ".join(pd) process_service_check_result(hst, svc, state, full_output, config) +def process_service_check_result(hst: str, svc: str, state: int, output: str, config='config0', use_grpc=0, nb_check=1): + if use_grpc > 0: + port = 50001 + int(config[6:]) + with grpc.insecure_channel(f"127.0.0.1:{port}") as channel: + stub = engine_pb2_grpc.EngineStub(channel) + for i in range(nb_check): + indexed_output = f"{output}_{i}" + stub.ProcessServiceCheckResult(engine_pb2.Check( + host_name=hst, svc_desc=svc, output=indexed_output, code=state)) -def process_service_check_result(hst: str, svc: str, state: int, output: str, config='config0'): - now = int(time.time()) - cmd = f"[{now}] PROCESS_SERVICE_CHECK_RESULT;{hst};{svc};{state};{output}\n" - f = open( - f"{VAR_ROOT}/lib/centreon-engine/{config}/rw/centengine.cmd", "w") - f.write(cmd) - f.close() + else: + now = int(time.time()) + with open(f"{VAR_ROOT}/lib/centreon-engine/{config}/rw/centengine.cmd", "w") as f: + for i in range(nb_check): + cmd = f"[{now}] PROCESS_SERVICE_CHECK_RESULT;{hst};{svc};{state};{output}_{i}\n" + f.write(cmd) @external_command diff --git a/tests/update-doc.py b/tests/update-doc.py index 752ffe36b87..906afaa9e88 100755 --- a/tests/update-doc.py +++ b/tests/update-doc.py @@ -75,7 +75,7 @@ def parse_dir(d): On other rpm based distributions, you can try the following commands to initialize your robot tests: ``` -pip3 install -U robotframework robotframework-databaselibrary robotframework-httpctrl pymysql +pip3 install -U robotframework robotframework-databaselibrary robotframework-httpctrl robotframework-examples pymysql yum install python3-devel -y