Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smoke: support node image #1500

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
include:
- image: wordpress
tag: 6.1.1
- image: node
tag: 19.8
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -109,6 +111,8 @@ jobs:
include:
- image: wordpress
tag: 6.1.1
- image: node
tag: 19.8
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -145,6 +149,8 @@ jobs:
include:
- image: wordpress
tag: 6.1.1
- image: node
tag: 19.8
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -181,6 +187,8 @@ jobs:
include:
- image: wordpress
tag: 6.1.1
- image: node
tag: 19.8
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -208,6 +216,9 @@ jobs:
"wordpress")
echo "### workload: wait the 80 port response" > $GITHUB_STEP_SUMMARY
;;
"node")
echo "### workload: node index.js; wait the 80 port response" > $GITHUB_STEP_SUMMARY
;;
esac
cd benchmark-result
metric_files=(
Expand Down
10 changes: 10 additions & 0 deletions smoke/tests/texture/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("hello\n");
});

server.listen(80);
48 changes: 31 additions & 17 deletions smoke/tests/tool/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand All @@ -29,10 +28,17 @@ type ContainerMetrics struct {

type RunArgs struct {
WaitURL string
Arg string
Mount mountPath
BaselineReadCount map[string]uint64
BaselineReadAmount map[string]uint64
}

type mountPath struct {
source string
target string
}

var URL_WAIT = map[string]RunArgs{
"wordpress": {
WaitURL: "http://localhost:80",
Expand All @@ -47,27 +53,33 @@ var URL_WAIT = map[string]RunArgs{
"zran": 79836339,
},
},
"node": {
WaitURL: "http://localhost:80",
Arg: "node /src/index.js",
Mount: mountPath{
source: "tests/texture/node",
target: "/src",
},
},
}

var supportContainerImages = []string{"wordpress"}

// SupportContainerImage help to check if we support the image or not
func SupportContainerImage(image string) bool {
return contains(supportContainerImages, image)
}

func contains(slice []string, value string) bool {
for _, v := range slice {
if strings.Contains(v, value) {
return true
}
}
return false
_, ok := URL_WAIT[image]
return ok
}

// runUrlWaitContainer run Contaienr util geting http response from WaitUrl
func runUrlWaitContainer(t *testing.T, image string, containerName string, runArgs RunArgs) {
cmd := fmt.Sprintf("sudo nerdctl --insecure-registry --snapshotter nydus run -d --net=host --name=%s %s", containerName, image)
cmd := "sudo nerdctl --insecure-registry --snapshotter nydus run -d --net=host"
if runArgs.Mount.source != "" {
currentDir, err := os.Getwd()
if err != nil {
t.Fatalf("can't get rooted path name")
}
cmd += fmt.Sprintf(" --volume %s:%s", filepath.Join(currentDir, runArgs.Mount.source), runArgs.Mount.target)
}
cmd += fmt.Sprintf(" --name=%s %s %s", containerName, image, runArgs.Arg)
RunWithoutOutput(t, cmd)
for {
resp, err := http.Get(runArgs.WaitURL)
Expand Down Expand Up @@ -103,14 +115,16 @@ func RunContainerWithBaseline(t *testing.T, image string, containerName string,
// RunContainer and return container metric
func RunContainer(t *testing.T, image string, containerName string) *ContainerMetrics {
var containerMetic ContainerMetrics
startTime := time.Now()

// runContainer
args, ok := URL_WAIT[ImageRepo(t, image)]
if ok {
startTime := time.Now()
runUrlWaitContainer(t, image, containerName, args)
endTime := time.Now()
containerMetic.E2ETime = endTime.Sub(startTime)
defer clearContainer(t, image, containerName)
}

containerMetic.E2ETime = time.Since(startTime)
backendMetrics, err := getContainerBackendMetrics(t)
if err != nil {
t.Logf(err.Error())
Expand Down