Skip to content

Commit fc5f111

Browse files
committed
curvefs/client: add base module.
Signed-off-by: Wine93 <[email protected]>
1 parent 1205fd6 commit fc5f111

File tree

11 files changed

+279
-0
lines changed

11 files changed

+279
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curve
19+
* Created Date: 2023-11-20
20+
* Author: Jingli Chen (Wine93)
21+
*/
22+
23+
namespace curvefs {
24+
namespace client {
25+
namespace base {
26+
27+
} // namespace base
28+
} // namespace client
29+
} // namespace curvefs
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curve
19+
* Created Date: 2023-11-20
20+
* Author: Jingli Chen (Wine93)
21+
*/
22+
23+
// 配置管理器:
24+
// (1) 动态配置需要支持所有配置项,足够灵活
25+
// (2) 目前该模块主要用来控制日志采集器
26+
27+
#ifndef CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_
28+
#define CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_
29+
30+
namespace curvefs {
31+
namespace client {
32+
namespace base {
33+
34+
} // namespace base
35+
} // namespace client
36+
} // namespace curvefs
37+
38+
#endif // CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_
File renamed without changes.

curvefs/src/client/base/log_sender.cpp

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curve
19+
* Created Date: 2023-11-20
20+
* Author: Jingli Chen (Wine93)
21+
*/
22+
23+
// 日志的采集器:
24+
// (1) 需要支持 buffer
25+
// (2) 配置可以指定多个后端地址,采用轮询进行负载
26+
// (3) 并且发送需要有 retry 机制
27+
// (4) 需要采集比例的可配置,如 4/100、100/100
28+
// (5) 由于采集器的逻辑经常变更,可以考虑以插件的形式实现,以 so 加载或者 lua
29+
// (6) 需要和 access log 和 perf_context 结合起来,日志要同时发送到文件与 TCP
30+
// 实现不允许有冗余代码, 所以 log 的输出逻辑需要足够灵活,考虑采用 multi-sender
31+
32+
#ifndef CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_
33+
#define CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_
34+
35+
namespace curvefs {
36+
namespace client {
37+
namespace base {
38+
39+
} // namespace base
40+
} // namespace client
41+
} // namespace curvefs
42+
43+
#endif // CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_

curvefs/src/client/base/metric.h

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curve
19+
* Created Date: 2023-11-20
20+
* Author: Jingli Chen (Wine93)
21+
*/
22+
23+
#ifndef CURVEFS_SRC_CLIENT_BASE_METRIC_H_
24+
#define CURVEFS_SRC_CLIENT_BASE_METRIC_H_
25+
26+
#include <string>
27+
28+
#include "curvefs/src/common/metric_utils.h"
29+
30+
namespace curvefs {
31+
namespace client {
32+
namespace base {
33+
34+
#define DEFINE_METRICS(seq) END(A seq)
35+
#define BODY(x) OpMetric x = OpMetric(#x);
36+
#define A(x) BODY(x) B
37+
#define B(x) BODY(x) A
38+
#define A_END
39+
#define B_END
40+
#define END(...) END_(__VA_ARGS__)
41+
#define END_(...) __VA_ARGS__##_END
42+
43+
struct OpMetric {
44+
static const std::string prefix = "fuse_ll_"
45+
46+
explicit OpMetric(const std::string& name)
47+
ninflight(prefix, name + "_ninflight"),
48+
nerror(prefix, name + "_nerror"),
49+
latency(prefix, name + "_latency") {}
50+
51+
bvar::Adder<int64_t> ninflight;
52+
bvar::Adder<uint64_t> nerror;
53+
bvar::LatencyRecorder latency;
54+
};
55+
56+
// OpMetric lookup = OpMetric("lookup");
57+
// OpMetric getattr = OpMetric("getattr");
58+
// ...
59+
struct FuseLLOpMetric {
60+
DEFINE_METRICS(
61+
(lookup)
62+
(getattr)
63+
(setattr)
64+
(readlink)
65+
(mknod)
66+
(mkdir)
67+
(unlink)
68+
(rmdir)
69+
(symlink)
70+
(rename)
71+
(link)
72+
(open)
73+
(read)
74+
(write)
75+
(flush)
76+
(release)
77+
(fsync)
78+
(opendir)
79+
(readdir)
80+
(readdirplus)
81+
(releasedir)
82+
(statfs)
83+
(setxattr)
84+
(getxattr)
85+
(listxattr)
86+
(create)
87+
(bmap)
88+
)
89+
90+
FuseLLOpMetric GetInstance() {
91+
static FuseLLOpMetric instance;
92+
return instance;
93+
}
94+
};
95+
96+
struct CodeGuard {
97+
CodeGuard(bvar::Adder<uint64_t>* nerror, CURVEFS_ERROR* code)
98+
: nerror(nerror), code(code) {}
99+
100+
~CodeGuard() {
101+
if (*code != CURVEFS_ERROR::OK) {
102+
(*nerror) << 1;
103+
}
104+
}
105+
106+
bvar::Adder<uint64_t>* nerror;
107+
CURVEFS_ERROR* code;
108+
};
109+
110+
struct MetricGuards {
111+
explicit MetricGuards(OpMetric* metric, CURVEFS_ERROR* code)
112+
: iGuard(&metric->ninflight),
113+
cGuard(&metric->nerror, code),
114+
lGuard(&metric->latency) {}
115+
116+
~MetricGuards() = default;
117+
118+
InflightGuard iGuard;
119+
CodeGuard cGuard;
120+
LatencyUpdater lGuard;
121+
};
122+
123+
// NOTE: param rc is implicit
124+
#define MetricGuard(OP) MetricGuards(&FuseLLOpMetric::GetInstance().OP, &rc);
125+
126+
} // namespace base
127+
} // namespace client
128+
} // namespace curvefs
129+
130+
#endif // CURVEFS_SRC_CLIENT_BASE_METRIC_H_

curvefs/src/client/base/perf_context.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)