Skip to content

Commit

Permalink
dummy generator
Browse files Browse the repository at this point in the history
b276c49de282319efa7c7acceeaf4ac385cd268a
  • Loading branch information
oke11o committed Jul 17, 2024
1 parent dc6574a commit 648b637
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .changes/v0.5.31.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.5.31 - 2024-07-12
### Added
* dummy generator
5 changes: 5 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "-"

Expand Down
56 changes: 56 additions & 0 deletions components/guns/dummy/generator.go
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions components/guns/import.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 2 additions & 2 deletions docs/content/en/get-started/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions docs/content/ru/get-started/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 каналов.

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -15,6 +16,7 @@ func main() {
coreimport.Import(fs)
phttp.Import(fs)
grpc.Import(fs)
guns.Import(fs)

cli.Run()
}
14 changes: 14 additions & 0 deletions tests/acceptance/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions tests/acceptance/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -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",
Expand Down
68 changes: 68 additions & 0 deletions tests/acceptance/dummy_test.go
Original file line number Diff line number Diff line change
@@ -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)))
})
}
}
15 changes: 2 additions & 13 deletions tests/acceptance/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 1 addition & 8 deletions tests/acceptance/http_scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
9 changes: 1 addition & 8 deletions tests/acceptance/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/testdata/connect/connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pools:
rps:
- times: 2
type: once
- duration: 0.5s
- duration: 1s
ops: 4
type: const
startup:
Expand Down
Loading

0 comments on commit 648b637

Please sign in to comment.