-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add file-to-blockhole ilogtail benchmark
- Loading branch information
1 parent
4e25935
commit 5d85ef1
Showing
12 changed files
with
526 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2024 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 e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cucumber/godog" | ||
) | ||
|
||
func TestE2EOnDockerCompose(t *testing.T) { | ||
suite := godog.TestSuite{ | ||
Name: "E2EOnDockerCompose", | ||
ScenarioInitializer: scenarioInitializer, | ||
Options: &godog.Options{ | ||
Format: "pretty", | ||
Paths: []string{"test_cases"}, | ||
Tags: "@e2e && @docker-compose && ~@ebpf", | ||
TestingT: t, | ||
}, | ||
} | ||
if suite.Run() != 0 { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestE2EOnDockerComposeCore(t *testing.T) { | ||
suite := godog.TestSuite{ | ||
Name: "E2EOnDockerCompose", | ||
ScenarioInitializer: scenarioInitializer, | ||
Options: &godog.Options{ | ||
Format: "pretty", | ||
Paths: []string{"test_cases"}, | ||
Tags: "@e2e-core && @docker-compose && ~@ebpf", | ||
TestingT: t, | ||
}, | ||
} | ||
if suite.Run() != 0 { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestE2EOnDockerComposePerformance(t *testing.T) { | ||
suite := godog.TestSuite{ | ||
Name: "E2EOnDockerCompose", | ||
ScenarioInitializer: scenarioInitializer, | ||
Options: &godog.Options{ | ||
Format: "pretty", | ||
Paths: []string{"test_cases"}, | ||
Tags: "@e2e-performance && @docker-compose && ~@ebpf", | ||
TestingT: t, | ||
}, | ||
} | ||
if suite.Run() != 0 { | ||
t.Fail() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2024 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 e2e | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cucumber/godog" | ||
|
||
"github.com/alibaba/ilogtail/pkg/logger" | ||
"github.com/alibaba/ilogtail/test/config" | ||
"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/verify" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
loggerOptions := []logger.ConfigOption{ | ||
logger.OptionAsyncLogger, | ||
} | ||
loggerOptions = append(loggerOptions, logger.OptionInfoLevel) | ||
logger.InitTestLogger(loggerOptions...) | ||
|
||
config.TestConfig = config.Config{} | ||
// Log | ||
config.TestConfig.GeneratedLogDir = os.Getenv("GENERATED_LOG_DIR") | ||
if len(config.TestConfig.GeneratedLogDir) == 0 { | ||
config.TestConfig.GeneratedLogDir = "/tmp/ilogtail" | ||
} | ||
config.TestConfig.WorkDir = os.Getenv("WORK_DIR") | ||
|
||
// SSH | ||
config.TestConfig.SSHUsername = os.Getenv("SSH_USERNAME") | ||
config.TestConfig.SSHIP = os.Getenv("SSH_IP") | ||
config.TestConfig.SSHPassword = os.Getenv("SSH_PASSWORD") | ||
|
||
// K8s | ||
config.TestConfig.KubeConfigPath = os.Getenv("KUBE_CONFIG_PATH") | ||
|
||
// SLS | ||
config.TestConfig.Project = os.Getenv("PROJECT") | ||
config.TestConfig.Logstore = os.Getenv("LOGSTORE") | ||
config.TestConfig.AccessKeyID = os.Getenv("ACCESS_KEY_ID") | ||
config.TestConfig.AccessKeySecret = os.Getenv("ACCESS_KEY_SECRET") | ||
config.TestConfig.Endpoint = os.Getenv("ENDPOINT") | ||
config.TestConfig.Aliuid = os.Getenv("ALIUID") | ||
config.TestConfig.QueryEndpoint = os.Getenv("QUERY_ENDPOINT") | ||
config.TestConfig.Region = os.Getenv("REGION") | ||
timeout, err := strconv.ParseInt(os.Getenv("RETRY_TIMEOUT"), 10, 64) | ||
if err != nil { | ||
timeout = 60 | ||
} | ||
config.TestConfig.RetryTimeout = time.Duration(timeout) * time.Second | ||
code := m.Run() | ||
logger.Flush() | ||
os.Exit(code) | ||
} | ||
|
||
func scenarioInitializer(ctx *godog.ScenarioContext) { | ||
// Given | ||
ctx.Given(`^\{(\S+)\} environment$`, setup.InitEnv) | ||
ctx.Given(`^iLogtail depends on containers \{(.*)\}`, setup.SetDockerComposeDependOn) | ||
ctx.Given(`^iLogtail container mount \{(.*)\} to \{(.*)\}`, setup.MountVolume) | ||
ctx.Given(`^iLogtail expose port \{(.*)\} to \{(.*)\}`, setup.ExposePort) | ||
ctx.Given(`^\{(.*)\} local config as below`, control.AddLocalConfig) | ||
ctx.Given(`^\{(.*)\} http config as below`, control.AddHTTPConfig) | ||
ctx.Given(`^remove http config \{(.*)\}`, control.RemoveHTTPConfig) | ||
ctx.Given(`^subcribe data from \{(\S+)\} with config`, subscriber.InitSubscriber) | ||
|
||
// When | ||
ctx.When(`^generate \{(\d+)\} regex logs, with interval \{(\d+)\}ms$`, trigger.RegexSingle) | ||
ctx.When(`^generate logs to file, speed \{(\d+)\}MB/s, total \{(\d+)\}min, to file \{(.*)\}, template`, trigger.GenerateLogToFile) | ||
ctx.When(`^generate \{(\d+)\} http logs, with interval \{(\d+)\}ms, url: \{(.*)\}, method: \{(.*)\}, body:`, trigger.HTTP) | ||
ctx.When(`^add k8s label \{(.*)\}`, control.AddLabel) | ||
ctx.When(`^remove k8s label \{(.*)\}`, control.RemoveLabel) | ||
ctx.When(`^start docker-compose \{(\S+)\}`, setup.StartDockerComposeEnv) | ||
ctx.When(`^start monitor \{(\S+)\}`, monitor.StartMonitor) | ||
|
||
// Then | ||
ctx.Then(`^there is \{(\d+)\} logs$`, verify.LogCount) | ||
ctx.Then(`^there is at least \{(\d+)\} logs$`, verify.LogCountAtLeast) | ||
ctx.Then(`^there is at least \{(\d+)\} logs with filter key \{(.*)\} value \{(.*)\}$`, verify.LogCountAtLeastWithFilter) | ||
ctx.Then(`^the log fields match regex single`, verify.RegexSingle) | ||
ctx.Then(`^the log fields match kv`, verify.LogFieldKV) | ||
ctx.Then(`^the log tags match kv`, verify.TagKV) | ||
ctx.Then(`^the context of log is valid$`, verify.LogContext) | ||
ctx.Then(`^the log fields match`, verify.LogField) | ||
ctx.Then(`^the log labels match`, verify.LogLabel) | ||
ctx.Then(`^the logtail log contains \{(\d+)\} times of \{(.*)\}$`, verify.LogtailPluginLog) | ||
ctx.Then(`wait \{(\d+)\} seconds`, func(ctx context.Context, t int) context.Context { | ||
time.Sleep(time.Duration(t) * time.Second) | ||
return ctx | ||
}) | ||
|
||
// Cleanup | ||
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { | ||
cleanup.HandleSignal() | ||
return ctx, nil | ||
}) | ||
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) { | ||
cleanup.All() | ||
return ctx, nil | ||
}) | ||
} |
Empty file.
39 changes: 39 additions & 0 deletions
39
test/benchmark/test_cases/performance_file_to_blackhole_ilogtail/case.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@input | ||
Feature: performance file to blackhole iLogtail | ||
Performance file to blackhole iLogtail | ||
|
||
@e2e-performance @docker-compose | ||
Scenario: PerformanceFileToBlackholeiLogtail | ||
Given {docker-compose} environment | ||
Given subcribe data from {grpc} with config | ||
""" | ||
""" | ||
Given {performance-file-to-blackhole-ilogtail-case} local config as below | ||
""" | ||
enable: true | ||
inputs: | ||
- Type: input_file | ||
FilePaths: | ||
- /home/test-log/json.log | ||
processors: | ||
- Type: processor_parse_json_native | ||
SourceKey: content | ||
- Type: processor_filter_regex_native | ||
FilterKey: | ||
- user-agent | ||
FilterRegex: | ||
- ^no-agent$ | ||
flushers: | ||
- Type: flusher_sls | ||
Region: cn-hangzhou | ||
Endpoint: cn-hangzhou.log.aliyuncs.com | ||
Project: test_project | ||
Logstore: test_logstore | ||
""" | ||
Given iLogtail container mount {./a.log} to {/home/test-log/json.log} | ||
When start docker-compose {performance_file_to_blackhole_ilogtail} | ||
When start monitor {e2e-ilogtailC-1} | ||
When generate logs to file, speed {10}MB/s, total {3}min, to file {./a.log}, template | ||
""" | ||
{"url": "POST /PutData?Category=YunOsAccountOpLog HTTP/1.1", "ip": "10.200.98.220", "user-agent": "aliyun-sdk-java", "request": {"status": "200", "latency": "18204"}, "time": "07/Jul/2022:10:30:28"} | ||
""" |
31 changes: 31 additions & 0 deletions
31
test/benchmark/test_cases/performance_file_to_blackhole_ilogtail/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2021 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. | ||
|
||
version: '3.8' | ||
|
||
services: | ||
cadvisor: | ||
image: gcr.io/cadvisor/cadvisor:v0.49.1 | ||
volumes: | ||
- /:/rootfs:ro | ||
- /var/run:/var/run:ro | ||
- /sys:/sys:ro | ||
- /var/lib/docker/:/var/lib/docker:ro | ||
- /dev/disk/:/dev/disk:ro | ||
ports: | ||
- "8080:8080" | ||
privileged: true | ||
devices: | ||
- /dev/kmsg | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cleanup | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/alibaba/ilogtail/test/engine/setup/monitor" | ||
) | ||
|
||
func StopMonitor(ctx context.Context) (context.Context, error) { | ||
return monitor.StopMonitor(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package monitor | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/google/cadvisor/client" | ||
v1 "github.com/google/cadvisor/info/v1" | ||
|
||
"github.com/alibaba/ilogtail/test/config" | ||
) | ||
|
||
const ( | ||
cadvisorURL = "http://localhost:8080/" | ||
interval = 3 | ||
) | ||
|
||
var stopCh chan bool | ||
var isMonitoring atomic.Bool | ||
|
||
func StartMonitor(ctx context.Context, containerName string) (context.Context, error) { | ||
stopCh = make(chan bool) | ||
isMonitoring.Store(true) | ||
// connect to cadvisor | ||
client, err := client.NewClient("http://localhost:8080/") | ||
if err != nil { | ||
return ctx, err | ||
} | ||
// 获取机器信息 | ||
_, err = client.MachineInfo() | ||
if err != nil { | ||
// 处理错误 | ||
return ctx, err | ||
} | ||
// fmt.Println("Machine Info:", machineInfo) | ||
fmt.Println("Start monitoring container:", containerName) | ||
go monitoring(client, containerName) | ||
return ctx, nil | ||
} | ||
|
||
func StopMonitor(ctx context.Context) (context.Context, error) { | ||
if isMonitoring.Load() { | ||
stopCh <- true | ||
} | ||
return ctx, nil | ||
} | ||
|
||
func monitoring(client *client.Client, containerName string) { | ||
// create csv file | ||
reportDir := config.CaseHome + "/report/" | ||
if _, err := os.Stat(reportDir); os.IsNotExist(err) { | ||
// 文件夹不存在,创建文件夹 | ||
err := os.MkdirAll(reportDir, 0755) // 使用适当的权限 | ||
if err != nil { | ||
log.Fatalf("Failed to create folder: %s", err) | ||
} | ||
} | ||
file, err := os.OpenFile(reportDir+"performance.csv", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644) | ||
if err != nil { | ||
fmt.Println("Error creating file:", err) | ||
return | ||
} | ||
defer file.Close() | ||
header := "CPU Usage Max(%),CPU Usage Avg(%), Memory Usage Max(MB), Memory Usage Avg(MB)\n" | ||
_, err = file.WriteString(header) | ||
if err != nil { | ||
fmt.Println("Error writring file header:", err) | ||
return | ||
} | ||
// new ticker | ||
ticker := time.NewTicker(interval * time.Second) | ||
defer ticker.Stop() | ||
// read from cadvisor per interval seconds | ||
request := &v1.ContainerInfoRequest{NumStats: 10} | ||
monitorStatistic := NewMonitorStatistic() | ||
for { | ||
select { | ||
case <-stopCh: | ||
fmt.Fprintln(file, monitorStatistic.cpu.maxVal, ",", monitorStatistic.cpu.avgVal, ",", monitorStatistic.mem.maxVal, ",", monitorStatistic.mem.avgVal) | ||
return | ||
case <-ticker.C: | ||
// 获取容器信息 | ||
containerInfo, err := client.DockerContainer(containerName, request) | ||
if err != nil { | ||
fmt.Println("Error getting container info:", err) | ||
return | ||
} | ||
for _, stat := range containerInfo.Stats { | ||
monitorStatistic.UpdateStatistic(stat) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.