1 Star 0 Fork 46

DriedYellowPeach/iSulad_1

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0007-add-CRI-ContainerStats-Service.patch 21.16 KB
一键复制 编辑 原始数据 按行查看 历史
From 9bd02c394110180ac7d7cbe80c1f4abe18146ebb Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <[email protected]>
Date: Fri, 10 Feb 2023 17:43:11 +0800
Subject: [PATCH 07/53] add CRI ContainerStats Service
Signed-off-by: zhangxiaoyu <[email protected]>
---
.../connect/grpc/runtime_image_service.cc | 12 ++---
.../connect/grpc/runtime_runtime_service.cc | 45 +++++++++++-----
.../connect/grpc/runtime_runtime_service.h | 3 ++
.../cri/cri_container_manager_service.cc | 54 +++++++++++++++++++
.../entry/cri/cri_container_manager_service.h | 3 ++
src/daemon/entry/cri/cri_runtime_service.h | 3 ++
.../entry/cri/cri_runtime_service_impl.cc | 6 +++
.../entry/cri/cri_runtime_service_impl.h | 3 ++
src/daemon/modules/events/collector.c | 4 +-
src/daemon/modules/image/image.c | 16 +++---
.../modules/image/oci/oci_common_operators.c | 8 +--
11 files changed, 125 insertions(+), 32 deletions(-)
diff --git a/src/daemon/entry/connect/grpc/runtime_image_service.cc b/src/daemon/entry/connect/grpc/runtime_image_service.cc
index 23447baf..e593a9c6 100644
--- a/src/daemon/entry/connect/grpc/runtime_image_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_image_service.cc
@@ -54,7 +54,7 @@ grpc::Status RuntimeImageServiceImpl::ListImages(grpc::ServerContext *context,
std::vector<std::unique_ptr<runtime::v1alpha2::Image>> images;
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all images}");
+ INFO("Event: {Object: CRI, Type: Listing all images}");
rService->ListImages(request->filter(), &images, error);
if (!error.Empty()) {
@@ -70,7 +70,7 @@ grpc::Status RuntimeImageServiceImpl::ListImages(grpc::ServerContext *context,
*image = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all images}");
+ INFO("Event: {Object: CRI, Type: Listed all images}");
return grpc::Status::OK;
}
@@ -82,7 +82,7 @@ grpc::Status RuntimeImageServiceImpl::ImageStatus(grpc::ServerContext *context,
std::unique_ptr<runtime::v1alpha2::Image> image_info = nullptr;
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing image %s}", request->image().image().c_str());
+ INFO("Event: {Object: CRI, Type: Statusing image %s}", request->image().image().c_str());
image_info = rService->ImageStatus(request->image(), error);
if (!error.Empty() && !CRIHelpers::IsImageNotFoundError(error.GetMessage())) {
@@ -96,7 +96,7 @@ grpc::Status RuntimeImageServiceImpl::ImageStatus(grpc::ServerContext *context,
*image = *image_info;
}
- WARN("Event: {Object: CRI, Type: Statused image %s}", request->image().image().c_str());
+ INFO("Event: {Object: CRI, Type: Statused image %s}", request->image().image().c_str());
return grpc::Status::OK;
}
@@ -108,7 +108,7 @@ grpc::Status RuntimeImageServiceImpl::ImageFsInfo(grpc::ServerContext *context,
std::vector<std::unique_ptr<runtime::v1alpha2::FilesystemUsage>> usages;
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing image fs info}");
+ INFO("Event: {Object: CRI, Type: Statusing image fs info}");
rService->ImageFsInfo(&usages, error);
if (!error.Empty()) {
@@ -125,7 +125,7 @@ grpc::Status RuntimeImageServiceImpl::ImageFsInfo(grpc::ServerContext *context,
*fs_info = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Statused image fs info}");
+ INFO("Event: {Object: CRI, Type: Statused image fs info}");
return grpc::Status::OK;
}
diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
index b6f9e751..8fed162b 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
@@ -171,7 +171,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainers(grpc::ServerContext *cont
{
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all Container}");
+ INFO("Event: {Object: CRI, Type: Listing all Container}");
std::vector<std::unique_ptr<runtime::v1alpha2::Container>> containers;
m_rService->ListContainers(request->has_filter() ? &request->filter() : nullptr, &containers, error);
@@ -189,7 +189,28 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainers(grpc::ServerContext *cont
*container = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all Container}");
+ INFO("Event: {Object: CRI, Type: Listed all Container}");
+
+ return grpc::Status::OK;
+}
+
+grpc::Status RuntimeRuntimeServiceImpl::ContainerStats(grpc::ServerContext *context,
+ const runtime::v1alpha2::ContainerStatsRequest *request,
+ runtime::v1alpha2::ContainerStatsResponse *reply)
+{
+ Errors error;
+
+ INFO("Event: {Object: CRI, Type: Getting Container Stats: %s}", request->container_id().c_str());
+
+ std::unique_ptr<runtime::v1alpha2::ContainerStats> contStats =
+ m_rService->ContainerStats(request->container_id(), error);
+ if (!error.Empty() || !contStats) {
+ ERROR("Object: CRI, Type: Failed to get container stats %s", request->container_id().c_str());
+ return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage());
+ }
+ *(reply->mutable_stats()) = *contStats;
+
+ INFO("Event: {Object: CRI, Type: Got Container stats: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
@@ -200,7 +221,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainerStats(grpc::ServerContext *
{
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all Container stats}");
+ INFO("Event: {Object: CRI, Type: Listing all Container stats}");
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> containers;
m_rService->ListContainerStats(request->has_filter() ? &request->filter() : nullptr, &containers, error);
@@ -218,7 +239,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainerStats(grpc::ServerContext *
*container = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all Container stats}");
+ INFO("Event: {Object: CRI, Type: Listed all Container stats}");
return grpc::Status::OK;
}
@@ -229,7 +250,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ContainerStatus(grpc::ServerContext *con
{
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing Container: %s}", request->container_id().c_str());
+ INFO("Event: {Object: CRI, Type: Statusing Container: %s}", request->container_id().c_str());
std::unique_ptr<runtime::v1alpha2::ContainerStatus> contStatus =
m_rService->ContainerStatus(request->container_id(), error);
@@ -239,7 +260,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ContainerStatus(grpc::ServerContext *con
}
*(reply->mutable_status()) = *contStatus;
- WARN("Event: {Object: CRI, Type: Statused Container: %s}", request->container_id().c_str());
+ INFO("Event: {Object: CRI, Type: Statused Container: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
@@ -329,7 +350,7 @@ grpc::Status RuntimeRuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *co
{
Errors error;
- WARN("Event: {Object: CRI, Type: Status Pod: %s}", request->pod_sandbox_id().c_str());
+ INFO("Event: {Object: CRI, Type: Status Pod: %s}", request->pod_sandbox_id().c_str());
std::unique_ptr<runtime::v1alpha2::PodSandboxStatus> podStatus;
podStatus = m_rService->PodSandboxStatus(request->pod_sandbox_id(), error);
@@ -340,7 +361,7 @@ grpc::Status RuntimeRuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *co
}
*(reply->mutable_status()) = *podStatus;
- WARN("Event: {Object: CRI, Type: Statused Pod: %s}", request->pod_sandbox_id().c_str());
+ INFO("Event: {Object: CRI, Type: Statused Pod: %s}", request->pod_sandbox_id().c_str());
return grpc::Status::OK;
}
@@ -351,7 +372,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *cont
{
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all Pods}");
+ INFO("Event: {Object: CRI, Type: Listing all Pods}");
std::vector<std::unique_ptr<runtime::v1alpha2::PodSandbox>> pods;
m_rService->ListPodSandbox(request->has_filter() ? &request->filter() : nullptr, &pods, error);
@@ -368,7 +389,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *cont
*pod = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all Pods}");
+ INFO("Event: {Object: CRI, Type: Listed all Pods}");
return grpc::Status::OK;
}
@@ -460,7 +481,7 @@ grpc::Status RuntimeRuntimeServiceImpl::Status(grpc::ServerContext *context,
{
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing daemon}");
+ INFO("Event: {Object: CRI, Type: Statusing daemon}");
std::unique_ptr<runtime::v1alpha2::RuntimeStatus> status = m_rService->Status(error);
if (status == nullptr || error.NotEmpty()) {
@@ -469,7 +490,7 @@ grpc::Status RuntimeRuntimeServiceImpl::Status(grpc::ServerContext *context,
}
*(reply->mutable_status()) = *status;
- WARN("Event: {Object: CRI, Type: Statused daemon}");
+ INFO("Event: {Object: CRI, Type: Statused daemon}");
return grpc::Status::OK;
}
diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.h b/src/daemon/entry/connect/grpc/runtime_runtime_service.h
index 6e8c1009..cb3c5425 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.h
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.h
@@ -52,6 +52,9 @@ public:
const runtime::v1alpha2::ListContainerStatsRequest *request,
runtime::v1alpha2::ListContainerStatsResponse *reply) override;
+ grpc::Status ContainerStats(grpc::ServerContext *context, const runtime::v1alpha2::ContainerStatsRequest *request,
+ runtime::v1alpha2::ContainerStatsResponse *reply) override;
+
grpc::Status ContainerStatus(grpc::ServerContext *context, const runtime::v1alpha2::ContainerStatusRequest *request,
runtime::v1alpha2::ContainerStatusResponse *reply) override;
diff --git a/src/daemon/entry/cri/cri_container_manager_service.cc b/src/daemon/entry/cri/cri_container_manager_service.cc
index d044cca8..710556a3 100644
--- a/src/daemon/entry/cri/cri_container_manager_service.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service.cc
@@ -893,6 +893,60 @@ cleanup:
free_container_stats_response(response);
}
+auto ContainerManagerService::ContainerStats(const std::string &containerID, Errors &error)
+-> std::unique_ptr<runtime::v1alpha2::ContainerStats>
+{
+ container_stats_request *request { nullptr };
+ container_stats_response *response { nullptr };
+ std::unique_ptr<runtime::v1alpha2::ContainerStats> contStats { nullptr };
+ std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> contStatsVec;
+
+ if (containerID.empty()) {
+ error.SetError("Empty container id");
+ return nullptr;
+ }
+
+ if (m_cb == nullptr || m_cb->container.stats == nullptr) {
+ error.SetError("Unimplemented callback");
+ return nullptr;
+ }
+
+ request = (container_stats_request *)util_common_calloc_s(sizeof(container_stats_request));
+ if (request == nullptr) {
+ error.SetError("Out of memory");
+ return nullptr;
+ }
+
+ request->containers = (char **)util_smart_calloc_s(sizeof(char *), 1);
+ if (request->containers == nullptr) {
+ error.SetError("Out of memory");
+ goto cleanup;
+ }
+
+ request->containers[0] = util_strdup_s(containerID.c_str());
+ request->containers_len = 1;
+
+ if (m_cb->container.stats(request, &response) != 0) {
+ if (response != nullptr && response->errmsg != nullptr) {
+ error.SetError(response->errmsg);
+ } else {
+ error.SetError("Failed to call stats container callback");
+ }
+ goto cleanup;
+ }
+
+ ContainerStatsToGRPC(response, &contStatsVec, error);
+ if (error.NotEmpty()) {
+ goto cleanup;
+ }
+ contStats = std::move(contStatsVec[0]);
+
+cleanup:
+ free_container_stats_request(request);
+ free_container_stats_response(response);
+ return contStats;
+}
+
void ContainerManagerService::PackContainerImageToStatus(
container_inspect *inspect, std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus, Errors &error)
{
diff --git a/src/daemon/entry/cri/cri_container_manager_service.h b/src/daemon/entry/cri/cri_container_manager_service.h
index 8002b77d..6ec1f21d 100644
--- a/src/daemon/entry/cri/cri_container_manager_service.h
+++ b/src/daemon/entry/cri/cri_container_manager_service.h
@@ -53,6 +53,9 @@ public:
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats,
Errors &error);
+ auto ContainerStats(const std::string &containerID, Errors &error)
+ -> std::unique_ptr<runtime::v1alpha2::ContainerStats>;
+
auto ContainerStatus(const std::string &containerID, Errors &error)
-> std::unique_ptr<runtime::v1alpha2::ContainerStatus>;
diff --git a/src/daemon/entry/cri/cri_runtime_service.h b/src/daemon/entry/cri/cri_runtime_service.h
index 4727230f..5e4740cb 100644
--- a/src/daemon/entry/cri/cri_runtime_service.h
+++ b/src/daemon/entry/cri/cri_runtime_service.h
@@ -49,6 +49,9 @@ public:
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats,
Errors &error) = 0;
+ virtual auto ContainerStats(const std::string &containerID,
+ Errors &error) -> std::unique_ptr<runtime::v1alpha2::ContainerStats> = 0;
+
virtual auto ContainerStatus(const std::string &containerID,
Errors &error) -> std::unique_ptr<runtime::v1alpha2::ContainerStatus> = 0;
diff --git a/src/daemon/entry/cri/cri_runtime_service_impl.cc b/src/daemon/entry/cri/cri_runtime_service_impl.cc
index 241d4316..c4b84828 100644
--- a/src/daemon/entry/cri/cri_runtime_service_impl.cc
+++ b/src/daemon/entry/cri/cri_runtime_service_impl.cc
@@ -70,6 +70,12 @@ void CRIRuntimeServiceImpl::ListContainerStats(
m_containerManager->ListContainerStats(filter, containerstats, error);
}
+auto CRIRuntimeServiceImpl::ContainerStats(const std::string &containerID, Errors &error)
+-> std::unique_ptr<runtime::v1alpha2::ContainerStats>
+{
+ return m_containerManager->ContainerStats(containerID, error);
+}
+
auto CRIRuntimeServiceImpl::ContainerStatus(const std::string &containerID, Errors &error)
-> std::unique_ptr<runtime::v1alpha2::ContainerStatus>
{
diff --git a/src/daemon/entry/cri/cri_runtime_service_impl.h b/src/daemon/entry/cri/cri_runtime_service_impl.h
index f2e25e42..7355c5cb 100644
--- a/src/daemon/entry/cri/cri_runtime_service_impl.h
+++ b/src/daemon/entry/cri/cri_runtime_service_impl.h
@@ -51,6 +51,9 @@ public:
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats,
Errors &error) override;
+ auto ContainerStats(const std::string &containerID, Errors &error)
+ -> std::unique_ptr<runtime::v1alpha2::ContainerStats> override;
+
auto ContainerStatus(const std::string &containerID, Errors &error)
-> std::unique_ptr<runtime::v1alpha2::ContainerStatus> override;
diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c
index fb4e4a98..f53ad319 100644
--- a/src/daemon/modules/events/collector.c
+++ b/src/daemon/modules/events/collector.c
@@ -484,7 +484,7 @@ static int write_events_log(const struct isulad_events_format *events)
len = calculate_annaotation_info_len(events);
if (len == 1) {
- WARN("Event: {Object: %s, Type: %s}", events->id, events->opt);
+ INFO("Event: {Object: %s, Type: %s}", events->id, events->opt);
} else {
annotation = (char *)util_common_calloc_s(len);
if (annotation == NULL) {
@@ -502,7 +502,7 @@ static int write_events_log(const struct isulad_events_format *events)
}
(void)strcat(annotation, ")");
- WARN("Event: {Object: %s, Type: %s %s}", events->id, events->opt, annotation);
+ INFO("Event: {Object: %s, Type: %s %s}", events->id, events->opt, annotation);
}
out:
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
index d5fbc8dc..a9b9523e 100644
--- a/src/daemon/modules/image/image.c
+++ b/src/daemon/modules/image/image.c
@@ -416,7 +416,7 @@ int im_get_filesystem_info(const char *image_type, im_fs_info_response **respons
goto out;
}
- WARN("Event: {Object: get image filesystem info, Type: inspecting}");
+ INFO("Event: {Object: get image filesystem info, Type: inspecting}");
ret = q->ops->get_filesystem_info(response);
if (ret != 0) {
if (response != NULL && *response != NULL) {
@@ -426,7 +426,7 @@ int im_get_filesystem_info(const char *image_type, im_fs_info_response **respons
}
goto out;
}
- WARN("Event: {Object: get image filesystem info, Type: inspected}");
+ INFO("Event: {Object: get image filesystem info, Type: inspected}");
out:
return ret;
@@ -466,7 +466,7 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
request->name_id = util_strdup_s(id);
}
- WARN("Event: {Object: container \'%s\' filesystem info, Type: inspecting}", id != NULL ? id : "");
+ INFO("Event: {Object: container \'%s\' filesystem info, Type: inspecting}", id != NULL ? id : "");
ret = q->ops->container_fs_usage(request, &filesystemusage);
if (ret != 0) {
ERROR("Failed to get filesystem usage for container %s", id);
@@ -476,7 +476,7 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
*fs_usage = filesystemusage;
filesystemusage = NULL;
- WARN("Event: {Object: container \'%s\' filesystem info, Type: inspected}", id != NULL ? id : "");
+ INFO("Event: {Object: container \'%s\' filesystem info, Type: inspected}", id != NULL ? id : "");
out:
free_im_container_fs_usage_request(request);
@@ -916,7 +916,7 @@ int im_list_images(const im_list_request *ctx, im_list_response **response)
return -1;
}
- WARN("Event: {Object: list images, Type: listing}");
+ INFO("Event: {Object: list images, Type: listing}");
for (i = 0; i < g_numbims; i++) {
if (g_bims[i].ops->list_ims == NULL) {
@@ -936,7 +936,7 @@ int im_list_images(const im_list_request *ctx, im_list_response **response)
images_tmp = NULL;
}
- WARN("Event: {Object: list images, Type: listed}");
+ INFO("Event: {Object: list images, Type: listed}");
if (g_isulad_errmsg != NULL) {
(*response)->errmsg = util_strdup_s(g_isulad_errmsg);
@@ -1671,7 +1671,7 @@ int im_inspect_image(const im_inspect_request *request, im_inspect_response **re
image_ref = util_strdup_s(request->image.image);
- WARN("Event: {Object: %s, Type: image inspecting}", image_ref);
+ INFO("Event: {Object: %s, Type: image inspecting}", image_ref);
bim_type = bim_query(image_ref);
if (bim_type == NULL) {
@@ -1693,7 +1693,7 @@ int im_inspect_image(const im_inspect_request *request, im_inspect_response **re
goto pack_response;
}
- WARN("Event: {Object: %s, Type: image inspected}", image_ref);
+ INFO("Event: {Object: %s, Type: image inspected}", image_ref);
pack_response:
if (g_isulad_errmsg != NULL) {
diff --git a/src/daemon/modules/image/oci/oci_common_operators.c b/src/daemon/modules/image/oci/oci_common_operators.c
index 3d200e09..83cccbe6 100644
--- a/src/daemon/modules/image/oci/oci_common_operators.c
+++ b/src/daemon/modules/image/oci/oci_common_operators.c
@@ -429,7 +429,7 @@ int oci_summary_image(im_summary_request *request, im_summary_response *response
goto pack_response;
}
- WARN("Event: {Object: %s, Type: statusing image summary}", resolved_name);
+ INFO("Event: {Object: %s, Type: statusing image summary}", resolved_name);
image_summary = storage_img_get_summary(resolved_name);
if (image_summary == NULL) {
@@ -442,7 +442,7 @@ int oci_summary_image(im_summary_request *request, im_summary_response *response
response->image_summary = image_summary;
image_summary = NULL;
- WARN("Event: {Object: %s, Type: statused image summary}", resolved_name);
+ INFO("Event: {Object: %s, Type: statused image summary}", resolved_name);
pack_response:
free(resolved_name);
@@ -493,7 +493,7 @@ int oci_status_image(im_status_request *request, im_status_response *response)
goto pack_response;
}
- WARN("Event: {Object: %s, Type: statusing image}", resolved_name);
+ INFO("Event: {Object: %s, Type: statusing image}", resolved_name);
image_info = storage_img_get(resolved_name);
if (image_info == NULL) {
@@ -506,7 +506,7 @@ int oci_status_image(im_status_request *request, im_status_response *response)
response->image_info->image = image_info;
image_info = NULL;
- WARN("Event: {Object: %s, Type: statused image}", resolved_name);
+ INFO("Event: {Object: %s, Type: statused image}", resolved_name);
pack_response:
free(resolved_name);
--
2.25.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/driedyellowpeach/iSulad_1.git
[email protected]:driedyellowpeach/iSulad_1.git
driedyellowpeach
iSulad_1
iSulad_1
master

搜索帮助