diff --git a/curvefs/src/client/logger/BUILD b/curvefs/src/client/base/BUILD similarity index 100% rename from curvefs/src/client/logger/BUILD rename to curvefs/src/client/base/BUILD diff --git a/curvefs/src/client/logger/access_log.cpp b/curvefs/src/client/base/access_log.cpp similarity index 100% rename from curvefs/src/client/logger/access_log.cpp rename to curvefs/src/client/base/access_log.cpp diff --git a/curvefs/src/client/logger/access_log.h b/curvefs/src/client/base/access_log.h similarity index 100% rename from curvefs/src/client/logger/access_log.h rename to curvefs/src/client/base/access_log.h diff --git a/curvefs/src/client/base/configure.cpp b/curvefs/src/client/base/configure.cpp new file mode 100644 index 0000000000..4cc7e0e6ed --- /dev/null +++ b/curvefs/src/client/base/configure.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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: Curve + * Created Date: 2023-11-20 + * Author: Jingli Chen (Wine93) + */ + +namespace curvefs { +namespace client { +namespace base { + +} // namespace base +} // namespace client +} // namespace curvefs diff --git a/curvefs/src/client/base/configure.h b/curvefs/src/client/base/configure.h new file mode 100644 index 0000000000..a5cda1aefb --- /dev/null +++ b/curvefs/src/client/base/configure.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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: Curve + * Created Date: 2023-11-20 + * Author: Jingli Chen (Wine93) + */ + +// 配置管理器: +// (1) 动态配置需要支持所有配置项,足够灵活 +// (2) 目前该模块主要用来控制日志采集器 + +#ifndef CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_ +#define CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_ + +namespace curvefs { +namespace client { +namespace base { + +} // namespace base +} // namespace client +} // namespace curvefs + +#endif // CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_ diff --git a/curvefs/src/client/logger/error_log.h b/curvefs/src/client/base/error_log.h similarity index 100% rename from curvefs/src/client/logger/error_log.h rename to curvefs/src/client/base/error_log.h diff --git a/curvefs/src/client/base/log_sender.cpp b/curvefs/src/client/base/log_sender.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/curvefs/src/client/base/log_sender.h b/curvefs/src/client/base/log_sender.h new file mode 100644 index 0000000000..4c429df1b8 --- /dev/null +++ b/curvefs/src/client/base/log_sender.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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: Curve + * Created Date: 2023-11-20 + * Author: Jingli Chen (Wine93) + */ + +// 日志的采集器: +// (1) 需要支持 buffer +// (2) 配置可以指定多个后端地址,采用轮询进行负载 +// (3) 并且发送需要有 retry 机制 +// (4) 需要采集比例的可配置,如 4/100、100/100 +// (5) 由于采集器的逻辑经常变更,可以考虑以插件的形式实现,以 so 加载或者 lua + +#ifndef CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_ +#define CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_ + +namespace curvefs { +namespace client { +namespace base { + +} // namespace base +} // namespace client +} // namespace curvefs + +#endif // CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_ diff --git a/curvefs/src/client/base/metric.h b/curvefs/src/client/base/metric.h new file mode 100644 index 0000000000..3f821ec2a0 --- /dev/null +++ b/curvefs/src/client/base/metric.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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: Curve + * Created Date: 2023-11-20 + * Author: Jingli Chen (Wine93) + */ + +#ifndef CURVEFS_SRC_CLIENT_BASE_METRIC_H_ +#define CURVEFS_SRC_CLIENT_BASE_METRIC_H_ + +#include + +#include "curvefs/src/common/metric_utils.h" + +namespace curvefs { +namespace client { +namespace base { + +#define DEFINE_METRICS(seq) END(A seq) +#define BODY(x) OpMetric x = OpMetric(#x); +#define A(x) BODY(x) B +#define B(x) BODY(x) A +#define A_END +#define B_END +#define END(...) END_(__VA_ARGS__) +#define END_(...) __VA_ARGS__##_END + +struct OpMetric { + static const std::string prefix = "fuse_ll_" + + explicit OpMetric(const std::string& name) + ninflight(prefix, name + "_ninflight"), + nerror(prefix, name + "_nerror"), + latency(prefix, name + "_latency") {} + + bvar::Adder ninflight; + bvar::Adder nerror; + bvar::LatencyRecorder latency; +}; + +// OpMetric lookup = OpMetric("lookup"); +// OpMetric getattr = OpMetric("getattr"); +// ... +struct FuseLLOpMetric { + DEFINE_METRICS( + (lookup) + (getattr) + (setattr) + (readlink) + (mknod) + (mkdir) + (unlink) + (rmdir) + (symlink) + (rename) + (link) + (open) + (read) + (write) + (flush) + (release) + (fsync) + (opendir) + (readdir) + (readdirplus) + (releasedir) + (statfs) + (setxattr) + (getxattr) + (listxattr) + (create) + (bmap) + ) + + FuseLLOpMetric GetInstance() { + static FuseLLOpMetric instance; + return instance; + } +}; + +struct CodeGuard { + CodeGuard(bvar::Adder* nerror, CURVEFS_ERROR* code) + : nerror(nerror), code(code) {} + + ~CodeGuard() { + if (*code != CURVEFS_ERROR::OK) { + (*nerror) << 1; + } + } + + bvar::Adder* nerror; + CURVEFS_ERROR* code; +}; + +struct MetricGuards { + explicit MetricGuards(OpMetric* metric, CURVEFS_ERROR* code) + : iGuard(&metric->ninflight), + cGuard(&metric->nerror, code), + lGuard(&metric->latency) {} + + ~MetricGuards() = default; + + InflightGuard iGuard; + CodeGuard cGuard; + LatencyUpdater lGuard; +}; + +// NOTE: param rc is implicit +#define MetricGuard(OP) MetricGuards(&FuseLLOpMetric::GetInstance().OP, &rc); + +} // namespace base +} // namespace client +} // namespace curvefs + +#endif // CURVEFS_SRC_CLIENT_BASE_METRIC_H_ diff --git a/curvefs/src/client/base/perf_context.cpp b/curvefs/src/client/base/perf_context.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/curvefs/src/client/base/perf_context.h b/curvefs/src/client/base/perf_context.h new file mode 100644 index 0000000000..8c3184307b --- /dev/null +++ b/curvefs/src/client/base/perf_context.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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: Curve + * Created Date: 2023-11-20 + * Author: Jingli Chen (Wine93) + */ + +// perf context +// (1) 整体设计参考 rocksdb,需要更灵活 +// (2) IO 链路上的请求需要尽可能细的拆分: memory, diskcache, s3, memcache +// (3) 元数据操作主要是 rpc(如果可以拆分网络和磁盘等更好) + +#ifndef CURVEFS_SRC_CLIENT_BASE_PERF_CONTEXT_H_ +#define CURVEFS_SRC_CLIENT_BASE_PERF_CONTEXT_H_ + +namespace curvefs { +namespace client { +namespace base { + +} // namespace base +} // namespace client +} // namespace curvefs + +#endif // CURVEFS_SRC_CLIENT_BASE_PERF_CONTEXT_H_