Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrowland committed Oct 4, 2024
1 parent 3b20b29 commit 2f4bd62
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 27 deletions.
2 changes: 1 addition & 1 deletion system/metrics/sinks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 20 additions & 4 deletions system/metrics/sinks/elastic/elasticSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,23 @@
############################################################################## */

#include "elasticSink.hpp"
#include <cstdio>
#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;

Expand All @@ -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);
}


Expand Down
80 changes: 80 additions & 0 deletions system/metrics/sinks/elastic/elasticSink.cpp.bak
Original file line number Diff line number Diff line change
@@ -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()
{
;
}

27 changes: 5 additions & 22 deletions system/metrics/sinks/elastic/elasticSink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};

0 comments on commit 2f4bd62

Please sign in to comment.