Skip to content

Commit 640f455

Browse files
authored
Feature: Optimize local framework logging output (#62)
1 parent cbf6fbb commit 640f455

26 files changed

Lines changed: 1264 additions & 77 deletions

.github/.codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ coverage:
77
status:
88
project:
99
default:
10+
informational: true
1011
threshold: 1%
12+
patch:
13+
false

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ English | [中文](README.zh_CN.md)
5656
* [custom metrics plugin](./en/custom_metrics.md)
5757
* [prometheus](./en/prometheus_metrics.md)
5858
* Logging
59+
* [local logging tools](./en/local_logging.md)
5960
* [custom logging plugin](./en/custom_logging.md)
6061
* [cls](https://github.com/trpc-ecosystem/cpp-logging-cls/blob/main/README.md)
6162
* Tracing

docs/README.zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
* [开发自定义metrics插件](./zh/custom_metrics.md)
5656
* [prometheus](./zh/prometheus_metrics.md)
5757
* Logging插件
58+
* [本地日志工具](./zh/local_logging.md)
5859
* [开发自定义logging插件](./zh/custom_logging.md)
5960
* [cls](https://github.com/trpc-ecosystem/cpp-logging-cls/blob/main/README.zh_CN.md)
6061
* Tracing插件

docs/en/local_logging.md

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.

docs/en/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can use it:
2525

2626
Conventional framework performance test data is only performance data in relatively simple scenarios, and does not represent good performance in real and different business scenarios. Considering that Tencent has many different business scenarios, the requirements for framework performance are also different, for example:
2727

28-
- business accesses gateway scenarios: the feature is that the business logic is light, hign qps, large number of connections (long/short connections), heavy network io operations, and asynchronous programming is often used for programming;
28+
- business accesses gateway scenarios: the feature is that the business logic is light, high qps, large number of connections (long/short connections), heavy network io operations, and asynchronous programming is often used for programming;
2929
- recommendation/search scenarios: the feature is that the business logic is heavy, the qps is not large, each request needs to be calculated in parallel, pay attention to the long tail delay, and the programming often use synchronous programming;
3030
- game business scenarios: the feature is that logic very complex and has stateful, large qps, single-threaded programming, and use synchronous programming;
3131
- storage scenarios: the feature is that the business logic is light, large qps, low latency requirement, heavy network io and disk io operations, and asynchronous programming is often used for programming;

docs/images/log_design.png

267 KB
Loading

docs/zh/local_logging.md

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.

trpc/config/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,13 @@ cc_test(
136136
"@com_google_googletest//:gtest_main",
137137
],
138138
)
139+
140+
cc_test(
141+
name = "config_test",
142+
srcs = ["config_test.cc"],
143+
deps = [
144+
"//trpc/config/testing:mock_config",
145+
"@com_google_googletest//:gtest",
146+
"@com_google_googletest//:gtest_main",
147+
],
148+
)

trpc/config/config.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace trpc {
2323

2424
/// @brief The tRPC Config plugin abstract interface definition class, targeting plugin developers.
25-
/// @note This class is reserved for 1.0 compatibility, and new data sources (rainbow, etcd, local cache)
25+
/// @note This class is reserved for 1.0 compatibility, and new data sources
2626
/// should inherit provider_base.h directly.
2727
class Config : public Plugin {
2828
public:
@@ -31,15 +31,15 @@ class Config : public Plugin {
3131
~Config() override = default;
3232

3333
/// @brief Pulls file configuration.
34-
/// @param config_name - For tconf, pass in the configuration file name; for rainbow, pass in the group_name.
34+
/// @param config_name - The Group name.
3535
/// @param config - The content of the obtained configuration.
36-
/// @param params - For tconf, this parameter is not required; for rainbow, pass in the file name.
36+
/// @param params - File name.
3737
/// @return - true: Loading successful.
3838
/// false: Loading failed.
3939
virtual bool PullFileConfig(const std::string& config_name, std::string* config, const std::any& params) = 0;
4040

4141
/// @brief Pulls a single key-value configuration.
42-
/// @param config_name - The filename of the KV configuration to be loaded, for rainbow pass in the group.
42+
/// @param config_name - The filename of the KV configuration to be loaded, means group.
4343
/// @param key - Input key.
4444
/// @param config - Obtains the value corresponding to the key.
4545
/// @return - true: Loading successful.
@@ -48,7 +48,7 @@ class Config : public Plugin {
4848
const std::any& params) = 0;
4949

5050
/// @brief Pulls multiple key-value configurations.
51-
/// @param config_name - The filename of the KV configuration to be loaded, for rainbow pass in the group.
51+
/// @param config_name - The filename of the KV configuration to be loaded, means group.
5252
/// @param config - Obtains key-value pairs.
5353
/// @return - true: Loading successful.
5454
/// false: Loading failed.

trpc/config/config_test.cc

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
//
3+
// Tencent is pleased to support the open source community by making tRPC available.
4+
//
5+
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
6+
// All rights reserved.
7+
//
8+
// If you have downloaded a copy of the tRPC source code from Tencent,
9+
// please note that tRPC source code is licensed under the Apache 2.0 License,
10+
// A copy of the Apache 2.0 License is included in this file.
11+
//
12+
//
13+
14+
#include <any>
15+
#include <map>
16+
#include <string>
17+
18+
#include "gtest/gtest.h"
19+
#include "gmock/gmock.h"
20+
#include "trpc/config/testing/mock_config.h"
21+
22+
namespace trpc::testing {
23+
24+
class AnyEqMatcher : public ::testing::MatcherInterface<const std::any&> {
25+
public:
26+
explicit AnyEqMatcher(const std::any& expected) : expected_(expected) {}
27+
28+
bool MatchAndExplain(const std::any& actual, ::testing::MatchResultListener* listener) const override {
29+
if (!actual.has_value() && !expected_.has_value()) {
30+
return true;
31+
}
32+
33+
if (actual.type() != expected_.type()) {
34+
return false;
35+
}
36+
37+
if (actual.type() == typeid(int)) {
38+
return std::any_cast<int>(actual) == std::any_cast<int>(expected_);
39+
} else if (actual.type() == typeid(std::string)) {
40+
return std::any_cast<std::string>(actual) == std::any_cast<std::string>(expected_);
41+
}
42+
43+
return false;
44+
}
45+
46+
void DescribeTo(::std::ostream* os) const override {
47+
*os << "is equal to the expected value";
48+
}
49+
50+
void DescribeNegationTo(::std::ostream* os) const override {
51+
*os << "is not equal to the expected value";
52+
}
53+
54+
private:
55+
const std::any expected_;
56+
};
57+
58+
inline ::testing::Matcher<const std::any&> AnyEq(const std::any& expected) {
59+
return ::testing::MakeMatcher(new AnyEqMatcher(expected));
60+
}
61+
62+
class TestConfig : public ::testing::Test {
63+
protected:
64+
void SetUp() override {
65+
mock_config_ = MakeRefCounted<MockConfig>();
66+
ASSERT_TRUE(mock_config_ != nullptr);
67+
}
68+
69+
RefPtr<MockConfig> mock_config_;
70+
};
71+
72+
TEST_F(TestConfig, PullFileConfig) {
73+
std::string config_name = "test_config";
74+
std::string config;
75+
std::any params;
76+
EXPECT_CALL(*mock_config_, PullFileConfig(config_name, &config, AnyEq(params)))
77+
.WillOnce(::testing::Return(true));
78+
bool result = mock_config_->PullFileConfig(config_name, &config, params);
79+
80+
ASSERT_TRUE(result);
81+
}
82+
83+
TEST_F(TestConfig, PullKVConfig) {
84+
std::string config_name = "test_config";
85+
std::string key = "test_key";
86+
std::string config;
87+
std::any params;
88+
EXPECT_CALL(*mock_config_, PullKVConfig(config_name, key, &config, AnyEq(params)))
89+
.WillOnce(::testing::Return(true));
90+
bool result = mock_config_->PullKVConfig(config_name, key, &config, params);
91+
92+
ASSERT_TRUE(result);
93+
}
94+
95+
TEST_F(TestConfig, PullMultiKVConfig) {
96+
std::string config_name = "test_config";
97+
std::map<std::string, std::string> config;
98+
std::any params;
99+
EXPECT_CALL(*mock_config_, PullMultiKVConfig(config_name, &config, AnyEq(params)))
100+
.WillOnce(::testing::Return(true));
101+
bool result = mock_config_->PullMultiKVConfig(config_name, &config, params);
102+
103+
ASSERT_TRUE(result);
104+
}
105+
106+
} // namespace trpc::testing

0 commit comments

Comments
 (0)