Skip to content
Open
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
64 changes: 64 additions & 0 deletions test/engine/setup/chaos/cpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2025 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chaos

import (
"context"
"fmt"
"strconv"

"github.com/alibaba/ilogtail/test/engine/setup"
)

func CPUFullLoad(ctx context.Context, time int) (context.Context, error) {
switch setup.Env.GetType() {
case "host":
command := "/opt/chaosblade/blade create cpu fullload --timeout " + strconv.FormatInt(int64(time), 10)
_, err := setup.Env.ExecOnLoongCollector(command)
if err != nil {
return ctx, err
}
default:
return ctx, fmt.Errorf("not supported")
}
return ctx, nil
}

func CPU100NProc(ctx context.Context, time int) (context.Context, error) {
switch setup.Env.GetType() {
case "host":
command := "sh /root/e2eshel/100nProc.sh " + strconv.FormatInt(int64(time), 10)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个脚本没有提交

_, err := setup.Env.ExecOnLoongCollector(command)
if err != nil {
return ctx, err
}
default:
return ctx, fmt.Errorf("not supported")
}
return ctx, nil
}

func CPUNProc(ctx context.Context, time int) (context.Context, error) {
switch setup.Env.GetType() {
case "host":
command := "sh /root/e2eshel/runpy.sh /root/e2eshel/nproc.py " + strconv.FormatInt(int64(time), 10)
_, err := setup.Env.ExecOnLoongCollector(command)
if err != nil {
return ctx, err
}
default:
return ctx, fmt.Errorf("not supported")
}
return ctx, nil
}
64 changes: 64 additions & 0 deletions test/engine/setup/chaos/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2025 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chaos

import (
"context"
"fmt"
"strconv"

"github.com/alibaba/ilogtail/test/engine/setup"
)

func MemHigh(ctx context.Context, time int) (context.Context, error) {
switch setup.Env.GetType() {
case "host":
command := "/opt/chaosblade/blade c mem load --mem-percent 99 --timeout " + strconv.FormatInt(int64(time), 10)
_, err := setup.Env.ExecOnLoongCollector(command)
if err != nil {
return ctx, err
}
default:
return ctx, fmt.Errorf("not supported")
}
return ctx, nil
}

func Oom(ctx context.Context) (context.Context, error) {
switch setup.Env.GetType() {
case "host":
command := "sh /root/e2eshel/runpy.sh /root/e2eshel/oom_kill.py"
_, err := setup.Env.ExecOnLoongCollector(command)
if err != nil {
return ctx, err
}
default:
return ctx, fmt.Errorf("not supported")
}
return ctx, nil
}

func MemFrag(ctx context.Context, time int) (context.Context, error) {
switch setup.Env.GetType() {
case "host":
command := "/root/e2eshel/mem_frag " + strconv.FormatInt(int64(time), 10)
_, err := setup.Env.ExecOnLoongCollector(command)
if err != nil {
return ctx, err
}
default:
return ctx, fmt.Errorf("not supported")
}
return ctx, nil
}
6 changes: 6 additions & 0 deletions test/engine/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func ScenarioInitializer(ctx *godog.ScenarioContext) {
ctx.Given(`^disk full for \{(\d+)\} seconds$`, chaos.DiskFull)
ctx.Given(`^disk burn read for \{(\d+)\} seconds$`, chaos.DiskBurRead)
ctx.Given(`^disk burn write for \{(\d+)\} seconds$`, chaos.DiskBurWrite)
ctx.Given(`^cpu fullload for \{(\d+)\} seconds$`, chaos.CPUFullLoad)
ctx.Given(`^cpu 100nproc for \{(\d+)\} seconds$`, chaos.CPU100NProc)
ctx.Given(`^cpu nproc for \{(\d+)\} seconds$`, chaos.CPUNProc)
ctx.Given(`^mem high for \{(\d+)\} seconds$`, chaos.MemHigh)
ctx.Given(`^oom$`, chaos.Oom)
ctx.Given(`^mem frag for \{(\d+)\} seconds$`, chaos.MemFrag)
ctx.Given(`^clean all chaos$`, cleanup.DestoryAllChaos)
// ------------------------------------------

Expand Down
Loading