From 2f4bd625bd01c5cd0540df3ad6f6a979d3004b4e Mon Sep 17 00:00:00 2001 From: Ken Rowland Date: Mon, 30 Sep 2024 13:40:17 -0400 Subject: [PATCH] Addressed review comments --- system/metrics/sinks/CMakeLists.txt | 2 +- system/metrics/sinks/elastic/elasticSink.cpp | 24 +++++- .../metrics/sinks/elastic/elasticSink.cpp.bak | 80 +++++++++++++++++++ system/metrics/sinks/elastic/elasticSink.hpp | 27 ++----- 4 files changed, 106 insertions(+), 27 deletions(-) create mode 100644 system/metrics/sinks/elastic/elasticSink.cpp.bak diff --git a/system/metrics/sinks/CMakeLists.txt b/system/metrics/sinks/CMakeLists.txt index a46652b191c..d79f53e0871 100644 --- a/system/metrics/sinks/CMakeLists.txt +++ b/system/metrics/sinks/CMakeLists.txt @@ -1,5 +1,5 @@ ############################################################################### -# HPCC SYSTEMS software Copyright (C) 20214HPCC Systems®. +# HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/system/metrics/sinks/elastic/elasticSink.cpp b/system/metrics/sinks/elastic/elasticSink.cpp index 0c3a4bba890..cfe03b35ca3 100644 --- a/system/metrics/sinks/elastic/elasticSink.cpp +++ b/system/metrics/sinks/elastic/elasticSink.cpp @@ -12,8 +12,23 @@ ############################################################################## */ #include "elasticSink.hpp" -#include -#include "platform.h" + +#include "nlohmann/json.hpp" + +//including cpp-httplib single header file REST client +// doesn't work with format-nonliteral as an error +// +#if defined(__clang__) || defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + +#undef INVALID_SOCKET +#include "httplib.h" + +#if defined(__clang__) || defined(__GNUC__) +#pragma GCC diagnostic pop +#endif using namespace hpccMetrics; @@ -25,10 +40,11 @@ extern "C" MetricSink* getSinkInstance(const char *name, const IPropertyTree *pS ElasticMetricSink::ElasticMetricSink(const char *name, const IPropertyTree *pSettingsTree) : - PeriodicMetricSink(name, "file", pSettingsTree), - ignoreZeroMetrics(false) + PeriodicMetricSink(name, "elastic", pSettingsTree) { ignoreZeroMetrics = pSettingsTree->getPropBool("@ignoreZeroMetrics", true); + pSettingsTree->getProp("@elasticHost", elasticHost); + pSettingsTree->getProp("@indexName", indexName); } diff --git a/system/metrics/sinks/elastic/elasticSink.cpp.bak b/system/metrics/sinks/elastic/elasticSink.cpp.bak new file mode 100644 index 00000000000..553fee41e57 --- /dev/null +++ b/system/metrics/sinks/elastic/elasticSink.cpp.bak @@ -0,0 +1,80 @@ +/*############################################################################## + HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +############################################################################## */ + +#include "elasticSink.hpp" + +#include "nlohmann/json.hpp" + +//including cpp-httplib single header file REST client +// doesn't work with format-nonliteral as an error +// +#if defined(__clang__) || defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + +#undef INVALID_SOCKET +#include "httplib.h" + +#if defined(__clang__) || defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + +using namespace hpccMetrics; + +extern "C" MetricSink* getSinkInstance(const char *name, const IPropertyTree *pSettingsTree) +{ + MetricSink *pSink = new ElasticMetricSink(name, pSettingsTree); + return pSink; +} + + +ElasticMetricSink::ElasticMetricSink(const char *name, const IPropertyTree *pSettingsTree) : + PeriodicMetricSink(name, "elastic", pSettingsTree) +{ + ignoreZeroMetrics = pSettingsTree->getPropBool("@ignoreZeroMetrics", true); + pSettingsTree->getProp("@elasticHost", elasticHost); + + httplib::Client elasticClient(elasticHost.str()); + + nlohmann::json json_data = { + {"key1", "value1"}, + {"key2", "value2"} + }; + + std::string json_string = json_data.dump(); + + auto res = elasticClient.Post("/elastichost", json_string, "application/json"); + + lastStatus = res->status; + +} + + +void ElasticMetricSink::prepareToStartCollecting() +{ + +} + + +void ElasticMetricSink::doCollection() +{ + +} + + +void ElasticMetricSink::collectingHasStopped() +{ + ; +} + diff --git a/system/metrics/sinks/elastic/elasticSink.hpp b/system/metrics/sinks/elastic/elasticSink.hpp index 74dec839679..c83c8afb51e 100644 --- a/system/metrics/sinks/elastic/elasticSink.hpp +++ b/system/metrics/sinks/elastic/elasticSink.hpp @@ -18,24 +18,6 @@ #include "jptree.hpp" #include "jstring.hpp" -//including cpp-httplib single header file REST client -// doesn't work with format-nonliteral as an error -// -#if defined(__clang__) || defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - -#undef INVALID_SOCKET -#include "httplib.h" - -#if defined(__clang__) || defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - -#include "nlohmann/json.hpp" - - #ifdef ELASTICINK_EXPORTS #define ELASTICSINK_API DECL_EXPORT #else @@ -49,11 +31,12 @@ class ELASTICSINK_API ElasticMetricSink : public hpccMetrics::PeriodicMetricSink ~ElasticMetricSink() override = default; protected: - void prepareToStartCollecting() override; - void collectingHasStopped() override; - void doCollection() override; + virtual void prepareToStartCollecting() override; + virtual void collectingHasStopped() override; + virtual void doCollection() override; protected: StringBuffer indexName; - bool ignoreZeroMetrics; + bool ignoreZeroMetrics = false; + StringBuffer elasticHost; };