From d5cd451ed1bf2e1b577d7d66bdb6e95cd7dcbe4b Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 14 Nov 2023 17:24:23 +0800
Subject: [PATCH 153/181] improve event logs

Signed-off-by: haozi007 <liuhao27@huawei.com>
---
 .../entry/connect/grpc/runtime_runtime_service.cc     | 10 +++++++---
 .../entry/cri/cri_pod_sandbox_manager_service_impl.cc |  1 +
 src/daemon/entry/cri/network_plugin.cc                | 11 ++++++++---
 src/daemon/executor/volume_cb/volume_cb.c             |  4 ++--
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
index 852d6791..5b4adc3f 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
@@ -118,7 +118,7 @@ grpc::Status RuntimeRuntimeServiceImpl::CreateContainer(grpc::ServerContext *con
         return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid input arguments");
     }
 
-    EVENT("Event: {Object: CRI, Type: Creating Container}");
+    EVENT("Event: {Object: CRI, Type: Creating Container for sandbox: %s}", request->pod_sandbox_id().c_str());
 
     std::string responseID =
         rService->CreateContainer(request->pod_sandbox_id(), request->config(), request->sandbox_config(), error);
@@ -360,7 +360,11 @@ grpc::Status RuntimeRuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *conte
         return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid input arguments");
     }
 
-    EVENT("Event: {Object: CRI, Type: Running Pod}");
+    if (request->has_config() && request->config().has_metadata()) {
+        EVENT("Event: {Object: CRI, Type: Running Pod: %s}", request->config().metadata().name().c_str());
+    } else {
+        EVENT("Event: {Object: CRI, Type: Running Pod}");
+    }
 
     std::string responseID = rService->RunPodSandbox(request->config(), request->runtime_handler(), error);
     if (!error.Empty() || responseID.empty()) {
@@ -369,7 +373,7 @@ grpc::Status RuntimeRuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *conte
     }
     reply->set_pod_sandbox_id(responseID);
 
-    EVENT("Event: {Object: CRI, Type: Run Pod success}");
+    EVENT("Event: {Object: CRI, Type: Run Pod: %s success}", responseID.c_str());
 
     return grpc::Status::OK;
 }
diff --git a/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc b/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc
index c9b5527c..edf4dc81 100644
--- a/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc
+++ b/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc
@@ -624,6 +624,7 @@ auto PodSandboxManagerServiceImpl::RunPodSandbox(const runtime::v1alpha2::PodSan
     // Step 2: Create the sandbox container.
     response_id = CreateSandboxContainer(config, image, jsonCheckpoint, runtimeHandler, error);
     if (error.NotEmpty()) {
+        ERROR("Create sandbox failed: %s", error.GetCMessage());
         goto cleanup;
     }
 
diff --git a/src/daemon/entry/cri/network_plugin.cc b/src/daemon/entry/cri/network_plugin.cc
index 9933b584..9a14529e 100644
--- a/src/daemon/entry/cri/network_plugin.cc
+++ b/src/daemon/entry/cri/network_plugin.cc
@@ -460,13 +460,15 @@ void PluginManager::SetUpPod(const std::string &ns, const std::string &name, con
         error.AppendError(tmpErr.GetCMessage());
         return;
     }
-    INFO("Calling network plugin %s to set up pod %s", m_plugin->Name().c_str(), fullName.c_str());
+    EVENT("Setup network plugin %s for sandbox: %s", m_plugin->Name().c_str(), fullName.c_str());
 
     m_plugin->SetUpPod(ns, name, interfaceName, podSandboxID, annotations, options, tmpErr);
     if (tmpErr.NotEmpty()) {
-        error.Errorf("NetworkPlugin %s failed to set up pod %s network: %s", m_plugin->Name().c_str(), fullName.c_str(),
+        ERROR("Setup network for sandbox: %s failed: %s", fullName.c_str(), tmpErr.GetCMessage());
+        error.Errorf("NetworkPlugin %s for sandbox %s network: %s", m_plugin->Name().c_str(), fullName.c_str(),
                      tmpErr.GetCMessage());
     }
+    EVENT("Setuped network plugin %s for sandbox: %s", m_plugin->Name().c_str(), fullName.c_str());
 
     tmpErr.Clear();
     Unlock(fullName, tmpErr);
@@ -490,12 +492,15 @@ void PluginManager::TearDownPod(const std::string &ns, const std::string &name,
         goto unlock;
     }
 
-    INFO("Calling network plugin %s to tear down pod %s", m_plugin->Name().c_str(), fullName.c_str());
+    EVENT("Teardown network %s for sandbox: %s", m_plugin->Name().c_str(), fullName.c_str());
     m_plugin->TearDownPod(ns, name, Network::DEFAULT_NETWORK_INTERFACE_NAME, podSandboxID, annotations, tmpErr);
     if (tmpErr.NotEmpty()) {
+        ERROR("Teardown network for sandbox: %s failed: %s", fullName.c_str(), tmpErr.GetCMessage());
         error.Errorf("NetworkPlugin %s failed to teardown pod %s network: %s", m_plugin->Name().c_str(),
                      fullName.c_str(), tmpErr.GetCMessage());
     }
+    EVENT("Teardowned network %s for sandbox: %s", m_plugin->Name().c_str(), fullName.c_str());
+
 unlock:
     tmpErr.Clear();
     Unlock(fullName, tmpErr);
diff --git a/src/daemon/executor/volume_cb/volume_cb.c b/src/daemon/executor/volume_cb/volume_cb.c
index 13f99517..4ac5c301 100644
--- a/src/daemon/executor/volume_cb/volume_cb.c
+++ b/src/daemon/executor/volume_cb/volume_cb.c
@@ -58,7 +58,7 @@ static int volume_list_cb(const volume_list_volume_request *request, volume_list
         goto err_out;
     }
 
-    EVENT("Volume Event: {Object: list volumes, Type: listing}");
+    INFO("Volume Event: {Object: list volumes, Type: listing}");
 
     list = volume_list();
     if (list == NULL) {
@@ -91,7 +91,7 @@ static int volume_list_cb(const volume_list_volume_request *request, volume_list
     }
 
 out:
-    EVENT("Volume Event: {Object: list volumes, Type: listed");
+    INFO("Volume Event: {Object: list volumes, Type: listed");
 
 err_out:
     if (*response != NULL) {
-- 
2.42.0

