From 4301df46caa0b7d27767366e05f73ebc4e73e3c1 Mon Sep 17 00:00:00 2001 From: Aleksandr Ivanov Date: Mon, 30 Oct 2023 13:54:03 +0200 Subject: [PATCH] Refactor test to use broker default config Signed-off-by: Aleksandr Ivanov --- .../tests/localBMQ/etc/bmqbrkrcfg.json | 112 ------------------ .../tests/localBMQ/etc/clusters.json | 88 -------------- .../etc/domains/bmq.test.mem.broadcast.json | 37 ------ .../etc/domains/bmq.test.mem.fanout.json | 43 ------- .../etc/domains/bmq.test.mem.priority.json | 37 ------ .../domains/bmq.test.persistent.fanout.json | 43 ------- .../bmq.test.persistent.fanout.sc.json | 43 ------- .../domains/bmq.test.persistent.priority.json | 37 ------ .../bmq.test.persistent.priority.sc.json | 37 ------ .../prometheus/tests/localBMQ/logs/.keep | 0 .../localBMQ/storage/local/archive/.keep | 0 .../prometheus_prometheusstatconsumer_test.py | 50 +++++--- 12 files changed, 31 insertions(+), 496 deletions(-) delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/bmqbrkrcfg.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/clusters.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.broadcast.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.fanout.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.priority.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.sc.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.sc.json delete mode 100644 src/plugins/prometheus/tests/localBMQ/logs/.keep delete mode 100644 src/plugins/prometheus/tests/localBMQ/storage/local/archive/.keep diff --git a/src/plugins/prometheus/tests/localBMQ/etc/bmqbrkrcfg.json b/src/plugins/prometheus/tests/localBMQ/etc/bmqbrkrcfg.json deleted file mode 100644 index 437cb8baf..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/bmqbrkrcfg.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "taskConfig": { - "allocatorType": "STACKTRACETEST", - "allocationLimit": 34359738368, - "logController": { - "fileName": "localBMQ/logs/logs.%T.%p", - "fileMaxAgeDays": 10, - "rotationBytes": 268435456, - "logfileFormat": "%d (%t) %s %F:%l %m\n\n", - "consoleFormat": "%d (%t) %s %F:%l %m\n", - "loggingVerbosity": "INFO", - "consoleSeverityThreshold": "ERROR", - "categories": [ - "BMQBRKR:INFO:green", - "BMQ*:INFO:green", - "MQB*:INFO:green", - "SIM*:INFO:gray", - "DMC*:INFO:yellow", - "BAEA.PERFORMANCEMONITOR:INFO:white" - ], - "syslog": { - "enabled": false, - "appName": "BMQ", - "logFormat": "%d (%t) %s %F:%l %m\n\n", - "verbosity": "" - } - } - }, - "appConfig": { - "brokerInstanceName": "default", - "brokerVersion": 999999, - "configVersion": 999999, - "etcDir": "", - "hostName": "localhost", - "hostTags": "standalone", - "hostDataCenter": "UNSPECIFIED", - "isRunningOnDev": false, - "logsObserverMaxSize": 1000, - "dispatcherConfig": { - "sessions": { - "numProcessors": 4, - "processorConfig": { - "queueSizeLowWatermark": 100000, - "queueSizeHighWatermark": 200000, - "queueSize": 500000 - } - }, - "queues": { - "numProcessors": 8, - "processorConfig": { - "queueSizeLowWatermark": 100000, - "queueSizeHighWatermark": 200000, - "queueSize": 500000 - } - }, - "clusters": { - "numProcessors": 4, - "processorConfig": { - "queueSizeLowWatermark": 100000, - "queueSizeHighWatermark": 200000, - "queueSize": 500000 - } - } - }, - "stats": { - "snapshotInterval": 1, - "plugins": [ - { - "name": "PrometheusStatConsumer", - "publishInterval": 1, - "host": "localhost", - "port": 9091, - "mode": "push" - } - ], - "printer": { - "printInterval": 60, - "file": "./localBMQ/logs/stat.%T.%p", - "maxAgeDays": 3, - "rotateBytes": 268435456, - "rotateDays": 1 - } - }, - "networkInterfaces": { - "heartbeats": { - "client": 0, - "downstreamBroker": 10, - "upstreamBroker": 10, - "clusterPeer": 10 - }, - "tcpInterface": { - "name": "TCPInterface", - "port": 30114, - "ioThreads": 4, - "maxConnections": 10000, - "lowWatermark": 4194304, - "highWatermark": 1073741824, - "nodeLowWatermark": 5242880, - "nodeHighWatermark": 10485760, - "heartbeatIntervalMs": 3000, - "useNtf": false - } - }, - "bmqconfConfig": { - "cacheTTLSeconds": 30 - }, - "plugins": { - "libraries": ["./"], - "enabled": ["PrometheusStatConsumer"] - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/clusters.json b/src/plugins/prometheus/tests/localBMQ/etc/clusters.json deleted file mode 100644 index a61ea742e..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/clusters.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "myClusters": [ - { - "name": "local", - "clusterAttributes": { - "isCSLModeEnabled": true, - "isFSMWorkflow": false - }, - "nodes": [ - { - "id": 0, - "dataCenter": "UNSPECIFIED", - "name": "localhost", - "transport": { - "tcp": { - "endpoint": "tcp://localhost:30114" - } - } - } - ], - "partitionConfig": { - "flushAtShutdown": true, - "location": "localBMQ/storage/local", - "maxArchivedFileSets": 0, - "maxDataFileSize": 268435456, - "maxJournalFileSize": 67108864, - "maxQlistFileSize": 8388608, - "numPartitions": 1, - "preallocate": false, - "prefaultPages": false, - "archiveLocation": "localBMQ/storage/local/archive", - "syncConfig": { - "fileChunkSize": 0, - "masterSyncMaxDurationMs": 0, - "maxAttemptsStorageSync": 0, - "partitionSyncDataReqTimeoutMs": 0, - "partitionSyncEventSize": 0, - "partitionSyncStateReqTimeoutMs": 0, - "startupRecoveryMaxDurationMs": 0, - "startupWaitDurationMs": 0, - "storageSyncReqTimeoutMs": 0 - } - }, - "masterAssignment": "E_LEADER_IS_MASTER_ALL", - "elector": { - "electionResultTimeoutMs": 4000, - "heartbeatBroadcastPeriodMs": 2000, - "heartbeatCheckPeriodMs": 1000, - "heartbeatMissCount": 10, - "initialWaitTimeoutMs": 8000, - "leaderSyncDelayMs": 80000, - "maxRandomWaitTimeoutMs": 3000, - "quorum": 0 - }, - "queueOperations": { - "ackWindowSize": 500, - "assignmentTimeoutMs": 15000, - "closeTimeoutMs": 300000, - "configureTimeoutMs": 300000, - "consumptionMonitorPeriodMs": 30000, - "keepaliveDurationMs": 1800000, - "openTimeoutMs": 300000, - "reopenMaxAttempts": 10, - "reopenRetryIntervalMs": 5000, - "reopenTimeoutMs": 43200000, - "shutdownTimeoutMs": 20000, - "stopTimeoutMs": 10000 - }, - "clusterMonitorConfig": { - "maxTimeLeader": 60, - "maxTimeMaster": 120, - "maxTimeNode": 120, - "maxTimeFailover": 240, - "thresholdLeader": 30, - "thresholdMaster": 60, - "thresholdNode": 60, - "thresholdFailover": 120 - }, - "messageThrottleConfig": { - "lowThreshold": 2, - "highThreshold": 4, - "lowInterval": 1000, - "highInterval": 3000 - } - } - ], - "proxyClusters": [] -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.broadcast.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.broadcast.json deleted file mode 100644 index b8a90ab9a..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.broadcast.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "consistency": { - "eventual": {} - }, - "storage": { - "config": { - "inMemory": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "maxProducers": 0, - "maxConsumers": 0, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "broadcast": {} - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.fanout.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.fanout.json deleted file mode 100644 index bcb56dfe3..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.fanout.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "consistency": { - "eventual": {} - }, - "storage": { - "config": { - "inMemory": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "maxProducers": 0, - "maxConsumers": 0, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "fanout": { - "appIDs": [ - "foo", - "bar", - "baz" - ] - } - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.priority.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.priority.json deleted file mode 100644 index aaeeba988..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.mem.priority.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "consistency": { - "eventual": {} - }, - "storage": { - "config": { - "inMemory": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "maxProducers": 0, - "maxConsumers": 0, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "priority": {} - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.json deleted file mode 100644 index 0595781d8..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "consistency": { - "eventual": {} - }, - "storage": { - "config": { - "fileBacked": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "maxProducers": 0, - "maxConsumers": 0, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "fanout": { - "appIDs": [ - "foo", - "bar", - "baz" - ] - } - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.sc.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.sc.json deleted file mode 100644 index 55d3db7a9..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.fanout.sc.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "storage": { - "config": { - "fileBacked": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "consistency": { - "strong": {} - }, - "maxProducers": 0, - "maxConsumers": 1, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "fanout": { - "appIDs": [ - "foo", - "bar", - "baz" - ] - } - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.json deleted file mode 100644 index 667784b9e..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "consistency": { - "eventual": {} - }, - "storage": { - "config": { - "fileBacked": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "maxProducers": 0, - "maxConsumers": 0, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "priority": {} - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.sc.json b/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.sc.json deleted file mode 100644 index 3a2339072..000000000 --- a/src/plugins/prometheus/tests/localBMQ/etc/domains/bmq.test.persistent.priority.sc.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "definition": { - "location": "local", - "parameters": { - "maxDeliveryAttempts": 0, - "deduplicationTimeMs": 300000, - "storage": { - "config": { - "fileBacked": {} - }, - "domainLimits": { - "bytes": 2097152, - "messages": 2000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - }, - "queueLimits": { - "bytes": 1048576, - "messages": 1000, - "bytesWatermarkRatio": 0.8, - "messagesWatermarkRatio": 0.8 - } - }, - "messageTtl": 300, - "consistency": { - "strong": {} - }, - "maxProducers": 0, - "maxConsumers": 0, - "maxQueues": 0, - "maxIdleTime": 0, - "mode": { - "priority": {} - } - } - } -} diff --git a/src/plugins/prometheus/tests/localBMQ/logs/.keep b/src/plugins/prometheus/tests/localBMQ/logs/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/plugins/prometheus/tests/localBMQ/storage/local/archive/.keep b/src/plugins/prometheus/tests/localBMQ/storage/local/archive/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/plugins/prometheus/tests/prometheus_prometheusstatconsumer_test.py b/src/plugins/prometheus/tests/prometheus_prometheusstatconsumer_test.py index b09657764..9b463cbf2 100755 --- a/src/plugins/prometheus/tests/prometheus_prometheusstatconsumer_test.py +++ b/src/plugins/prometheus/tests/prometheus_prometheusstatconsumer_test.py @@ -21,7 +21,7 @@ Usage: ./prometheus_prometheusstatconsumer_test.py [-h] -p PATH options: -h, --help show this help message and exit - -p PATH, --path PATH absolute path to BlasingMQ folder + -p PATH, --path PATH path to BlasingMQ build folder """ import argparse @@ -30,6 +30,7 @@ import os import shutil import subprocess +import sys import tempfile import time import urllib.parse @@ -51,12 +52,12 @@ def parse_arguments(): parser = argparse.ArgumentParser( description='Integration tests for Prometheus plugin') parser.add_argument('-p', '--path', type=str, required=True, - help="absolute path to BlasingMQ folder") + help="path to BlasingMQ build folder") return parser.parse_args() -def test_local_cluster(plugin_path, broker_path, broker_cfg_path, tool_path, prometheus_host, prometheus_docker_file_path, mode): +def test_local_cluster(plugin_path, broker_path, tool_path, prometheus_host, prometheus_docker_file_path, mode): current_dir = os.getcwd() # Run Prometheus in docker @@ -67,16 +68,27 @@ def test_local_cluster(plugin_path, broker_path, broker_cfg_path, tool_path, pro # Create sandbox in temp folder with tempfile.TemporaryDirectory() as tmpdirname: # Copy broker and plugins lib into sandbox - shutil.copy(plugin_path.joinpath('libprometheus.so'), tmpdirname) - shutil.copy(broker_path.joinpath('bmqbrkr.tsk'), tmpdirname) + shutil.copy(plugin_path, tmpdirname) + shutil.copy(broker_path, tmpdirname) # Copy broker config folder into sandbox + broker_cfg_path = broker_path.parent.joinpath('etc') local_cfg_path = shutil.copytree( - Path(broker_cfg_path), Path(tmpdirname).joinpath('localBMQ')) + Path(broker_cfg_path), Path(tmpdirname).joinpath('localBMQ/etc')) + # Create required folders + os.makedirs(Path(tmpdirname).joinpath('localBMQ/logs')) + os.makedirs(Path(tmpdirname).joinpath( + 'localBMQ/storage/local/archive')) # Edit broker config for given mode - local_cfg_file = Path(local_cfg_path.joinpath('etc/bmqbrkrcfg.json')) + local_cfg_file = Path(local_cfg_path.joinpath('bmqbrkrcfg.json')) with local_cfg_file.open() as f: local_cfg = json.load(f) + local_cfg['taskConfig']['logController']['consoleSeverityThreshold'] = 'ERROR' + local_cfg['appConfig']['stats']['plugins'] = [ + dict(name='PrometheusStatConsumer', publishInterval=1, host='localhost')] + local_cfg['appConfig']['plugins'] = dict( + libraries=['./'], enabled=['PrometheusStatConsumer']) + prometheus_cfg = local_cfg['appConfig']['stats']['plugins'][0] if mode == 'push': prometheus_cfg['port'] = 9091 @@ -136,27 +148,27 @@ def test_local_cluster(plugin_path, broker_path, broker_cfg_path, tool_path, pro def main(args): - prometheus_docker_file_path = Path(args.path).joinpath( - 'src/plugins/prometheus/tests/docker/docker-compose.yml') - broker_path = Path(args.path).joinpath( - 'build/blazingmq/src/applications/bmqbrkr') - broker_cfg_path = Path(args.path).joinpath( - 'src/plugins/prometheus/tests/localBMQ') - tool_path = Path(args.path).joinpath( - 'build/blazingmq/src/applications/bmqtool/bmqtool.tsk') - plugin_path = Path(args.path).joinpath('build/blazingmq/src/plugins') + build_dir = Path(args.path).absolute() + test_folder = Path(__file__).absolute().parent + prometheus_docker_file_path = test_folder.joinpath( + 'docker/docker-compose.yml') + broker_path = build_dir.joinpath('src/applications/bmqbrkr/bmqbrkr.tsk') + tool_path = build_dir.joinpath('src/applications/bmqtool/bmqtool.tsk') + plugin_path = build_dir.joinpath('src/plugins/libprometheus.so') results = dict() results['local_cluster_test_with_push_mode'] = test_local_cluster( - plugin_path, broker_path, broker_cfg_path, tool_path, PROMETHEUS_HOST, prometheus_docker_file_path, 'push') + plugin_path, broker_path, tool_path, PROMETHEUS_HOST, prometheus_docker_file_path, 'push') results['local_cluster_test_with_pull_mode'] = test_local_cluster( - plugin_path, broker_path, broker_cfg_path, tool_path, PROMETHEUS_HOST, prometheus_docker_file_path, 'pull') + plugin_path, broker_path, tool_path, PROMETHEUS_HOST, prometheus_docker_file_path, 'pull') print('\n\n\n========================================') print(f'{len(results)} integration tests executed with following results:') for test, result in results.items(): print(f'{test} : {"passed" if result else "failed"}') + return not all(results.values()) + def _make_request(host, url, params={}): try: @@ -252,4 +264,4 @@ def _assert_message(metric, expected, given): if __name__ == '__main__': - main(parse_arguments()) + sys.exit(main(parse_arguments()))