Skip to content

Commit

Permalink
add file-to-blackhole ilogtail benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Assassin718 committed Jul 11, 2024
1 parent 4e25935 commit 88ebf59
Show file tree
Hide file tree
Showing 13 changed files with 530 additions and 35 deletions.
3 changes: 2 additions & 1 deletion licenses/LICENSE_OF_TESTENGINE_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ When distributed in a binary form, Logtailplugin Test Engine may contain portion
- [github.com/opencontainers/go-digest](https://pkg.go.dev/github.com/opencontainers/go-digest?tab=licenses)
- [github.com/opencontainers/image-spec](https://pkg.go.dev/github.com/opencontainers/image-spec?tab=licenses)
- [github.com/opencontainers/runc](https://pkg.go.dev/github.com/opencontainers/runc?tab=licenses)
- [google.golang.org/genproto](https://pkg.go.dev/google.golang.org/genproto?tab=licenses)
- [google.golang.org/grpc](https://pkg.go.dev/google.golang.org/grpc?tab=licenses)
- [gopkg.in/ini.v1](https://pkg.go.dev/gopkg.in/ini.v1?tab=licenses)
- [gopkg.in/yaml.v2](https://pkg.go.dev/gopkg.in/yaml.v2?tab=licenses)
Expand Down Expand Up @@ -46,6 +45,8 @@ When distributed in a binary form, Logtailplugin Test Engine may contain portion
- [sigs.k8s.io/json](https://pkg.go.dev/sigs.k8s.io/json?tab=licenses)
- [sigs.k8s.io/structured-merge-diff](https://pkg.go.dev/sigs.k8s.io/structured-merge-diff?tab=licenses)
- [sigs.k8s.io/yaml](https://pkg.go.dev/sigs.k8s.io/yaml?tab=licenses)
- [github.com/google/cadvisor](https://pkg.go.dev/github.com/google/cadvisor?tab=licenses)
- [google.golang.org/genproto/googleapis/rpc](https://pkg.go.dev/google.golang.org/genproto/googleapis/rpc?tab=licenses)

## BSD licenses

Expand Down
68 changes: 68 additions & 0 deletions test/benchmark/benchmark_docker_test.go
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()
}
}
123 changes: 123 additions & 0 deletions test/benchmark/main_test.go
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.
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"}
"""
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
1 change: 1 addition & 0 deletions test/engine/cleanup/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func All() {
_, _ = control.RemoveAllLocalConfig(ctx)
_, _ = AllGeneratedLog(ctx)
_, _ = GoTestCache(ctx)
_, _ = StopMonitor(ctx)
_, _ = DeleteContainers(ctx)
if subscriber.TestSubscriber != nil {
_ = subscriber.TestSubscriber.Stop()
Expand Down
11 changes: 11 additions & 0 deletions test/engine/cleanup/monitor.go
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)
}
Loading

0 comments on commit 88ebf59

Please sign in to comment.