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

test: refactor E2E trigger #1861

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
strategy:
matrix:
go-version: [ 1.19.10 ]
python-version: [ 3.8 ]
runner: [ ubuntu-latest ]
fail-fast: true
permissions:
Expand All @@ -62,6 +63,11 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Check out code
uses: actions/checkout@v2
with:
Expand All @@ -83,6 +89,7 @@ jobs:
BUILD_LOGTAIL_UT: OFF
WITHOUTGDB: ON
run: |
pip3 install -r test/requirements.txt
make benchmark
git stash
Expand Down
5 changes: 2 additions & 3 deletions docker/Dockerfile.e2e-test
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM golang:1.19
FROM python:3.8

RUN go env -w GOPROXY="https://goproxy.cn,direct"
RUN mkdir -p /tmp/loongcollector

WORKDIR /root
COPY . ./loongcollector

WORKDIR /root/loongcollector/test
RUN go mod download
RUN pip3 install -r requirements.txt

CMD ["sh", "-c", "while true; do sleep 3600; done"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: performance file to blackhole filebeat
Given docker-compose boot type {benchmark}
When start docker-compose {performance_file_to_blackhole_filebeat}
When start monitor {filebeat}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./a.log}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./test_cases/performance_file_to_blackhole_filebeat/a.log}
When wait monitor until log processing finished
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: performance file to blackhole fluentbit
Given docker-compose boot type {benchmark}
When start docker-compose {performance_file_to_blackhole_fluentbit}
When start monitor {fluent-bit}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./a.log}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./test_cases/performance_file_to_blackhole_fluentbit/a.log}
When wait monitor until log processing finished
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: performance file to blackhole iLogtail
Given docker-compose boot type {benchmark}
When start docker-compose {performance_file_to_blackhole_ilogtail}
When start monitor {ilogtailC}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./a.log}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./test_cases/performance_file_to_blackhole_ilogtail/a.log}
When wait monitor until log processing finished
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: performance file to blackhole iLogtail
Given docker-compose boot type {benchmark}
When start docker-compose {performance_file_to_blackhole_ilogtailspl}
When start monitor {ilogtailC}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./a.log}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./test_cases/performance_file_to_blackhole_ilogtailspl/a.log}
When wait monitor until log processing finished
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: performance file to blackhole vector
Given docker-compose boot type {benchmark}
When start docker-compose {performance_file_to_blackhole_vector}
When start monitor {vector}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./a.log}
When generate random nginx logs to file, speed {10}MB/s, total {3}min, to file {./test_cases/performance_file_to_blackhole_vector/a.log}
When wait monitor until log processing finished
5 changes: 5 additions & 0 deletions test/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package config

import (
"os"
"path/filepath"
"strconv"
"time"

Expand Down Expand Up @@ -72,6 +73,10 @@ func ParseConfig() {
TestConfig.GeneratedLogDir = "/tmp/loongcollector"
}
TestConfig.WorkDir = os.Getenv("WORK_DIR")
if len(TestConfig.WorkDir) == 0 {
testFileDir, _ := os.Getwd()
TestConfig.WorkDir = filepath.Dir(testFileDir)
}

// SSH
TestConfig.SSHUsername = os.Getenv("SSH_USERNAME")
Expand Down
8 changes: 7 additions & 1 deletion test/engine/setup/docker_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"time"

Expand Down Expand Up @@ -128,5 +129,10 @@ func (d *DockerComposeEnv) ExecOnLogtail(command string) (string, error) {
}

func (d *DockerComposeEnv) ExecOnSource(ctx context.Context, command string) (string, error) {
return "", fmt.Errorf("not implemented")
// exec on host of docker compose
fmt.Println(command)
cmd := exec.Command("sh", "-c", command)
output, err := cmd.CombinedOutput()
fmt.Println(string(output))
return string(output), err
}
36 changes: 23 additions & 13 deletions test/engine/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (
"github.com/alibaba/ilogtail/test/engine/cleanup"
"github.com/alibaba/ilogtail/test/engine/control"
"github.com/alibaba/ilogtail/test/engine/setup"
"github.com/alibaba/ilogtail/test/engine/setup/monitor"
"github.com/alibaba/ilogtail/test/engine/setup/subscriber"
"github.com/alibaba/ilogtail/test/engine/trigger"
"github.com/alibaba/ilogtail/test/engine/trigger/ebpf"
"github.com/alibaba/ilogtail/test/engine/trigger/log"
"github.com/alibaba/ilogtail/test/engine/verify"
)

Expand All @@ -27,6 +30,7 @@ func ScenarioInitializer(ctx *godog.ScenarioContext) {
ctx.Given(`^remove http config \{(.*)\}`, control.RemoveHTTPConfig)
ctx.Given(`^subcribe data from \{(\S+)\} with config`, subscriber.InitSubscriber)
ctx.Given(`^mkdir \{(.*)\}`, setup.Mkdir)
ctx.Given(`^docker-compose boot type \{(\S+)\}$`, setup.SetDockerComposeBootType)
// ------------------------------------------

// When
Expand All @@ -41,19 +45,25 @@ func ScenarioInitializer(ctx *godog.ScenarioContext) {

// generate
ctx.When(`^begin trigger`, trigger.BeginTrigger)
ctx.When(`^generate \{(\d+)\} regex logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.RegexSingle)
ctx.When(`^generate \{(\d+)\} multiline regex logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.RegexMultiline)
ctx.When(`^generate \{(\d+)\} regex gbk logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.RegexSingleGBK)
ctx.When(`^generate \{(\d+)\} http logs, with interval \{(\d+)\}ms, url: \{(.*)\}, method: \{(.*)\}, body:`, trigger.HTTP)
ctx.When(`^generate \{(\d+)\} apsara logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.Apsara)
ctx.When(`^generate \{(\d+)\} delimiter logs to file \{(.*)\}, with interval \{(\d+)\}ms, with delimiter \{(.*)\} and quote \{(.*)\}$`, trigger.DelimiterSingle)
ctx.When(`^generate \{(\d+)\} multiline delimiter logs to file \{(.*)\}, with interval \{(\d+)\}ms, with delimiter \{(.*)\} and quote \{(.*)\}$`, trigger.DelimiterMultiline)
ctx.When(`^generate \{(\d+)\} json logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.JSONSingle)
ctx.When(`^generate \{(\d+)\} multiline json logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.JSONMultiline)
ctx.When(`^execute \{(\d+)\} commands to generate process security events`, trigger.TrigerProcessSecurityEvents)
ctx.When(`^execute \{(\d+)\} commands to generate network security events on url \{(.*)\}$`, trigger.TrigerNetworksSecurityEvents)
ctx.When(`^execute \{(\d+)\} commands to generate file security events on files \{(.*)\}$`, trigger.TrigerFileSecurityEvents)
ctx.When(`^generate \{(\d+)\} HTTP requests, with interval \{(\d+)\}ms, url: \{(.*)\}`, trigger.TrigerHTTP)
// log
ctx.When(`^generate \{(\d+)\} regex logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, log.RegexSingle)
ctx.When(`^generate \{(\d+)\} multiline regex logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, log.RegexMultiline)
ctx.When(`^generate \{(\d+)\} regex gbk logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, log.RegexSingleGBK)
ctx.When(`^generate \{(\d+)\} http logs, with interval \{(\d+)\}ms, url: \{(.*)\}, method: \{(.*)\}, body:`, log.HTTP)
ctx.When(`^generate \{(\d+)\} apsara logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, log.Apsara)
ctx.When(`^generate \{(\d+)\} delimiter logs to file \{(.*)\}, with interval \{(\d+)\}ms, with delimiter \{(.*)\} and quote \{(.*)\}$`, log.DelimiterSingle)
ctx.When(`^generate \{(\d+)\} multiline delimiter logs to file \{(.*)\}, with interval \{(\d+)\}ms, with delimiter \{(.*)\} and quote \{(.*)\}$`, log.DelimiterMultiline)
ctx.When(`^generate \{(\d+)\} json logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, log.JSONSingle)
ctx.When(`^generate \{(\d+)\} multiline json logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, log.JSONMultiline)
ctx.When(`^generate random nginx logs to file, speed \{(\d+)\}MB/s, total \{(\d+)\}min, to file \{(.*)\}`, log.Nginx)
ctx.When(`^start monitor \{(\S+)\}`, monitor.StartMonitor)
ctx.When(`^wait monitor until log processing finished$`, monitor.WaitMonitorUntilProcessingFinished)

// ebpf
ctx.When(`^execute \{(\d+)\} commands to generate process security events`, ebpf.ProcessSecurityEvents)
ctx.When(`^execute \{(\d+)\} commands to generate network security events on url \{(.*)\}$`, ebpf.NetworksSecurityEvents)
ctx.When(`^execute \{(\d+)\} commands to generate file security events on files \{(.*)\}$`, ebpf.FileSecurityEvents)
ctx.When(`^generate \{(\d+)\} HTTP requests, with interval \{(\d+)\}ms, url: \{(.*)\}`, ebpf.HTTP)
// ------------------------------------------

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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 trigger
package ebpf

import (
"context"
Expand All @@ -22,7 +22,7 @@ import (
"github.com/alibaba/ilogtail/test/engine/setup"
)

func TrigerHTTP(ctx context.Context, count int, interval int, url string) (context.Context, error) {
func HTTP(ctx context.Context, count int, interval int, url string) (context.Context, error) {
logger.Debugf(context.Background(), "count:%d interval:%d url:%s", count, interval, url)
cmd := fmt.Sprintf("curl -vL %s", url)
time.Sleep(time.Second * 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
// 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 trigger
package ebpf

import (
"context"
"html/template"
"strconv"
"strings"
"time"

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

/*
********************
input_process_security
********************
*/
func TrigerProcessSecurityEvents(ctx context.Context, commandCnt int) (context.Context, error) {
func ProcessSecurityEvents(ctx context.Context, commandCnt int) (context.Context, error) {
time.Sleep(5 * time.Second)
if err := execveCommands(ctx, commandCnt); err != nil {
return ctx, err
Expand All @@ -51,7 +51,7 @@ func execveCommands(ctx context.Context, commandCnt int) error {
input_network_security
********************
*/
func TrigerNetworksSecurityEvents(ctx context.Context, commandCnt int, url string) (context.Context, error) {
func NetworksSecurityEvents(ctx context.Context, commandCnt int, url string) (context.Context, error) {
time.Sleep(5 * time.Second)
if err := curlURL(ctx, commandCnt, url); err != nil {
return ctx, err
Expand All @@ -74,9 +74,8 @@ func curlURL(ctx context.Context, commandCnt int, url string) error {
input_file_security
********************
*/
const triggerFileSecurityTemplate = "cd {{.WorkDir}} && COMMAND_CNT={{.CommandCnt}} FILE_NAME={{.FileName}} {{.Command}}"

func TrigerFileSecurityEvents(ctx context.Context, commandCnt int, filenames string) (context.Context, error) {
func FileSecurityEvents(ctx context.Context, commandCnt int, filenames string) (context.Context, error) {
time.Sleep(5 * time.Second)
if err := rwFile(ctx, commandCnt, filenames); err != nil {
return ctx, err
Expand Down Expand Up @@ -112,20 +111,10 @@ func rwFile(ctx context.Context, commandCnt int, filenames string) error {
}

func mmapFile(ctx context.Context, commandCnt int, filenames string) error {
mmapFileCommand := getRunTriggerCommand("TestGenerateMmapCommand")
files := strings.Split(filenames, ",")
for _, file := range files {
var triggerEBPFCommand strings.Builder
template := template.Must(template.New("trigger").Parse(triggerFileSecurityTemplate))
if err := template.Execute(&triggerEBPFCommand, map[string]interface{}{
"WorkDir": config.TestConfig.WorkDir,
"CommandCnt": commandCnt,
"FileName": file,
"Command": mmapFileCommand,
}); err != nil {
return err
}
if _, err := setup.Env.ExecOnSource(ctx, triggerEBPFCommand.String()); err != nil {
mmapFileCommand := trigger.GetRunTriggerCommand("mmap", "commandCnt", strconv.FormatInt(int64(commandCnt), 10), "filename", file)
if _, err := setup.Env.ExecOnSource(ctx, mmapFileCommand); err != nil {
return err
}
}
Expand Down
114 changes: 0 additions & 114 deletions test/engine/trigger/file.go

This file was deleted.

Loading
Loading