Skip to content

Commit

Permalink
MON-20431 Add metrics name tests size (#839) (#998)
Browse files Browse the repository at this point in the history
REFS:MON-32950
* Add metrics name tests size

* Update library installation

* fix tests

---------

Co-authored-by: NITCHEU B <[email protected]>
  • Loading branch information
jean-christophe81 and thearchit3ct authored Feb 7, 2024
1 parent e2e1a1f commit 56b8953
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 12 deletions.
2 changes: 1 addition & 1 deletion resources/centreon_storage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 56 additions & 0 deletions tests/broker-engine/services-and-bulk-stmt.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/broker-engine/services-increased.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
27 changes: 18 additions & 9 deletions tests/resources/Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/update-doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56b8953

Please sign in to comment.