From 8be85a73be22c123f175a4f3c5d5bb97aeabb44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sat, 14 Jan 2023 12:52:40 +0100 Subject: [PATCH] Add support for OpenSearch to server detection --- lstail/util/http.py | 7 ++++++- .../test_data/opensearch_cluster_state_es1.json | 17 +++++++++++++++++ .../test_data/opensearch_cluster_state_es2.json | 17 +++++++++++++++++ tests/unit/util_http_test.py | 2 ++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/test_data/opensearch_cluster_state_es1.json create mode 100644 tests/test_data/opensearch_cluster_state_es2.json diff --git a/lstail/util/http.py b/lstail/util/http.py index 64f87f6..6f413e2 100644 --- a/lstail/util/http.py +++ b/lstail/util/http.py @@ -35,7 +35,12 @@ def _log_error(exc): else: try: exact_version = cluster_state['version']['number'] - if exact_version.startswith('2.'): + + # OpenSearch + if cluster_state['version'].get('distribution') == "opensearch": + es_major_version = ELASTICSEARCH_MAJOR_VERSION_7 + # ElasticSearch + elif exact_version.startswith('2.'): es_major_version = ELASTICSEARCH_MAJOR_VERSION_2 elif exact_version.startswith('5.') or exact_version.startswith('6.'): es_major_version = ELASTICSEARCH_MAJOR_VERSION_6 diff --git a/tests/test_data/opensearch_cluster_state_es1.json b/tests/test_data/opensearch_cluster_state_es1.json new file mode 100644 index 0000000..ec6a6ea --- /dev/null +++ b/tests/test_data/opensearch_cluster_state_es1.json @@ -0,0 +1,17 @@ +{ + "name" : "test-cluster-os2-n1", + "cluster_name" : "test-cluster-os2", + "cluster_uuid" : "d6af0bf5-3be4-4e98-aff1-812a5b6bcdfe", + "version" : { + "distribution" : "opensearch", + "number" : "1.2.0", + "build_type" : "tar", + "build_hash" : "c459282fd67ddb17dcc545ec9bcdc805880bcbec", + "build_date" : "2021-11-22T16:57:18.360386Z", + "build_snapshot" : false, + "lucene_version" : "8.10.1", + "minimum_wire_compatibility_version" : "6.8.0", + "minimum_index_compatibility_version" : "6.0.0-beta1" + }, + "tagline" : "The OpenSearch Project: https://opensearch.org/" +} diff --git a/tests/test_data/opensearch_cluster_state_es2.json b/tests/test_data/opensearch_cluster_state_es2.json new file mode 100644 index 0000000..ef40acb --- /dev/null +++ b/tests/test_data/opensearch_cluster_state_es2.json @@ -0,0 +1,17 @@ +{ + "name" : "test-cluster-os2-n1", + "cluster_name" : "test-cluster-os2", + "cluster_uuid" : "d6af0bf5-3be4-4e98-aff1-812a5b6bcdfe", + "version" : { + "distribution" : "opensearch", + "number" : "2.4.0", + "build_type" : "tar", + "build_hash" : "744ca260b892d119be8164f48d92b8810bd7801c", + "build_date" : "2022-11-15T04:42:29.671309257Z", + "build_snapshot" : false, + "lucene_version" : "9.4.1", + "minimum_wire_compatibility_version" : "7.10.0", + "minimum_index_compatibility_version" : "7.0.0" + }, + "tagline" : "The OpenSearch Project: https://opensearch.org/" +} diff --git a/tests/unit/util_http_test.py b/tests/unit/util_http_test.py index 89e106e..e57da9a 100644 --- a/tests/unit/util_http_test.py +++ b/tests/unit/util_http_test.py @@ -21,6 +21,8 @@ (ELASTICSEARCH_MAJOR_VERSION_7, 'elasticsearch_cluster_state_es7'), (ELASTICSEARCH_MAJOR_VERSION_6, 'elasticsearch_cluster_state_es6'), (ELASTICSEARCH_MAJOR_VERSION_2, 'elasticsearch_cluster_state_es2'), + (ELASTICSEARCH_MAJOR_VERSION_7, 'opensearch_cluster_state_es1'), + (ELASTICSEARCH_MAJOR_VERSION_7, 'opensearch_cluster_state_es2'), )