mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-31 13:04:23 +01:00
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:
@@ -1,3 +1,8 @@
|
||||
// Copyright (c) 2020 Ant Financial
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user