diff --git a/.changes/v0.5.31.md b/.changes/v0.5.31.md new file mode 100644 index 000000000..a0299818c --- /dev/null +++ b/.changes/v0.5.31.md @@ -0,0 +1,3 @@ +## v0.5.31 - 2024-07-12 +### Added +* dummy generator diff --git a/.mapping.json b/.mapping.json index db71f1193..ff86b40d9 100644 --- a/.mapping.json +++ b/.mapping.json @@ -28,6 +28,7 @@ ".changes/v0.5.28.md":"load/projects/pandora/.changes/v0.5.28.md", ".changes/v0.5.29.md":"load/projects/pandora/.changes/v0.5.29.md", ".changes/v0.5.30.md":"load/projects/pandora/.changes/v0.5.30.md", + ".changes/v0.5.31.md":"load/projects/pandora/.changes/v0.5.31.md", ".changie.yaml":"load/projects/pandora/.changie.yaml", ".github/actions/setup-yc/action.yml":"load/projects/pandora/.github/actions/setup-yc/action.yml", ".github/workflows/pages.yml":"load/projects/pandora/.github/workflows/pages.yml", @@ -45,6 +46,7 @@ "cli/cli.go":"load/projects/pandora/cli/cli.go", "cli/expvar.go":"load/projects/pandora/cli/expvar.go", "components/grpc/import/import.go":"load/projects/pandora/components/grpc/import/import.go", + "components/guns/dummy/generator.go":"load/projects/pandora/components/guns/dummy/generator.go", "components/guns/grpc/core.go":"load/projects/pandora/components/guns/grpc/core.go", "components/guns/grpc/core_test.go":"load/projects/pandora/components/guns/grpc/core_test.go", "components/guns/grpc/scenario/ammo.go":"load/projects/pandora/components/guns/grpc/scenario/ammo.go", @@ -72,6 +74,7 @@ "components/guns/http_scenario/mock_client_test.go":"load/projects/pandora/components/guns/http_scenario/mock_client_test.go", "components/guns/http_scenario/new.go":"load/projects/pandora/components/guns/http_scenario/new.go", "components/guns/http_scenario/templater.go":"load/projects/pandora/components/guns/http_scenario/templater.go", + "components/guns/import.go":"load/projects/pandora/components/guns/import.go", "components/phttp/import/import.go":"load/projects/pandora/components/phttp/import/import.go", "components/phttp/import/import_test.go":"load/projects/pandora/components/phttp/import/import_test.go", "components/providers/base/provider.go":"load/projects/pandora/components/providers/base/provider.go", @@ -545,6 +548,7 @@ "tests/acceptance/common.go":"load/projects/pandora/tests/acceptance/common.go", "tests/acceptance/config_model.go":"load/projects/pandora/tests/acceptance/config_model.go", "tests/acceptance/connect_test.go":"load/projects/pandora/tests/acceptance/connect_test.go", + "tests/acceptance/dummy_test.go":"load/projects/pandora/tests/acceptance/dummy_test.go", "tests/acceptance/grpc_test.go":"load/projects/pandora/tests/acceptance/grpc_test.go", "tests/acceptance/http_scenario_test.go":"load/projects/pandora/tests/acceptance/http_scenario_test.go", "tests/acceptance/http_test.go":"load/projects/pandora/tests/acceptance/http_test.go", @@ -555,6 +559,7 @@ "tests/acceptance/testdata/connect/connect.yaml":"load/projects/pandora/tests/acceptance/testdata/connect/connect.yaml", "tests/acceptance/testdata/connect/payload.uri":"load/projects/pandora/tests/acceptance/testdata/connect/payload.uri", "tests/acceptance/testdata/connect/payload5.uri":"load/projects/pandora/tests/acceptance/testdata/connect/payload5.uri", + "tests/acceptance/testdata/dummy/dummy.yaml":"load/projects/pandora/tests/acceptance/testdata/dummy/dummy.yaml", "tests/acceptance/testdata/grpc/base.yaml":"load/projects/pandora/tests/acceptance/testdata/grpc/base.yaml", "tests/acceptance/testdata/grpc/grpc.payload":"load/projects/pandora/tests/acceptance/testdata/grpc/grpc.payload", "tests/acceptance/testdata/http/http-check-limit.yaml":"load/projects/pandora/tests/acceptance/testdata/http/http-check-limit.yaml", diff --git a/CHANGELOG.md b/CHANGELOG.md index fbbc1eb8c..d59c336f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). +## v0.5.31 - 2024-07-12 +### Added +* dummy generator + ## v0.5.30 - 2024-07-10 ### Added * new monitoring metric - engine_LastMaxActiveRequests diff --git a/cli/cli.go b/cli/cli.go index 0e0082e7f..350cda29a 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -25,7 +25,7 @@ import ( "go.uber.org/zap/zapcore" ) -const Version = "0.5.30" +const Version = "0.5.31" const defaultConfigFile = "load" const stdinConfigSelector = "-" diff --git a/components/guns/dummy/generator.go b/components/guns/dummy/generator.go new file mode 100644 index 000000000..56ed4f86b --- /dev/null +++ b/components/guns/dummy/generator.go @@ -0,0 +1,56 @@ +package dummy + +import ( + "time" + + "github.com/yandex/pandora/core" + "github.com/yandex/pandora/core/aggregator/netsample" + "github.com/yandex/pandora/core/warmup" +) + +type GunConfig struct { + Sleep time.Duration `config:"sleep"` +} + +type Gun struct { + DebugLog bool + Conf GunConfig + Aggr core.Aggregator + core.GunDeps +} + +func DefaultGunConfig() GunConfig { + return GunConfig{} +} + +func (g *Gun) WarmUp(_ *warmup.Options) (any, error) { + return nil, nil +} + +func NewGun(conf GunConfig) *Gun { + return &Gun{Conf: conf} +} + +func (g *Gun) Bind(aggr core.Aggregator, deps core.GunDeps) error { + g.Aggr = aggr + g.GunDeps = deps + return nil +} + +func (g *Gun) Shoot(_ core.Ammo) { + g.shoot() +} + +func (g *Gun) shoot() { + code := 0 + sample := netsample.Acquire("") + defer func() { + sample.SetProtoCode(code) + g.Aggr.Report(sample) + }() + + time.Sleep(g.Conf.Sleep) + code = 200 +} + +var _ warmup.WarmedUp = (*Gun)(nil) diff --git a/components/guns/import.go b/components/guns/import.go new file mode 100644 index 000000000..2bcd7b779 --- /dev/null +++ b/components/guns/import.go @@ -0,0 +1,11 @@ +package guns + +import ( + "github.com/spf13/afero" + "github.com/yandex/pandora/components/guns/dummy" + "github.com/yandex/pandora/core/register" +) + +func Import(fs afero.Fs) { + register.Gun("dummy", dummy.NewGun, dummy.DefaultGunConfig) +} diff --git a/docs/content/en/get-started/architecture.md b/docs/content/en/get-started/architecture.md index 2224c0e55..f8a229541 100644 --- a/docs/content/en/get-started/architecture.md +++ b/docs/content/en/get-started/architecture.md @@ -8,10 +8,10 @@ weight: 14 ## Architectural scheme -You can download architectural scheme source [here](../images/architecture.graphml). +You can download architectural scheme source [here](../../images/architecture.graphml). Open it with [YeD](https://www.yworks.com/en/products/yfiles/yed/) editor. -![architectural scheme](../images/architecture.png) +![architectural scheme](../../images/architecture.png) Pandora is a set of components talking to each other through Go channels. There are different types of components. diff --git a/docs/content/ru/get-started/architecture.md b/docs/content/ru/get-started/architecture.md index 6a695801f..c9030b51e 100644 --- a/docs/content/ru/get-started/architecture.md +++ b/docs/content/ru/get-started/architecture.md @@ -8,10 +8,10 @@ weight: 14 ## Схема -Код схемы доступен [здесь](../../images/architecture.graphml). +Код схемы доступен [здесь](../../../images/architecture.graphml). Его можно открыть и редактировать в редакторе [YeD](https://www.yworks.com/en/products/yfiles/yed/). -![architectural scheme](../../images/architecture.png) +![architectural scheme](../../../images/architecture.png) Pandora - это набор компонентов, взаимодействующих друг с другом с помощью Go каналов. diff --git a/main.go b/main.go index 8c25937e8..b080b29df 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "github.com/spf13/afero" "github.com/yandex/pandora/cli" grpc "github.com/yandex/pandora/components/grpc/import" + "github.com/yandex/pandora/components/guns" phttp "github.com/yandex/pandora/components/phttp/import" coreimport "github.com/yandex/pandora/core/import" ) @@ -15,6 +16,7 @@ func main() { coreimport.Import(fs) phttp.Import(fs) grpc.Import(fs) + guns.Import(fs) cli.Run() } diff --git a/tests/acceptance/common.go b/tests/acceptance/common.go index 018e928b1..5caf9a1c0 100644 --- a/tests/acceptance/common.go +++ b/tests/acceptance/common.go @@ -8,13 +8,27 @@ import ( "testing" "text/template" + "github.com/spf13/afero" "github.com/stretchr/testify/require" "github.com/yandex/pandora/cli" + grpc "github.com/yandex/pandora/components/grpc/import" + "github.com/yandex/pandora/components/guns" + phttpimport "github.com/yandex/pandora/components/phttp/import" "github.com/yandex/pandora/core" "github.com/yandex/pandora/core/config" + coreimport "github.com/yandex/pandora/core/import" "gopkg.in/yaml.v2" ) +func importDependencies(fs afero.Fs) func() { + return func() { + coreimport.Import(fs) + phttpimport.Import(fs) + grpc.Import(fs) + guns.Import(fs) + } +} + func parseConfigFile(t *testing.T, filename string, serverAddr string) *cli.CliConfig { t.Helper() mapCfg := unmarshalConfigFile(t, filename, serverAddr) diff --git a/tests/acceptance/connect_test.go b/tests/acceptance/connect_test.go index cb6e38faf..066f09a3c 100644 --- a/tests/acceptance/connect_test.go +++ b/tests/acceptance/connect_test.go @@ -8,10 +8,7 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/suite" - grpc "github.com/yandex/pandora/components/grpc/import" - phttpimport "github.com/yandex/pandora/components/phttp/import" "github.com/yandex/pandora/core/engine" - coreimport "github.com/yandex/pandora/core/import" "github.com/yandex/pandora/lib/testutil" "go.uber.org/atomic" "go.uber.org/zap" @@ -30,11 +27,7 @@ type ConnectGunSuite struct { func (s *ConnectGunSuite) SetupSuite() { s.fs = afero.NewOsFs() - testOnce.Do(func() { - coreimport.Import(s.fs) - phttpimport.Import(s.fs) - grpc.Import(s.fs) - }) + testOnce.Do(importDependencies(s.fs)) s.log = testutil.NewNullLogger() s.metrics = engine.NewMetrics("connect_suite") @@ -53,7 +46,7 @@ func (s *ConnectGunSuite) Test_Connect() { name: "http", filecfg: "testdata/connect/connect.yaml", isTLS: false, - wantCnt: 4, + wantCnt: 6, }, { name: "http-check-limits", diff --git a/tests/acceptance/dummy_test.go b/tests/acceptance/dummy_test.go new file mode 100644 index 000000000..c9799ff45 --- /dev/null +++ b/tests/acceptance/dummy_test.go @@ -0,0 +1,68 @@ +package acceptance + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/spf13/afero" + "github.com/stretchr/testify/suite" + "github.com/yandex/pandora/core/engine" + "github.com/yandex/pandora/lib/testutil" + "go.uber.org/zap" +) + +func TestDummyGunSuite(t *testing.T) { + suite.Run(t, new(DummyGunSuite)) +} + +type DummyGunSuite struct { + suite.Suite + fs afero.Fs + log *zap.Logger + metrics engine.Metrics +} + +func (s *DummyGunSuite) SetupSuite() { + s.fs = afero.NewOsFs() + testOnce.Do(importDependencies(s.fs)) + + s.log = testutil.NewNullLogger() + s.metrics = engine.NewMetrics("dummy_suite") +} + +func (s *DummyGunSuite) Test_Shoot() { + tests := []struct { + name string + filecfg string + isTLS bool + preStartSrv func(srv *httptest.Server) + wantErrContain string + wantCnt int + }{ + { + name: "dummy", + filecfg: "testdata/dummy/dummy.yaml", + wantCnt: 6, + }, + } + for _, tt := range tests { + s.Run(tt.name, func() { + + conf := parseConfigFile(s.T(), tt.filecfg, "") + s.Require().Equal(1, len(conf.Engine.Pools)) + aggr := &aggregator{} + conf.Engine.Pools[0].Aggregator = aggr + pandora := engine.New(s.log, s.metrics, conf.Engine) + + err := pandora.Run(context.Background()) + if tt.wantErrContain != "" { + s.Require().Error(err) + s.Require().Contains(err.Error(), tt.wantErrContain) + return + } + s.Require().NoError(err) + s.Require().Equal(int64(tt.wantCnt), int64(len(aggr.samples))) + }) + } +} diff --git a/tests/acceptance/grpc_test.go b/tests/acceptance/grpc_test.go index 0fdf8398e..a12101f28 100644 --- a/tests/acceptance/grpc_test.go +++ b/tests/acceptance/grpc_test.go @@ -14,10 +14,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/yandex/pandora/cli" - grpcimport "github.com/yandex/pandora/components/grpc/import" - phttpimport "github.com/yandex/pandora/components/phttp/import" "github.com/yandex/pandora/core/engine" - coreimport "github.com/yandex/pandora/core/import" "github.com/yandex/pandora/examples/grpc/server" "github.com/yandex/pandora/lib/pointer" "github.com/yandex/pandora/lib/testutil" @@ -30,11 +27,7 @@ import ( func TestCheckGRPCReflectServer(t *testing.T) { fs := afero.NewOsFs() - testOnce.Do(func() { - coreimport.Import(fs) - phttpimport.Import(fs) - grpcimport.Import(fs) - }) + testOnce.Do(importDependencies(fs)) pandoraLogger := testutil.NewNullLogger() pandoraMetrics := engine.NewMetrics("reflect") baseFile, err := os.ReadFile("testdata/grpc/base.yaml") @@ -215,11 +208,7 @@ type GrpcGunSuite struct { func (s *GrpcGunSuite) SetupSuite() { s.fs = afero.NewOsFs() - testOnce.Do(func() { - coreimport.Import(s.fs) - phttpimport.Import(s.fs) - grpcimport.Import(s.fs) - }) + testOnce.Do(importDependencies(s.fs)) s.log = testutil.NewNullLogger() s.metrics = engine.NewMetrics("grpc_suite") diff --git a/tests/acceptance/http_scenario_test.go b/tests/acceptance/http_scenario_test.go index 0681114a6..546a1eb02 100644 --- a/tests/acceptance/http_scenario_test.go +++ b/tests/acceptance/http_scenario_test.go @@ -9,10 +9,7 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/suite" - grpc "github.com/yandex/pandora/components/grpc/import" - phttpimport "github.com/yandex/pandora/components/phttp/import" "github.com/yandex/pandora/core/engine" - coreimport "github.com/yandex/pandora/core/import" "github.com/yandex/pandora/examples/http/server" "github.com/yandex/pandora/lib/testutil" "go.uber.org/zap" @@ -33,11 +30,7 @@ type HTTPScenarioSuite struct { func (s *HTTPScenarioSuite) SetupSuite() { s.fs = afero.NewOsFs() - testOnce.Do(func() { - coreimport.Import(s.fs) - phttpimport.Import(s.fs) - grpc.Import(s.fs) - }) + testOnce.Do(importDependencies(s.fs)) s.log = testutil.NewNullLogger() s.metrics = engine.NewMetrics("http_scenario_suite") diff --git a/tests/acceptance/http_test.go b/tests/acceptance/http_test.go index 4ae65c750..38ed1b786 100644 --- a/tests/acceptance/http_test.go +++ b/tests/acceptance/http_test.go @@ -9,10 +9,7 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/suite" - grpc "github.com/yandex/pandora/components/grpc/import" - phttpimport "github.com/yandex/pandora/components/phttp/import" "github.com/yandex/pandora/core/engine" - coreimport "github.com/yandex/pandora/core/import" "github.com/yandex/pandora/lib/testutil" "go.uber.org/atomic" "go.uber.org/zap" @@ -34,11 +31,7 @@ type PandoraSuite struct { func (s *PandoraSuite) SetupSuite() { s.fs = afero.NewOsFs() - testOnce.Do(func() { - coreimport.Import(s.fs) - phttpimport.Import(s.fs) - grpc.Import(s.fs) - }) + testOnce.Do(importDependencies(s.fs)) s.log = testutil.NewNullLogger() s.metrics = engine.NewMetrics("http_suite") diff --git a/tests/acceptance/testdata/connect/connect.yaml b/tests/acceptance/testdata/connect/connect.yaml index 323a9cfd2..c5e9fdb36 100644 --- a/tests/acceptance/testdata/connect/connect.yaml +++ b/tests/acceptance/testdata/connect/connect.yaml @@ -14,7 +14,7 @@ pools: rps: - times: 2 type: once - - duration: 0.5s + - duration: 1s ops: 4 type: const startup: diff --git a/tests/acceptance/testdata/dummy/dummy.yaml b/tests/acceptance/testdata/dummy/dummy.yaml new file mode 100644 index 000000000..8677b3e7e --- /dev/null +++ b/tests/acceptance/testdata/dummy/dummy.yaml @@ -0,0 +1,21 @@ +pools: + - id: "dummy" + ammo: + type: dummy + result: + type: discard + gun: + type: dummy + sleep: 10ms + rps-per-instance: false + rps: + - times: 2 + type: once + - duration: 1s + ops: 4 + type: const + startup: + - times: 2 + type: once +log: + level: debug