runtime: add new command to collect metrics from Kata containers

Add a new command to collect metrics and return metrics to Prometheus.

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu
2020-06-10 17:40:47 +08:00
parent 186fed2a11
commit 1b75daa00f
280 changed files with 68037 additions and 96 deletions

View File

@@ -1,3 +1,8 @@
// Copyright (c) 2020 Ant Financial
//
// SPDX-License-Identifier: Apache-2.0
//
package utils
import (

View File

@@ -1,10 +1,12 @@
// Copyright (c) 2020 Ant Financial
//
// SPDX-License-Identifier: Apache-2.0
//
package utils
import (
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
)
@@ -29,14 +31,3 @@ func GzipAccepted(header http.Header) bool {
func String2Pointer(s string) *string {
return &s
}
// EnsureFileDir will check if file a in an absolute format and ensure the directory is exits
// if not, make the dir like `mkdir -p`
func EnsureFileDir(file string) error {
if !filepath.IsAbs(file) {
return fmt.Errorf("file must be an absolute path")
}
path := filepath.Dir(file)
return os.MkdirAll(path, 0755)
}

View File

@@ -1,8 +1,12 @@
// Copyright (c) 2020 Ant Financial
//
// SPDX-License-Identifier: Apache-2.0
//
package utils
import (
"net/http"
"os"
"testing"
"github.com/stretchr/testify/assert"
@@ -41,45 +45,3 @@ func TestGzipAccepted(t *testing.T) {
assert.Equal(tc.result, b)
}
}
func TestEnsureFileDir(t *testing.T) {
assert := assert.New(t)
testCases := []struct {
file string
path string
err bool
}{
{
file: "abc.txt",
path: "",
err: true,
},
{
file: "/tmp/kata-test/abc/def/igh.txt",
path: "/tmp/kata-test/abc/def",
err: false,
},
{
file: "/tmp/kata-test/abc/../def/igh.txt",
path: "/tmp/kata-test/def",
err: false,
},
}
for i := range testCases {
tc := testCases[i]
err := EnsureFileDir(tc.file)
// assert error
assert.Equal(tc.err, err != nil)
if !tc.err {
// assert directory created
fileInfo, err := os.Stat(tc.path)
assert.Equal(nil, err)
assert.Equal(true, fileInfo.IsDir())
}
}
// clear test directory
os.RemoveAll("/tmp/kata-test")
}