Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【腾讯犀牛鸟开源课题实战】prometheus插件专项建设(PUSH模式支持等) #175

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
809dfe0
Update prometheus documentation and running scripts
Heaven2024 Aug 26, 2024
ccfc856
Update prometheus documentation and running scripts
Heaven2024 Aug 26, 2024
8a1de0e
Fixed prometheus documentation and running scripts
Heaven2024 Aug 26, 2024
c879973
Fixed prometheus documentation and running scripts
Heaven2024 Aug 26, 2024
e1916f8
v1
Heaven2024 Sep 29, 2024
b980723
Feature: Add Prometheus pull mode authentication.
leolin49 Jul 19, 2024
7f42fbd
Merge branch 'prometheus' into branch_prometheus_basic
leolin49 Oct 5, 2024
cd24612
Merge pull request #1 from leolin49/branch_prometheus_basic
Heaven2024 Oct 7, 2024
816bc28
fixed
Heaven2024 Oct 8, 2024
3d907d6
Fixed: Prometheus pull mode authentication.
leolin49 Oct 12, 2024
2309769
Fixed: Prometheus pull mode authentication.
leolin49 Oct 16, 2024
1a5bb30
Fixed: Prometheus pull mode authentication.
leolin49 Oct 16, 2024
8cb45d4
Fixed: Prometheus pull mode authentication.
leolin49 Oct 26, 2024
a931cfc
Fixed: Prometheus pull mode authentication.
leolin49 Nov 26, 2024
3a9fe81
Fixed: Prometheus push mode authentication.
leolin49 Nov 26, 2024
35ef136
Fixed: Prometheus authentication clang-format.
leolin49 Nov 26, 2024
f87a954
Fixed: Prometheus pull mode authentication empty auth config.
leolin49 Nov 27, 2024
973bf4b
Update prometheus_metrics.md
leolin49 Nov 27, 2024
18dc6d7
Update prometheus_metrics.md
leolin49 Nov 27, 2024
919b8b3
Update prometheus_metrics.md
leolin49 Nov 27, 2024
c986e4f
Prometheus authentication format.
leolin49 Nov 28, 2024
12afca9
Merge branch 'prometheus' of https://github.com/Heaven2024/trpc-cpp i…
leolin49 Nov 28, 2024
16b5b8c
Update LICENSE: Add 'jwt-cpp' LICENSE
leolin49 Dec 4, 2024
078f31d
Update prometheus_metrics.md
leolin49 Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build --copt=-O2
#build --copt=-g --strip=never
build --jobs 16
#test --cache_test_results=no --test_output=errors

build --define trpc_include_prometheus=true
Copy link
Contributor

Choose a reason for hiding this comment

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

默认关闭prometheus,这行可以删掉

7 changes: 4 additions & 3 deletions docs/zh/prometheus_metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ client:
| aApp | 主调app名 |
| aServer | 主调server名 |
| aService | 主调service名 |
| aIp | 主调ip地址 |
| pApp | 被调app名 |
| pServer | 被调server名 |
| pService | 被调service名 |
Expand All @@ -109,6 +110,7 @@ client:
| frame_ret_code | 调用的框架错误码 |
| interface_ret_code | 调用的接口错误码 |


### 被调监控上报

只需在框架配置文件的 `server` 中加上 `prometheus` 拦截器,即可开启被调监控:
Expand All @@ -124,7 +126,6 @@ server:

统计数据:

```mermaid
| 监控名 | 监控类型 | 说明 |
| ------ | ------ | ------ |
| rpc_server_counter_metric | Counter | 服务端收到的请求总次数 |
Expand All @@ -149,7 +150,7 @@ server:
| pConSetId | 被调所属set |
| frame_ret_code | 调用的框架错误码 |
| interface_ret_code | 调用的接口错误码 |
```


## 属性监控上报

Expand Down Expand Up @@ -314,7 +315,7 @@ single_metrics_info.single_attr_info.value = 1;

#### 通用多维属性上报

Prometheus 监控插件支持框架通用的多维属性上报方式,即通过构造 `::trpc::TrpcMultiAttrMetricsInfo` 然后使用`::trpc::metrics::MultiAttrReport`接口来上报。**Prometheus 的单维属性上报是指上报统计标签包含多个键值对的数据。**。
Prometheus 监控插件支持框架通用的多维属性上报方式,即通过构造 `::trpc::TrpcMultiAttrMetricsInfo` 然后使用`::trpc::metrics::MultiAttrReport`接口来上报。**Prometheus 的多维属性上报是指上报统计标签包含多个键值对的数据。**。

设置 `::trpc::TrpcMultiAttrMetricsInfo` 值需要注意:

Expand Down
10 changes: 10 additions & 0 deletions examples/features/prometheus/proxy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ cc_library(
"@trpc_cpp//trpc/metrics/prometheus:prometheus_metrics_api",
],
)

cc_binary(
Copy link
Contributor

Choose a reason for hiding this comment

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

不需要push这个文件,去掉与之相关的编译引入

name = "push",
srcs = ["push.cc"],
deps = [
"@trpc_cpp//trpc/metrics/prometheus:prometheus_metrics_api",
"@trpc_cpp//trpc/log:trpc_log",

],
)
6 changes: 6 additions & 0 deletions examples/features/prometheus/proxy/forward_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ ::trpc::Status ForwardServiceImpl::Route(::trpc::ServerContextPtr context,
"counter_name", "counter_desc", {{"const_counter_key", "const_counter_value"}});
::prometheus::Counter& counter = counter_family->Add({{"counter_key", "counter_value"}});
counter.Increment(random_num);

if (::trpc::prometheus::PushMetricsInfo()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥这里还需要手动调用呢?不能配置一下yaml文件就生效吗?

TRPC_FMT_INFO("Successfully pushed metrics to Pushgateway");
} else {
TRPC_FMT_ERROR("Failed to push metrics to Pushgateway");
}
#endif

auto client_context = ::trpc::MakeClientContext(context, greeter_proxy_);
Expand Down
22 changes: 22 additions & 0 deletions examples/features/prometheus/proxy/push.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <chrono>
Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件和框架无关,没必要增加,用法放在文档就好了

#include <thread>
#include "trpc/metrics/prometheus/prometheus_metrics_api.h"
#include "trpc/log/trpc_log.h"



int main(int argc, char** argv) {

while (true) {
if (::trpc::prometheus::PushMetricsInfo())
{
std::cout << "Successfully pushed metrics to Pushgateway" << std::endl;
} else {
std::cerr << "Failed to push metrics to Pushgateway" << std::endl;
}

std::this_thread::sleep_for(std::chrono::seconds(5)); // 每60秒推送一次
}

return 0;
}
5 changes: 5 additions & 0 deletions examples/features/prometheus/proxy/trpc_cpp_fiber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ plugins:
const_labels:
const_key1: const_value1
const_key2: const_value2
push_mode:
Copy link
Contributor

Choose a reason for hiding this comment

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

例子需要演示pull模式和push模式,应该给出2个文件配置

enabled: true
gateway_url: "http://pushgateway:9091"
job_name: "test_job"
push_interval_seconds: 2
log:
default:
- name: default
Expand Down
2 changes: 1 addition & 1 deletion examples/features/prometheus/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ echo "begin"
sleep 1
./bazel-bin/examples/features/prometheus/proxy/forward_server --config=examples/features/prometheus/proxy/trpc_cpp_fiber.yaml &
sleep 1
./bazel-bin/examples/features/prometheus/client/client_config --config=examples/features/prometheus/client/trpc_cpp_fiber.yaml
./bazel-bin/examples/features/prometheus/client/client --client_config=examples/features/prometheus/client/trpc_cpp_fiber.yaml

killall helloworld_svr
if [ $? -ne 0 ]; then
Expand Down
6 changes: 6 additions & 0 deletions trpc/admin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,19 @@ cc_library(
":admin_handler",
":base_funcs",
"//trpc/util:prometheus",
"//trpc/common/config:trpc_config",
"//trpc/log:trpc_log",
"//trpc/util/http:base64",
"//trpc/util/string:string_helper",
] + select({
"//conditions:default": [],
"//trpc:trpc_include_prometheus": [
"@com_github_jupp0r_prometheus_cpp//pull",
"//trpc/metrics/prometheus:prometheus_metrics",
],
"//trpc:include_metrics_prometheus": [
"@com_github_jupp0r_prometheus_cpp//pull",
"//trpc/metrics/prometheus:prometheus_metrics",
],
}),
)
Expand Down
58 changes: 57 additions & 1 deletion trpc/admin/prometheus_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,68 @@

namespace trpc::admin {

PrometheusHandler::PrometheusHandler() { description_ = "[GET /metrics] get prometheus metrics"; }
PrometheusHandler::PrometheusHandler() {
description_ = "[GET /metrics] get prometheus metrics";
bool ret = TrpcConfig::GetInstance()->GetPluginConfig<PrometheusConfig>(
"metrics", trpc::prometheus::kPrometheusMetricsName, prometheus_conf_);
if (!ret) {
TRPC_LOG_WARN(
"Failed to obtain Prometheus plugin configuration from the framework configuration file. Default configuration "
"will be used.");
}
Init();
Copy link
Contributor

Choose a reason for hiding this comment

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

构造函数别执行太复杂的事情,Init不能放在外面执行吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。

}

void PrometheusHandler::Init() {
auto& cfg = prometheus_conf_.auth_cfg;
if (cfg.count("username") && cfg.count("password")) {
auth_conf_.username = cfg["username"];
auth_conf_.password = cfg["password"];
} else {
TRPC_LOG_INFO("can not found prometheus auth config");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

构造函数做了太复杂的事情,可以定义一个Init函数,把这部分逻辑放在Init函数里

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。

}

void PrometheusHandler::CommandHandle(http::HttpRequestPtr req, rapidjson::Value& result,
rapidjson::Document::AllocatorType& alloc) {
static std::unique_ptr<::prometheus::Serializer> serializer = std::make_unique<::prometheus::TextSerializer>();

if (auth_conf_.username.size() && auth_conf_.password.size()) {
std::string token = req->GetHeader("Authorization");
Copy link
Contributor

Choose a reason for hiding this comment

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

这块逻辑有啥用?看起来只是判断用户名和密码是否匹配,判断之后有啥用?

Copy link
Contributor

Choose a reason for hiding this comment

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

只有用户名密码都正确的情况下,才会返回metric数据,否则拒绝请求。

Copy link
Contributor

@weimch weimch Oct 15, 2024

Choose a reason for hiding this comment

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

用户名和密码,在prometheus的gateway服务哪里能配置呢?文档有给出吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

想起来了,这是pull模式的,那用户名和密码在prometheus服务器里哪里能配置呢?

Copy link
Contributor

Choose a reason for hiding this comment

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

文档我还没有写,确认一下,Prometheus鉴权相关的使用方法是直接添加在prometheus_metrics.md吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

可以的

auto splited = Split(token, ' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

鉴权部分单独提出一个类私有成员接口

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。

if (splited.size() != 2) {
result.AddMember("message", "wrong request without authorization", alloc);
TRPC_LOG_INFO("error token: " << token);
return;
}
if (splited[0] != "Basic") {
result.AddMember("message", "wrong request without right auth", alloc);
TRPC_LOG_INFO("error token: " << token);
return;
}

std::string username_pwd = http::Base64Decode(std::begin(splited[1]), std::end(splited[1]));
auto sp = Split(username_pwd, ':');
if (sp.size() != 2) {
result.AddMember("message", "wrong request without authorization", alloc);
TRPC_LOG_INFO("error token: " << token);
Copy link
Contributor

Choose a reason for hiding this comment

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

使用错误日志宏 TRPC_FMT_ERROR

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。

return;
weimch marked this conversation as resolved.
Show resolved Hide resolved
}

auto username = sp[0];
if (username != auth_conf_.username) {
Copy link
Contributor

Choose a reason for hiding this comment

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

用户名和密码应该一起判断,如果不对,统一返回 wrong username or password 的信息,现在这种实现,攻击者能猜对用户名

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。

result.AddMember("message", "wrong request without right username", alloc);
TRPC_LOG_INFO("error username: " << username << ",right username: " << auth_conf_.username);
return;
}
auto pwd = sp[1];
if (pwd != auth_conf_.password) {
result.AddMember("message", "wrong request without right password", alloc);
TRPC_LOG_INFO("error password: " << pwd << ",right password: " << auth_conf_.password);
return;
}
}

std::string prometheus_str = serializer->Serialize(trpc::prometheus::Collect());
result.AddMember(rapidjson::StringRef("trpc-html"), rapidjson::Value(prometheus_str, alloc).Move(), alloc);
}
Expand Down
15 changes: 15 additions & 0 deletions trpc/admin/prometheus_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

#include "trpc/admin/admin_handler.h"
#include "trpc/util/prometheus.h"
#include "trpc/util/http/base64.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

用clang-format格式化一下,头文件顺序需要按照字母序顺序排列

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。

#include "trpc/util/string/string_helper.h"
#include "trpc/util/time.h"
#include "trpc/log/trpc_log.h"
#include "trpc/metrics/prometheus/prometheus_metrics.h"
#include "trpc/common/config/trpc_config.h"

namespace trpc::admin {

Expand All @@ -26,6 +32,15 @@ class PrometheusHandler : public AdminHandlerBase {

void CommandHandle(http::HttpRequestPtr req, rapidjson::Value& result,
rapidjson::Document::AllocatorType& alloc) override;
private:
void Init();

PrometheusConfig prometheus_conf_;
Copy link
Contributor

Choose a reason for hiding this comment

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

还是不理解鉴权相关的参数放admin服务的意图,可以描述下

Copy link
Contributor

Choose a reason for hiding this comment

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

因为Prometheus拉取数据是要走admin服务的,我感觉只有在这里才能拿到http包头中的用户名密码信息,才能进行鉴权。

Copy link
Contributor

Choose a reason for hiding this comment

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

看实现,只需要填充username和password就好了吧?不需要保留prometheus_conf_,只需要填充CommandHandle里的username和password字段

Copy link
Contributor

Choose a reason for hiding this comment

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

已修改。


struct AuthConf {
std::string username;
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥不使用token的方式来鉴权呢?

Copy link
Contributor

@leolin49 leolin49 Oct 16, 2024

Choose a reason for hiding this comment

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

是可以使用token,一开始的实现也是token,但是我查了资料,pushgateway没办法用token来鉴权。所以如果pull模式用token的话,就相当于是两套鉴权模式了。

Copy link
Contributor

Choose a reason for hiding this comment

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

push和pull确实是两套鉴权模式吧,配置区分开就好

Copy link
Contributor

@leolin49 leolin49 Oct 27, 2024

Choose a reason for hiding this comment

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

实现了一版两套鉴权模式的,但是发现Prometheus配置最多只能同时存在一种鉴权机制(否则Prometheus服务器会启动不了),所以应该只能按照现在这样pull和push都通过一套机制鉴权。

Copy link
Contributor

Choose a reason for hiding this comment

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

没懂你意思,我的意思是,这里并不要求push和pull功能同时启用,一个server在prometheus的push或pull两种模式选择一个,他能在选择的模式下进行鉴权。如果选择push模式,则用push模式鉴权的配置,如果选择pull模式,则用pull模式鉴权的配置。

你可以举个例子来说明你得意思

Copy link
Contributor

Choose a reason for hiding this comment

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

意思是prometheus插件不会同时使用pull和push模式吗?如果需要同时使用pull和push,那么就只能统一通过账号密码的方式;否则就是如果一个server使用pull模式,那prometheus服务器的配置就是配置token,如果这个server切换成push模式,那prometheus服务器配置也要手动修改为用户名密码。

Copy link
Contributor

Choose a reason for hiding this comment

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

对的,不会同时使用pull和push,一般这种切换是架构层面的事情,改动配置没什么问题

std::string password;
} auth_conf_;
};

} // namespace trpc::admin
Expand Down
2 changes: 1 addition & 1 deletion trpc/common/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Plugin : public RefCounted<Plugin> {

/// @brief Stop the runtime environment of the plugin
virtual void Stop() noexcept {}

Copy link
Contributor

Choose a reason for hiding this comment

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

记得用clang-format把所有代码文件都格式化一遍(使用项目根目录的.clang-format配置的格式化规范)

Copy link
Contributor

Choose a reason for hiding this comment

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

这里出现了不必要的空格

/// @brief destroy plugin internal resources
virtual void Destroy() noexcept {}

Expand Down
15 changes: 15 additions & 0 deletions trpc/metrics/prometheus/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ filegroup(
]),
)

cc_library(
name = "prometheus_pusher",
srcs = ["prometheus_pusher.cc"],
hdrs = ["prometheus_pusher.h"],
deps = [
"//trpc/util/log:logging",
"@com_github_jupp0r_prometheus_cpp//push",
],
)

cc_library(
name = "prometheus_conf",
srcs = ["prometheus_conf.cc"],
Expand Down Expand Up @@ -73,15 +83,20 @@ cc_library(
":prometheus_conf",
":prometheus_conf_parser",
"//trpc/util:prometheus",
"@com_github_jupp0r_prometheus_cpp//core",

Copy link
Contributor

Choose a reason for hiding this comment

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

不必要的换行,BUILD文件使用 buildifier 格式化一下

"//trpc/common/config:trpc_config",
":prometheus_pusher",
"//trpc/metrics",
] + select({
"//conditions:default": [],
"//trpc:trpc_include_prometheus": [
"@com_github_jupp0r_prometheus_cpp//pull",
"@com_github_jupp0r_prometheus_cpp//push",
],
"//trpc:include_metrics_prometheus": [
"@com_github_jupp0r_prometheus_cpp//pull",
"@com_github_jupp0r_prometheus_cpp//push",
],
}),
)
Expand Down
45 changes: 45 additions & 0 deletions trpc/metrics/prometheus/prometheus_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,52 @@ void PrometheusConfig::Display() const {
TRPC_LOG_DEBUG(label.first << ":" << label.second);
}

TRPC_LOG_DEBUG("auth_cfg:");
for (auto label : auth_cfg) {
TRPC_LOG_DEBUG(label.first << ":" << label.second);
}

TRPC_LOG_DEBUG("--------------------------------");
}

} // namespace trpc

namespace YAML {

YAML::Node convert<trpc::PrometheusConfig>::encode(const trpc::PrometheusConfig& config) {
YAML::Node node;
node["histogram_module_cfg"] = config.histogram_module_cfg;
node["const_labels"] = config.const_labels;
node["auth_cfg"] = config.auth_cfg;
node["push_mode"]["enabled"] = config.push_mode.enabled;
if (config.push_mode.enabled) {
node["push_mode"]["gateway_url"] = config.push_mode.gateway_url;
node["push_mode"]["job_name"] = config.push_mode.job_name;
node["push_mode"]["push_interval_seconds"] = config.push_mode.push_interval_seconds;
}
return node;
}

bool convert<trpc::PrometheusConfig>::decode(const YAML::Node& node, trpc::PrometheusConfig& config) {
if (node["histogram_module_cfg"]) {
config.histogram_module_cfg = node["histogram_module_cfg"].as<std::vector<double>>();
}
if (node["const_labels"]) {
config.const_labels = node["const_labels"].as<std::map<std::string, std::string>>();
}
if (node["auth_cfg"]) {
config.auth_cfg = node["auth_cfg"].as<std::map<std::string, std::string>>();
}
if (node["push_mode"]) {
const auto& push_mode = node["push_mode"];
config.push_mode.enabled = push_mode["enabled"].as<bool>(false);
if (config.push_mode.enabled) {
config.push_mode.gateway_url = push_mode["gateway_url"].as<std::string>();
config.push_mode.job_name = push_mode["job_name"].as<std::string>();
config.push_mode.push_interval_seconds = push_mode["push_interval_seconds"].as<int>(15);
}
}
return true;
}

} // namespace YAML
19 changes: 19 additions & 0 deletions trpc/metrics/prometheus/prometheus_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,26 @@ struct PrometheusConfig {
/// The default label attached to each RPC metrics data
std::map<std::string, std::string> const_labels;

std::map<std::string, std::string> auth_cfg;

struct PushMode {
bool enabled = false;
std::string gateway_url;
std::string job_name;
weimch marked this conversation as resolved.
Show resolved Hide resolved
int push_interval_seconds = 15;
weimch marked this conversation as resolved.
Show resolved Hide resolved
} push_mode;

void Display() const;
};

} // namespace trpc

namespace YAML {

template <>
struct convert<trpc::PrometheusConfig> {
static YAML::Node encode(const trpc::PrometheusConfig& config);
static bool decode(const YAML::Node& node, trpc::PrometheusConfig& config);
};

} // namespace YAML
5 changes: 5 additions & 0 deletions trpc/metrics/prometheus/prometheus_conf_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct convert<trpc::PrometheusConfig> {
YAML::Node node;
node["histogram_module_cfg"] = conf.histogram_module_cfg;
node["const_labels"] = conf.const_labels;
node["auth_cfg"] = conf.auth_cfg;

return node;
}
Expand All @@ -37,6 +38,10 @@ struct convert<trpc::PrometheusConfig> {
if (node["const_labels"]) {
conf.const_labels = node["const_labels"].as<std::map<std::string, std::string>>();
}

if (node["auth_cfg"]) {
conf.auth_cfg = node["auth_cfg"].as<std::map<std::string, std::string>>();
}
return true;
}
};
Expand Down
Loading
Loading