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

Add Filter query configuration to Continuous Benchmark Job #2296

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions charts/vald-benchmark-operator/crds/valdbenchmarkjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ spec:
object_config:
type: object
properties:
filter_config:
type: object
properties:
host:
type: string
filter_configs:
type: array
items:
type: object
x-kubernetes-preserve-unknown-fields: true
remove_config:
type: object
properties:
Expand Down
17 changes: 8 additions & 9 deletions charts/vald-benchmark-operator/schemas/job-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,14 @@ remove_config:
# @schema {"name": "object_config", "type": "object"}
# object_config -- object config
object_config:
# @schema {"name": "object_config.filter_config", "type": "object"}
# object_config.filter_config -- filter target config
filter_config:
# @schema {"name": "object_config.filter_config.host", "type": "string"}
# object_config.filter_config.host -- filter target host
host: 0.0.0.0
# @schema {"name": "object_config.filter_config.host", "type": "integer"}
# object_config.filter_config.port -- filter target host
port: 8081
# @schema {"name": "object_config.filter_configs", "type": "array", "items": {"type": "object"}}
# object_config.filter_configs -- filter configs
filter_configs:
- target:
host: 0.0.0.0
port: 8081
query:
query: ""
# @schema {"name": "client_config", "type": "object"}
# client_config -- gRPC client config for request to the Vald cluster
client_config:
Expand Down
33 changes: 28 additions & 5 deletions internal/config/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@

// ObjectConfig defines the desired state of object config
type ObjectConfig struct {
FilterConfig FilterConfig `json:"filter_config,omitempty" yaml:"filter_config"`
FilterConfigs []*FilterConfig `json:"filter_configs,omitempty" yaml:"filter_configs"`
}

func (cfg *ObjectConfig) Bind() *ObjectConfig {
cfg.FilterConfig = *cfg.FilterConfig.Bind()
for i := 0; i < len(cfg.FilterConfigs); i++ {
if cfg.FilterConfigs[i] != nil {
cfg.FilterConfigs[i] = cfg.FilterConfigs[i].Bind()
}

Check warning on line 166 in internal/config/benchmark.go

View check run for this annotation

Codecov / codecov/patch

internal/config/benchmark.go#L163-L166

Added lines #L163 - L166 were not covered by tests
}
return cfg
}

Expand All @@ -175,14 +179,33 @@
return cfg
}

// FilterQuery defines the query passed to filter target.
type FilterQuery struct {
Query string `json:"query,omitempty" yaml:"query"`
}

func (cfg *FilterQuery) Bind() *FilterQuery {
cfg.Query = GetActualValue(cfg.Query)
return cfg

Check warning on line 189 in internal/config/benchmark.go

View check run for this annotation

Codecov / codecov/patch

internal/config/benchmark.go#L187-L189

Added lines #L187 - L189 were not covered by tests
}

// FilterConfig defines the desired state of filter config
type FilterConfig struct {
Targets []*FilterTarget `json:"target,omitempty" yaml:"target"`
Target *FilterTarget `json:"target,omitempty" yaml:"target"`
Query *FilterQuery `json:"query,omitempty" yaml:"query"`
}

func (cfg *FilterConfig) Bind() *FilterConfig {
for i := 0; i < len(cfg.Targets); i++ {
cfg.Targets[i] = cfg.Targets[i].Bind()
if cfg.Target != nil {
cfg.Target = cfg.Target.Bind()
} else {
cfg.Target = (&FilterTarget{}).Bind()
}

Check warning on line 203 in internal/config/benchmark.go

View check run for this annotation

Codecov / codecov/patch

internal/config/benchmark.go#L199-L203

Added lines #L199 - L203 were not covered by tests

if cfg.Query != nil {
cfg.Query = cfg.Query.Bind()
} else {
cfg.Query = (&FilterQuery{}).Bind()

Check warning on line 208 in internal/config/benchmark.go

View check run for this annotation

Codecov / codecov/patch

internal/config/benchmark.go#L205-L208

Added lines #L205 - L208 were not covered by tests
}
return cfg
}
Expand Down
31 changes: 23 additions & 8 deletions pkg/tools/benchmark/job/service/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,29 @@ func (j *job) getObject(ctx context.Context, ech chan error) error {
eg.SetLimit(j.concurrencyLimit)
for i := j.dataset.Range.Start; i <= j.dataset.Range.End; i++ {
log.Infof("[benchmark job] Start get object: iter = %d", i)
ft := []*payload.Filter_Target{}
fcfgs := []*payload.Filter_Config{}
if j.objectConfig != nil {
for i, target := range j.objectConfig.FilterConfig.Targets {
ft[i] = &payload.Filter_Target{
Host: target.Host,
Port: uint32(target.Port),
for _, cfg := range j.objectConfig.FilterConfigs {
if cfg != nil {
var (
target *payload.Filter_Target
query *payload.Filter_Query
)
if cfg.Target != nil {
target = &payload.Filter_Target{
Host: cfg.Target.Host,
Port: uint32(cfg.Target.Port),
}
}
if cfg.Query != nil {
query = &payload.Filter_Query{
Query: cfg.Query.Query,
}
}
fcfgs = append(fcfgs, &payload.Filter_Config{
Target: target,
Query: query,
})
}
}
}
Expand All @@ -108,9 +125,7 @@ func (j *job) getObject(ctx context.Context, ech chan error) error {
Id: &payload.Object_ID{
Id: strconv.Itoa(idx),
},
Filters: &payload.Filter_Config{
Targets: ft,
},
Filters: fcfgs,
})
if err != nil {
select {
Expand Down
Loading