Skip to content

Commit

Permalink
Merge branch 'main' into workspace_privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglam authored Jan 13, 2025
2 parents 1bbc711 + 7c72e10 commit fd56019
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/vale/styles/Vocab/OpenSearch/Products/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ Tribuo
VisBuilder
Winlogbeat
XGBoost
Zipf
Zstandard
2 changes: 1 addition & 1 deletion .github/vale/styles/Vocab/OpenSearch/Words/reject.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

[Aa]ss
6 changes: 6 additions & 0 deletions FORMATTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ Some Markdown paragraph. Here's a formula:
And back to Markdown.
```

Alternatively, you can use double dollar signs (`$$`) for both display and inline math directly in Markdown:

```
The probability of selecting pair $$i$$ is proportional to $$1 \over i^\alpha$$.
```

## Tables

Markdown table columns are automatically sized, and there is no need to specify a different number of dashes in the formatting.
Expand Down
2 changes: 1 addition & 1 deletion _api-reference/snapshots/restore-snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If open indexes with the same name that you want to restore already exist in the
## Endpoints

```json
GET _snapshot/<repository>/<snapshot>/
POST _snapshot/<repository>/<snapshot>/_restore
```

## Path parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
layout: default
title: Running randomized workloads
title: Randomizing queries
nav_order: 160
parent: Optimizing benchmarks
grand_parent: User guide
has_math: true
---

# Randomizing queries
Expand All @@ -29,15 +30,13 @@ For example, changing `"gte"` and `"lt"` in the following `nyc_taxis` operation
}
```


You can't completely randomize the values because the cache would not get any hits. To get cache hits, the cache must sometimes encounter the same values. To account for the same values while randomizing, OpenSearch Benchmark generates a number `N` of value pairs for each randomized operation at the beginning of the benchmark. OpenSearch Benchmark stores these values in a saved list where each pair is assigned an index from `1` to `N`.
You can't completely randomize the values because the cache would not get any hits. To get cache hits, the cache must sometimes encounter the same values. To account for the same values while randomizing, OpenSearch Benchmark generates a number $$N$$ of value pairs for each randomized operation at the beginning of the benchmark. OpenSearch Benchmark stores these values in a saved list where each pair is assigned an index from $$1$$ to $$N$$.

Every time OpenSearch sends a query, OpenSearch Benchmark decides whether to use a pair of values from this saved list in the query. It does this a configurable fraction of the time, called _repeat frequency_ (`rf`). If OpenSearch has encountered the value pair before, this might cause a cache hit. For example, if `rf` = 0.7, the cache hit ratio could be up to 70%. This ratio could cause a hit, depending on the benchmark's duration and cache size.

OpenSearch Benchmark selects saved value pairs using the Zipf probability distribution, where the probability of selecting pair `i` is proportional to `1/i^α`. In this formula, `i` represents the index of the saved value pair, and `α` controls how concentrated the distribution is. This distribution reflects usage patterns observed in real caches. Pairs with lower `i` values (closer to `1`) are selected more frequently, while pairs with higher `i` values (closer to `N`) are selected less often.

Otherwise, the other `1-rf` fraction of the time, a new random pair of values is generated. Because OpenSearch Benchmark has not encountered these value pairs before, the pairs should miss the cache.
OpenSearch Benchmark selects saved value pairs using the Zipf probability distribution, where the probability of selecting pair $$i$$ is proportional to $$1 \over i^\alpha$$. In this formula, $$i$$ represents the index of the saved value pair, and $$\alpha$$ controls how concentrated the distribution is. This distribution reflects usage patterns observed in real caches. Pairs with lower $$i$$ values (closer to $$1$$) are selected more frequently, while pairs with higher $$i$$ values (closer to $$N$$) are selected less often.

The other $$1 -$$ `rf` fraction of the time, a new random pair of values is generated. Because OpenSearch Benchmark has not encountered these value pairs before, the pairs should miss the cache.

## Usage

Expand Down
4 changes: 2 additions & 2 deletions spec-insert/lib/insert_arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Doc Insert Arguments
class InsertArguments
COLUMNS = %w[Parameter Description Required Type Default].freeze
DEFAULT_COLUMNS = %w[Parameter Type Description].freeze
COLUMNS = ['Parameter', 'Description', 'Required', 'Data type', 'Default'].freeze
DEFAULT_COLUMNS = ['Parameter', 'Data type', 'Description'].freeze
attr_reader :raw

# @param [Array<String>] lines the lines between <!-- doc_insert_start and -->
Expand Down
2 changes: 1 addition & 1 deletion spec-insert/lib/renderers/parameter_table_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def row(param)
'Parameter' => "`#{param.name}`#{' <br> _DEPRECATED_' if param.deprecated}",
'Description' => description(param),
'Required' => param.required ? 'Required' : nil,
'Type' => param.doc_type,
'Data type' => param.doc_type,
'Default' => param.default.nil? ? nil : "`#{param.default}`"
}
end
Expand Down
11 changes: 10 additions & 1 deletion spec-insert/lib/renderers/path_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ class PathParameters < BaseMustacheRenderer
self.template_file = "#{__dir__}/templates/path_parameters.mustache"

def table
params = @action.arguments.select { |arg| arg.location == ArgLocation::PATH }
ParameterTableRenderer.new(params, @args).render
end

def optional
params.none?(&:required)
end

private

def params
@params ||= @action.arguments.select { |arg| arg.location == ArgLocation::PATH }
end
end
15 changes: 13 additions & 2 deletions spec-insert/lib/renderers/query_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ class QueryParameters < BaseMustacheRenderer
self.template_file = "#{__dir__}/templates/query_parameters.mustache"

def table
params = @action.arguments.select { |arg| arg.location == ArgLocation::QUERY }
params += Parameter.global if @args.include_global
ParameterTableRenderer.new(params, @args).render
end

def optional
params.none?(&:required)
end

private

def params
return @params if defined?(@params)
@params = @action.arguments.select { |arg| arg.location == ArgLocation::QUERY }
@params += Parameter.global if @args.include_global
@params
end
end
3 changes: 3 additions & 0 deletions spec-insert/lib/renderers/templates/path_parameters.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{{^omit_header}}
## Path parameters

The following table lists the available path parameters.{{#optional}} All path parameters are optional.{{/optional}}

{{/omit_header}}
{{{table}}}
6 changes: 3 additions & 3 deletions spec-insert/lib/renderers/templates/query_parameters.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{^omit_header}}
## Query parameters
{{#optional}}
All query parameters are optional.
{{/optional}}

The following table lists the available query parameters.{{#optional}} All query parameters are optional.{{/optional}}

{{/omit_header}}
{{{table}}}
39 changes: 31 additions & 8 deletions spec-insert/spec/_fixtures/expected_output/param_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ api: search
component: path_parameters
-->
## Path parameters
Parameter | Type | Description

The following table lists the available path parameters. All path parameters are optional.

Parameter | Data type | Description
:--- | :--- | :---
`index` | List or String | Comma-separated list of data streams, indexes, and aliases to search. Supports wildcards (`*`). To search all data streams and indexes, omit this parameter or use `*` or `_all`.
<!-- spec_insert_end -->
Expand All @@ -17,15 +20,18 @@ api: search
component: query_parameters
include_global: true
pretty: true
columns: Type, Parameter, Description, Required, Default
columns: Data type, Parameter, Description, Required, Default
-->
## Query parameters
| Type | Parameter | Description | Required | Default |
|:--------|:--------------------------|:-----------------------------------------------------------------------------------------------------------------------------------|:---------|:--------|
| Boolean | `analyze_wildcard` | If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. | Required | `false` |
| String | `analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified. | | |
| Boolean | `pretty` | Whether to pretty format the returned JSON response. | | |
| Boolean | `human` <br> _DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | `true` |

The following table lists the available query parameters.

| Data type | Parameter | Description | Required | Default |
|:----------|:--------------------------|:-----------------------------------------------------------------------------------------------------------------------------------|:---------|:--------|
| Boolean | `analyze_wildcard` | If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. | Required | `false` |
| String | `analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified. | | |
| Boolean | `pretty` | Whether to pretty format the returned JSON response. | | |
| Boolean | `human` <br> _DEPRECATED_ | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. | | `true` |
<!-- spec_insert_end -->

Query Parameters Example with only Parameter and Description Columns
Expand All @@ -41,3 +47,20 @@ Parameter | Description
`analyze_wildcard` | **(Required)** If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified. _(Default: `false`)_
`analyzer` | Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified.
<!-- spec_insert_end -->

Optional Params Text

<!-- spec_insert_start
api: cat.health
component: query_parameters
include_global: true
-->
## Query parameters

The following table lists the available query parameters. All query parameters are optional.

Parameter | Data type | Description
:--- | :--- | :---
`pretty` | Boolean | Whether to pretty format the returned JSON response.
`human` <br> _DEPRECATED_ | Boolean | _(Deprecated since 3.0: Use the `format` parameter instead.)_ Whether to return human readable values for statistics. _(Default: `true`)_
<!-- spec_insert_end -->
11 changes: 10 additions & 1 deletion spec-insert/spec/_fixtures/input/param_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ api: search
component: query_parameters
include_global: true
pretty: true
columns: Type, Parameter, Description, Required, Default
columns: Data type, Parameter, Description, Required, Default
-->
THIS TEXT SHOULD BE REPLACED
<!-- spec_insert_end -->
Expand All @@ -37,3 +37,12 @@ SHOULD
BE
REPLACED
<!-- spec_insert_end -->

Optional Params Text

<!-- spec_insert_start
api: cat.health
component: query_parameters
include_global: true
-->
<!-- spec_insert_end -->
7 changes: 7 additions & 0 deletions spec-insert/spec/_fixtures/opensearch_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ info:
version: 1.0.0
x-api-version: 2.16.0
paths:
/_cat/health:
get:
operationId: cat_health.0
x-operation-group: cat.health
parameters:
- $ref: '#/components/parameters/_global___query.pretty'
- $ref: '#/components/parameters/_global___query.human'
/_search:
get:
operationId: search.0
Expand Down

0 comments on commit fd56019

Please sign in to comment.