From 97dcc5f78a55b237a809b2107b993b85de31c7c4 Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Tue, 20 Jul 2021 10:56:29 +0200 Subject: [PATCH] kata-monitor: drop getMonitorAddress() since the shim socket path is statically defined in the containerd-shimv2 code, we don't need to retrieve the socket name from the filesystem: construct the socket name using the containerd-shimv2 code. Signed-off-by: Francesco Giudici --- src/runtime/pkg/kata-monitor/cri.go | 2 -- src/runtime/pkg/kata-monitor/metrics.go | 20 -------------------- src/runtime/pkg/kata-monitor/pprof.go | 9 +++------ 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/src/runtime/pkg/kata-monitor/cri.go b/src/runtime/pkg/kata-monitor/cri.go index 087f097724..695344284d 100644 --- a/src/runtime/pkg/kata-monitor/cri.go +++ b/src/runtime/pkg/kata-monitor/cri.go @@ -26,8 +26,6 @@ import ( const ( // unixProtocol is the network protocol of unix socket. unixProtocol = "unix" - - k8sContainerdNamespace = "k8s.io" ) // getAddressAndDialer returns the address parsed from the given endpoint and a context dialer. diff --git a/src/runtime/pkg/kata-monitor/metrics.go b/src/runtime/pkg/kata-monitor/metrics.go index bbc62d18d3..558bb4f15b 100644 --- a/src/runtime/pkg/kata-monitor/metrics.go +++ b/src/runtime/pkg/kata-monitor/metrics.go @@ -9,15 +9,12 @@ import ( "bytes" "compress/gzip" "io" - "io/ioutil" "net/http" - "path/filepath" "sort" "strings" "sync" "time" - "github.com/kata-containers/kata-containers/src/runtime/pkg/types" mutils "github.com/kata-containers/kata-containers/src/runtime/pkg/utils" "github.com/prometheus/client_golang/prometheus" @@ -72,23 +69,6 @@ func registerMetrics() { prometheus.MustRegister(scrapeDurationsHistogram) } -// getMonitorAddress get metrics address for a sandbox, the abstract unix socket address is saved -// in `metrics_address` with the same place of `address`. -func (km *KataMonitor) getMonitorAddress(sandboxID, runtime string) (string, error) { - path := filepath.Join("/run/containerd", types.ContainerdRuntimeTaskPath, k8sContainerdNamespace, sandboxID, "monitor_address") - if runtime == RuntimeCRIO { - path = filepath.Join("/run/containers/storage/overlay-containers", sandboxID, "userdata", "monitor_address") - } - - monitorLog.WithField("path", path).Debug("get monitor address") - - data, err := ioutil.ReadFile(path) - if err != nil { - return "", err - } - return string(data), nil -} - // ProcessMetricsRequest get metrics from shim/hypervisor/vm/agent and return metrics to client. func (km *KataMonitor) ProcessMetricsRequest(w http.ResponseWriter, r *http.Request) { start := time.Now() diff --git a/src/runtime/pkg/kata-monitor/pprof.go b/src/runtime/pkg/kata-monitor/pprof.go index 11f5c34cf4..2060fe3dd3 100644 --- a/src/runtime/pkg/kata-monitor/pprof.go +++ b/src/runtime/pkg/kata-monitor/pprof.go @@ -11,6 +11,8 @@ import ( "io" "net" "net/http" + + shim "github.com/kata-containers/kata-containers/src/runtime/containerd-shim-v2" ) func serveError(w http.ResponseWriter, status int, txt string) { @@ -27,12 +29,7 @@ func (km *KataMonitor) composeSocketAddress(r *http.Request) (string, error) { return "", err } - runtime, err := km.getSandboxRuntime(sandbox) - if err != nil { - return "", err - } - - return km.getMonitorAddress(sandbox, runtime) + return shim.SocketAddress(sandbox), nil } func (km *KataMonitor) proxyRequest(w http.ResponseWriter, r *http.Request) {