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

Feat/search load #91

Merged
merged 2 commits into from
Aug 12, 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
57 changes: 57 additions & 0 deletions internal/native/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,63 @@
return PutContainerResponse{Success: true, ContainerID: contID.EncodeToString()}
}

type Filter struct {
Key string
Operation string
Value string
}

// Search searches for the objects in container that satisfies provided filters.
// Returns number of found objects.
func (c *Client) Search(cnrString string, filtersJS []Filter) (int, error) {
var cID cid.ID
err := cID.DecodeString(cnrString)
if err != nil {
return 0, fmt.Errorf("reading container ID: %w", err)

Check warning on line 338 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L334-L338

Added lines #L334 - L338 were not covered by tests
}

var op object.SearchMatchType
var filters object.SearchFilters
for _, flt := range filtersJS {
if !op.DecodeString(flt.Operation) {
return 0, fmt.Errorf("unknown filter operation: %s", flt.Operation)

Check warning on line 345 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L341-L345

Added lines #L341 - L345 were not covered by tests
}

filters.AddFilter(flt.Key, flt.Value, op)

Check warning on line 348 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L348

Added line #L348 was not covered by tests
}

var prm client.PrmObjectSearch
prm.SetFilters(filters)

Check warning on line 352 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L351-L352

Added lines #L351 - L352 were not covered by tests

start := time.Now()

Check warning on line 354 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L354

Added line #L354 was not covered by tests

r, err := c.cli.ObjectSearchInit(c.vu.Context(), cID, c.signer, prm)
smallhive marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return 0, fmt.Errorf("search stream initialization: %w", err)

Check warning on line 358 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L356-L358

Added lines #L356 - L358 were not covered by tests
}
defer func() {
_ = r.Close()
}()

Check warning on line 362 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L360-L362

Added lines #L360 - L362 were not covered by tests

var objsNum int
err = r.Iterate(func(_ oid.ID) bool {
objsNum++
return false
})
if err != nil {
return 0, fmt.Errorf("reading search results: %w", err)

Check warning on line 370 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L364-L370

Added lines #L364 - L370 were not covered by tests
}

var relativeTime time.Duration
if objsNum > 0 {
smallhive marked this conversation as resolved.
Show resolved Hide resolved
relativeTime = time.Since(start) / time.Duration(objsNum)

Check warning on line 375 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L373-L375

Added lines #L373 - L375 were not covered by tests
}

stats.Report(c.vu, objSearchDurationRelative, metrics.D(relativeTime))

Check warning on line 378 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L378

Added line #L378 was not covered by tests

return objsNum, nil

Check warning on line 380 in internal/native/client.go

View check run for this annotation

Codecov / codecov/patch

internal/native/client.go#L380

Added line #L380 was not covered by tests
}

func (c *Client) Onsite(containerID string, payload goja.ArrayBuffer) PreparedObject {
maxObjectSize, epoch, hhDisabled, err := parseNetworkInfo(c.vu.Context(), c.cli)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/native/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
objGetTotal, objGetFails, objGetDuration *metrics.Metric
objDeleteTotal, objDeleteFails, objDeleteDuration *metrics.Metric
cnrPutTotal, cnrPutFails, cnrPutDuration *metrics.Metric
objSearchDurationRelative *metrics.Metric
)

func init() {
Expand Down Expand Up @@ -136,6 +137,8 @@
cnrPutFails, _ = registry.NewMetric("neofs_cnr_put_fails", metrics.Counter)
cnrPutDuration, _ = registry.NewMetric("neofs_cnr_put_duration", metrics.Trend, metrics.Time)

objSearchDurationRelative, _ = registry.NewMetric("neofs_search_duration_relative", metrics.Trend, metrics.Time)

Check warning on line 140 in internal/native/native.go

View check run for this annotation

Codecov / codecov/patch

internal/native/native.go#L140

Added line #L140 was not covered by tests

return &Client{
vu: n.vu,
signer: signer,
Expand Down
35 changes: 35 additions & 0 deletions scenarios/grpc_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { check } from 'k6';
import native from 'k6/x/neofs/native';

const dial_timeout = 5
const stream_timeout = 15
const predefined_private_key = '' // usually no need for search requests in load tests
const grpc_client = native.connect(__ENV.GRPC_ENDPOINT, predefined_private_key, dial_timeout, stream_timeout);
const container = __ENV.cid

export const options = {
scenarios: {
system_write: {
executor: 'shared-iterations',
vus: __ENV.vu,
iterations: __ENV.i,
exec: 'search',
maxDuration: (24*365*100).toString()+"h", // default is 10m and this load is designed to be controlled by iterations only
cthulhu-rider marked this conversation as resolved.
Show resolved Hide resolved
gracefulStop: '30s',
},
},
};

export function search() {
let res = grpc_client.search(container, [{
key: "test",
operation: "STRING_EQUAL",
value: "test"
}])
check(res, {
'search': (r) => {
return r > 0;
}
}
)
}
Loading