Skip to content

Commit

Permalink
HPCC-32717 Create basic Elastic sink component
Browse files Browse the repository at this point in the history
Created new skeleton component and added to the build

Signed-Off-By: Kenneth Rowland kenneth.rowland@lexisnexisrisk.com
  • Loading branch information
kenrowland committed Sep 26, 2024
1 parent 318d964 commit 3b20b29
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
3 changes: 2 additions & 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) 2021 HPCC Systems®.
# HPCC SYSTEMS software Copyright (C) 20214HPCC Systems®.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,3 +17,4 @@
HPCC_ADD_SUBDIRECTORY (file)
HPCC_ADD_SUBDIRECTORY (log)
HPCC_ADD_SUBDIRECTORY (prometheus)
HPCC_ADD_SUBDIRECTORY (elastic)
33 changes: 33 additions & 0 deletions system/metrics/sinks/elastic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
################################################################################
# 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.
################################################################################

project(hpccmetrics_elasticsink)

set ( srcs
elasticSink.cpp
)

include_directories(
${HPCC_SOURCE_DIR}/system/include
${HPCC_SOURCE_DIR}/system/jlib
${HPCC_SOURCE_DIR}/system/httplib
)

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_CXX_FLAGS}")
ADD_DEFINITIONS( -DELASTICSINK_EXPORTS )
HPCC_ADD_LIBRARY( hpccmetrics_elasticsink SHARED ${srcs} )
TARGET_LINK_LIBRARIES( hpccmetrics_elasticsink jlib)
INSTALL ( TARGETS hpccmetrics_elasticsink RUNTIME DESTINATION ${EXEC_DIR} LIBRARY DESTINATION ${LIB_DIR} )
51 changes: 51 additions & 0 deletions system/metrics/sinks/elastic/elasticSink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*##############################################################################
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 <cstdio>
#include "platform.h"

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, "file", pSettingsTree),
ignoreZeroMetrics(false)
{
ignoreZeroMetrics = pSettingsTree->getPropBool("@ignoreZeroMetrics", true);
}


void ElasticMetricSink::prepareToStartCollecting()
{

}


void ElasticMetricSink::doCollection()
{

}


void ElasticMetricSink::collectingHasStopped()
{
;
}

59 changes: 59 additions & 0 deletions system/metrics/sinks/elastic/elasticSink.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*##############################################################################
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.
############################################################################## */


#pragma once

#include "jmetrics.hpp"
#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
#define ELASTICSINK_API DECL_IMPORT
#endif

class ELASTICSINK_API ElasticMetricSink : public hpccMetrics::PeriodicMetricSink
{
public:
explicit ElasticMetricSink(const char *name, const IPropertyTree *pSettingsTree);
~ElasticMetricSink() override = default;

protected:
void prepareToStartCollecting() override;
void collectingHasStopped() override;
void doCollection() override;

protected:
StringBuffer indexName;
bool ignoreZeroMetrics;
};

0 comments on commit 3b20b29

Please sign in to comment.