Skip to content

Commit

Permalink
enh(broker/common) http_client is moved to common and new class http_…
Browse files Browse the repository at this point in the history
…server

REFS: MON-35539
  • Loading branch information
jean-christophe81 authored May 17, 2024
1 parent 7469727 commit 638297b
Show file tree
Hide file tree
Showing 34 changed files with 1,425 additions and 775 deletions.
1 change: 0 additions & 1 deletion broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ add_broker_module(TLS2 OFF)
add_broker_module(DUMP OFF)
add_broker_module(GRPC ON)
add_broker_module(VICTORIA_METRICS ON)
add_subdirectory(http_client)
add_subdirectory(http_tsdb)

# Lua module.
Expand Down
49 changes: 0 additions & 49 deletions broker/http_client/precomp_inc/precomp.hh

This file was deleted.

4 changes: 2 additions & 2 deletions broker/http_tsdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# Global options.

set(INC_DIR "${PROJECT_SOURCE_DIR}/http_tsdb/inc/com/centreon/broker/http_tsdb")
set(HTTP_CLIENT_INC_DIR "${PROJECT_SOURCE_DIR}/http_client/inc")
set(HTTP_INC_DIR "${CMAKE_SOURCE_DIR}/common/http/inc")
set(SRC_DIR "src")
set(TEST_DIR "${PROJECT_SOURCE_DIR}/http_tsdb/test")
include_directories(inc ${INC_DIR} ${HTTP_CLIENT_INC_DIR})
include_directories(inc ${INC_DIR} ${HTTP_INC_DIR})

# Sources.
set(SOURCES
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/*
** Copyright 2022 Centreon
**
** 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.
**
** For more information : [email protected]
*/
/**
* Copyright 2024 Centreon (https://www.centreon.com/)
*
* 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.
*
* For more information : [email protected]
*
*/

#ifndef CCB_HTTP_TSDB_CONFIG_HH
#define CCB_HTTP_TSDB_CONFIG_HH

#include "column.hh"
#include "com/centreon/broker/http_client/http_config.hh"
#include "com/centreon/common/http/http_config.hh"

namespace com::centreon::broker {

namespace http_tsdb {
class http_tsdb_config : public http_client::http_config {
class http_tsdb_config : public common::http::http_config {
std::string _http_target;
std::string _user;
std::string _pwd;
Expand All @@ -34,14 +35,14 @@ class http_tsdb_config : public http_client::http_config {
std::vector<column> _metric_columns;

public:
http_tsdb_config(const http_client::http_config& http_conf,
http_tsdb_config(const common::http::http_config& http_conf,
const std::string& http_target,
const std::string& user,
const std::string& pwd,
unsigned max_queries_per_transaction,
const std::vector<column>& status_columns,
const std::vector<column>& metric_columns)
: http_client::http_config(http_conf),
: common::http::http_config(http_conf),
_http_target(http_target),
_user(user),
_pwd(pwd),
Expand All @@ -50,9 +51,9 @@ class http_tsdb_config : public http_client::http_config {
_metric_columns(metric_columns) {}

http_tsdb_config() : _max_queries_per_transaction(0) {}
http_tsdb_config(const http_client::http_config& http_conf,
http_tsdb_config(const common::http::http_config& http_conf,
unsigned max_queries_per_transaction)
: http_client::http_config(http_conf),
: common::http::http_config(http_conf),
_max_queries_per_transaction(max_queries_per_transaction) {}

const std::string& get_http_target() const { return _http_target; }
Expand All @@ -71,6 +72,6 @@ class http_tsdb_config : public http_client::http_config {
};
} // namespace http_tsdb

}
} // namespace com::centreon::broker

#endif
61 changes: 30 additions & 31 deletions broker/http_tsdb/inc/com/centreon/broker/http_tsdb/stream.hh
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
/*
** Copyright 2011-2017 Centreon
**
** 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.
**
** For more information : [email protected]
*/
/**
* Copyright 2024 Centreon (https://www.centreon.com/)
*
* 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.
*
* For more information : [email protected]
*
*/

#ifndef CCB_HTTP_TSDB_STREAM_HH
#define CCB_HTTP_TSDB_STREAM_HH

#include "com/centreon/broker/http_client/http_client.hh"
#include "com/centreon/broker/io/stream.hh"
#include "com/centreon/broker/persistent_cache.hh"
#include "com/centreon/common/http/http_client.hh"
#include "http_tsdb_config.hh"
#include "internal.hh"
#include "line_protocol_query.hh"

namespace http_client = com::centreon::broker::http_client;
namespace http = com::centreon::common::http;

namespace com::centreon::broker {

namespace http_tsdb {

class request : public http_client::request_base {
class request : public http::request_base {
protected:
unsigned _nb_metric;
unsigned _nb_status;
Expand All @@ -43,9 +44,8 @@ class request : public http_client::request_base {
request() : _nb_metric(0), _nb_status(0) {}
request(boost::beast::http::verb method,
const std::string& server_name,
boost::beast::string_view target,
unsigned version = 11)
: http_client::request_base(method, server_name, target),
boost::beast::string_view target)
: http::request_base(method, server_name, target),
_nb_metric(0),
_nb_status(0) {}

Expand All @@ -67,7 +67,7 @@ inline std::ostream& operator<<(std::ostream& str, const request& req) {
return str;
}

/**
/*
* @class stream stream.hh "com/centreon/broker/influxdb/stream.hh"
* @brief tsdb stream.
* This class is a base class
Expand All @@ -82,15 +82,15 @@ class stream : public io::stream, public std::enable_shared_from_this<stream> {
// Database and http parameters
std::shared_ptr<http_tsdb_config> _conf;

http_client::client::pointer _http_client;
http::client::pointer _http_client;

// number of metric and status sent to tsdb and acknowledged by a 20x response
unsigned _acknowledged;
// the current request that buffers metric to send
request::pointer _request;
// the two beans stat_unit and stat_average are used to produce statistics
// about request time
/**
/*
* @brief stat cumul
* this bean is used to cumulate request for example during one second
*/
Expand All @@ -106,7 +106,7 @@ class stream : public io::stream, public std::enable_shared_from_this<stream> {
stat _metric_stat;
stat _status_stat;

/**
/*
* @brief this cless calc an average over a period
*
*/
Expand All @@ -129,8 +129,7 @@ class stream : public io::stream, public std::enable_shared_from_this<stream> {
const std::shared_ptr<asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
const std::shared_ptr<http_tsdb_config>& conf,
http_client::client::connection_creator conn_creator =
http_client::http_connection::load);
http::connection_creator conn_creator);

virtual request::pointer create_request() const = 0;

Expand All @@ -139,7 +138,7 @@ class stream : public io::stream, public std::enable_shared_from_this<stream> {
void send_handler(const boost::beast::error_code& err,
const std::string& detail,
const request::pointer& request,
const http_client::response_ptr& response);
const http::response_ptr& response);

void add_to_stat(stat& to_maj, unsigned to_add);

Expand All @@ -155,6 +154,6 @@ class stream : public io::stream, public std::enable_shared_from_this<stream> {
};
} // namespace http_tsdb

}
} // namespace com::centreon::broker

#endif // !CCB_HTTP_TSDB_STREAM_HH
35 changes: 18 additions & 17 deletions broker/http_tsdb/src/factory.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/**
* Copyright 2011-2017 Centreon
*
* 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.
*
* For more information : [email protected]
*/
* Copyright 2024 Centreon (https://www.centreon.com/)
*
* 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.
*
* For more information : [email protected]
*
*/

#include "com/centreon/broker/http_tsdb/factory.hh"

Expand Down Expand Up @@ -244,7 +245,7 @@ void factory::create_conf(const config::endpoint& cfg,
certificate_path = it->second;
}

http_client::http_config http_cfg(
common::http::http_config http_cfg(
res_it->endpoint(), addr, encryption, connect_timeout, send_timeout,
receive_timeout, second_tcp_keep_alive_interval, std::chrono::seconds(1),
0, default_http_keepalive_duration, max_connections, ssl_method,
Expand Down
Loading

1 comment on commit 638297b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
3 2 0 5 60.00 6m17.530901s

Failed Tests

Name Message ⏱️ Duration Suite
BRCTS1 There should not exist queue map files. 162.803 s Reverse-Connection
BRCS1 There should not exist queue map files. 55.035 s Reverse-Connection

Please sign in to comment.