Skip to content

Commit

Permalink
✨ Add search result aggregation option
Browse files Browse the repository at this point in the history
Signed-off-by: vankichi <[email protected]>
  • Loading branch information
vankichi committed Jun 14, 2023
1 parent 3a0d522 commit fd47989
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 17 deletions.
8 changes: 8 additions & 0 deletions charts/vald-benchmark-operator/crds/valdbenchmarkjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ spec:
search_config:
type: object
properties:
aggregation_algorithm:
type: string
enum:
- Unknown
- ConcurrentQueue
- SortSlice
- SortPoolSlice
- PairingHeap
enable_linear_search:
type: boolean
epsilon:
Expand Down
11 changes: 11 additions & 0 deletions charts/vald-benchmark-operator/job-values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@
"type": "object",
"description": "upsert config",
"properties": {
"aggregation_algorithm": {
"type": "string",
"description": "search result aggregation algorithm",
"enum": [
"Unknown",
"ConcurrentQueue",
"SortSlice",
"SortPoolSlice",
"PairingHeap"
]
},
"enable_linear_search": {
"type": "boolean",
"description": "enable linear search for calculation recall"
Expand Down
3 changes: 3 additions & 0 deletions charts/vald-benchmark-operator/schemas/job-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ search_config:
# @schema {"name": "search_config.enable_linear_search", "type": "boolean"}
# search_config.enable_linear_search -- enable linear search for calculation recall
enable_linear_search: true
# @schema {"name": "search_config.aggregation_algorithm", "type": "string", "enum": ["Unknown", "ConcurrentQueue", "SortSlice", "SortPoolSlice", "PairingHeap"]}
# search_config.aggregation_algorithm -- search result aggregation algorithm
aggregation_algorithm: "Unknown"

# @schema {"name": "remove_config", "type": "object"}
# remove_config -- remove config
Expand Down
2 changes: 1 addition & 1 deletion charts/vald-benchmark-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ image:
job_image:
# @schema {"name": "job_image.repository", "type": "string"}
# image.repository -- job image repository
repository: vdaas/vald-benchmark-operator
repository: vdaas/vald-benchmark-job
# @schema {"name": "job_image.tag", "type": "string"}
# image.tag -- image tag for job docker image
tag: v1.7.5
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ require (
golang.org/x/sync v0.2.0
golang.org/x/sys v0.8.0
golang.org/x/text v0.9.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.9.1
golang.org/x/time v0.3.0
gonum.org/v1/hdf5 v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -656,7 +657,6 @@ require (
golang.org/x/image v0.7.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/api v0.125.0 // indirect
Expand Down
14 changes: 8 additions & 6 deletions internal/config/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,18 @@ func (cfg *UpsertConfig) Bind() *UpsertConfig {

// SearchConfig defines the desired state of search config
type SearchConfig struct {
Epsilon float32 `json:"epsilon,omitempty"`
Radius float32 `json:"radius,omitempty"`
Num int32 `json:"num,omitempty"`
MinNum int32 `json:"min_num,omitempty"`
Timeout string `json:"timeout,omitempty"`
EnableLinearSearch bool `json:"enable_linear_search,omitempty"`
Epsilon float32 `json:"epsilon,omitempty"`
Radius float32 `json:"radius,omitempty"`
Num int32 `json:"num,omitempty"`
MinNum int32 `json:"min_num,omitempty"`
Timeout string `json:"timeout,omitempty"`
EnableLinearSearch bool `json:"enable_linear_search,omitempty"`
AggregationAlgorithm string `json:"aggregation_algorithm,omitempty"`
}

func (cfg *SearchConfig) Bind() *SearchConfig {
cfg.Timeout = GetActualValue(cfg.Timeout)
cfg.AggregationAlgorithm = GetActualValue(cfg.AggregationAlgorithm)
return cfg
}

Expand Down
3 changes: 1 addition & 2 deletions internal/k8s/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// JobWatcher is a type alias for k8s resource controller.
Expand Down Expand Up @@ -153,7 +152,7 @@ func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) {

// Watches returns the kind of the job and the event handler.
// It will always return nil.
func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) {
func (r *reconciler) Watches() (client.Object, handler.EventHandler, []builder.WatchesOption) {
// return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{}
return nil, nil, nil
}
3 changes: 1 addition & 2 deletions internal/k8s/vald/benchmark/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/scheme"
"sigs.k8s.io/controller-runtime/pkg/source"
)

type BenchmarkJobWatcher k8s.ResourceController
Expand Down Expand Up @@ -134,7 +133,7 @@ func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) {
return nil, nil
}

func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) {
func (r *reconciler) Watches() (client.Object, handler.EventHandler, []builder.WatchesOption) {
// return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{}
return nil, nil, nil
}
6 changes: 3 additions & 3 deletions internal/k8s/vald/benchmark/scenario/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

type BenchmarkScenarioWatcher k8s.ResourceController
Expand Down Expand Up @@ -122,7 +121,8 @@ func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) {
return nil, nil
}

func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) {
func (r *reconciler) Watches() (client.Object, handler.EventHandler, []builder.WatchesOption) {
// return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{}
return &source.Kind{Type: new(v1.ValdBenchmarkScenario)}, &handler.EnqueueRequestForObject{}, nil
// return &source.Kind{Type: new(v1.ValdBenchmarkScenario)}, &handler.EnqueueRequestForObject{}, nil
return nil, &handler.EnqueueRequestForObject{}, nil
}
2 changes: 1 addition & 1 deletion k8s/tools/benchmark/operator/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ data:
enabled: false
sampling_rate: 1
job_image:
image: "local-registry:5000/vdaas/vald-benchmark-job"
image: "vdaas/vald-benchmark-job:v1.7.5"
pullPolicy: Always
8 changes: 8 additions & 0 deletions k8s/tools/benchmark/operator/crds/valdbenchmarkjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ spec:
search_config:
type: object
properties:
aggregation_algorithm:
type: string
enum:
- Unknown
- ConcurrentQueue
- SortSlice
- SortPoolSlice
- PairingHeap
enable_linear_search:
type: boolean
epsilon:
Expand Down
2 changes: 1 addition & 1 deletion k8s/tools/benchmark/operator/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
serviceAccountName: vald-benchmark-operator
containers:
- name: vald-benchmark-operator
image: local-registry:5000/vdaas/vald-benchmark-operator
image: "vdaas/vald-benchmark-operator:v1.7.5"
imagePullPolicy: Always
livenessProbe:
failureThreshold: 2
Expand Down
8 changes: 8 additions & 0 deletions pkg/tools/benchmark/job/service/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func (j *job) search(ctx context.Context, ech chan error) error {
Radius: float32(j.searchConfig.Radius),
Epsilon: float32(j.searchConfig.Epsilon),
Timeout: j.timeout.Nanoseconds(),
AggregationAlgorithm: func() payload.Search_AggregationAlgorithm {
if len(j.searchConfig.AggregationAlgorithm) > 0 {
if v, ok := payload.Search_AggregationAlgorithm_value[j.searchConfig.AggregationAlgorithm]; ok {
return payload.Search_AggregationAlgorithm(v)
}
}
return 0
}(),
}
sres := make([]*payload.Search_Response, len(vecs))
log.Infof("[benchmark job] Start search")
Expand Down

0 comments on commit fd47989

Please sign in to comment.