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 <fgiudici@redhat.com>
This commit is contained in:
Francesco Giudici 2021-07-20 10:56:29 +02:00
parent 0b03d97d0b
commit 97dcc5f78a
3 changed files with 3 additions and 28 deletions

View File

@ -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.

View File

@ -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()

View File

@ -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) {