Skip to content

Commit 4cbbb83

Browse files
authored
Merge branch 'main' into simplify_esql_response
2 parents e04864c + b517bc7 commit 4cbbb83

File tree

22 files changed

+385
-248
lines changed

22 files changed

+385
-248
lines changed

docs/changelog/129418.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 129418
2+
summary: Update traces duration mappings with appropriate unit type
3+
area: Ingest Node
4+
type: enhancement
5+
issues: []

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/DefaultESVectorUtilSupport.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,58 @@ static float ipFloatBitImpl(float[] q, byte[] d, int start) {
204204
return acc0 + acc1 + acc2 + acc3;
205205
}
206206

207+
/**
208+
* Returns the inner product (aka dot product) between the query vector {@code q}, and the data vector {@code d}.
209+
* <p>
210+
* The query vector should be {@link #B_QUERY}-bit quantized and striped, so that the first {@code n} bits
211+
* of the array are the initial bits of each of the {@code n} vector dimensions; the next {@code n}
212+
* bits are the second bits of each of the {@code n} vector dimensions, and so on
213+
* (this algorithm is only valid for vectors with dimensions a multiple of 8).
214+
* The striping is usually done by {@code BQSpaceUtils.transposeHalfByte}.
215+
* <p>
216+
* The data vector should be single-bit quantized.
217+
*
218+
* <h4>Dot products with bit quantization</h4>
219+
*
220+
* The dot product of any vector with a bit vector is a simple selector - each query vector dimension is multiplied
221+
* by the 0 or 1 in the corresponding data vector dimension; the result is that each dimension value
222+
* is either kept or ignored, with the dimensions that are kept then summed together.
223+
*
224+
* <h4>The algorithm</h4>
225+
*
226+
* The transposition already applied to the query vector ensures there's a 1-to-1 correspondence
227+
* between the data vector bits and query vector bits (see {@code BQSpaceUtils.transposeHalfByte)};
228+
* this means we can use a bitwise {@code &} to keep only the bits of the vector elements we want to sum.
229+
* Essentially, the data vector is used as a selector for each of the striped bits of each vector dimension
230+
* as stored, concatenated together, in {@code q}.
231+
* <p>
232+
* The final dot product result can be obtained by observing that the sum of each stripe of {@code n} bits
233+
* can be computed using the bit count of that stripe. Similar to
234+
* <a href="https://en.wikipedia.org/wiki/Multiplication_algorithm#Long_multiplication">long multiplication</a>,
235+
* the result of each stripe of {@code n} bits can be added together by shifting the value {@code s} bits to the left,
236+
* where {@code s} is the stripe number (0-3), then adding to the overall result. Any carry is handled by the add operation.
237+
*
238+
* @param q query vector, {@link #B_QUERY}-bit quantized and striped (see {@code BQSpaceUtils.transposeHalfByte})
239+
* @param d data vector, 1-bit quantized
240+
* @return inner product result
241+
*/
207242
public static long ipByteBinByteImpl(byte[] q, byte[] d) {
208243
long ret = 0;
209244
int size = d.length;
210-
for (int i = 0; i < B_QUERY; i++) {
245+
for (int s = 0; s < B_QUERY; s++) { // for each stripe of B_QUERY-bit quantization in q...
211246
int r = 0;
212-
long subRet = 0;
247+
long stripeRet = 0;
248+
// bitwise & the query and data vectors together, 32-bits at a time, and counting up the bits still set
213249
for (final int upperBound = d.length & -Integer.BYTES; r < upperBound; r += Integer.BYTES) {
214-
subRet += Integer.bitCount((int) BitUtil.VH_NATIVE_INT.get(q, i * size + r) & (int) BitUtil.VH_NATIVE_INT.get(d, r));
250+
stripeRet += Integer.bitCount((int) BitUtil.VH_NATIVE_INT.get(q, s * size + r) & (int) BitUtil.VH_NATIVE_INT.get(d, r));
215251
}
252+
// handle any tail
253+
// Java operations on bytes automatically extend to int, so we need to mask back down again in case it sign-extends the int
216254
for (; r < d.length; r++) {
217-
subRet += Integer.bitCount((q[i * size + r] & d[r]) & 0xFF);
255+
stripeRet += Integer.bitCount((q[s * size + r] & d[r]) & 0xFF);
218256
}
219-
ret += subRet << i;
257+
// shift the result of the s'th stripe s to the left and add to the result
258+
ret += stripeRet << s;
220259
}
221260
return ret;
222261
}

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/ESVectorUtilSupport.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111

1212
public interface ESVectorUtilSupport {
1313

14+
/**
15+
* The number of bits in bit-quantized query vectors
16+
*/
1417
short B_QUERY = 4;
1518

19+
/**
20+
* Compute dot product between {@code q} and {@code d}
21+
* @param q query vector, {@link #B_QUERY}-bit quantized and striped (see {@code BQSpaceUtils.transposeHalfByte})
22+
* @param d data vector, 1-bit quantized
23+
*/
1624
long ipByteBinByte(byte[] q, byte[] d);
1725

1826
int ipByteBit(byte[] q, byte[] d);

muted-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ tests:
544544
- class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceDiskSpaceTests
545545
method: testMergeTasksAreUnblockedWhenMoreDiskSpaceBecomesAvailable
546546
issue: https://github.com/elastic/elasticsearch/issues/129296
547+
- class: org.elasticsearch.xpack.security.PermissionsIT
548+
method: testCanManageIndexWithNoPermissions
549+
issue: https://github.com/elastic/elasticsearch/issues/129471
547550

548551
# Examples:
549552
#

server/src/main/java/org/elasticsearch/cluster/ProjectState.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public ClusterState updatedState(Consumer<ProjectMetadata.Builder> projectBuilde
7676
return ClusterState.builder(cluster).putProjectMetadata(projectBuilder).build();
7777
}
7878

79+
/**
80+
* Build a new {@link ClusterState} with the updated project.
81+
*/
82+
public ClusterState updatedState(ProjectMetadata updatedProject) {
83+
return ClusterState.builder(cluster).putProjectMetadata(updatedProject).build();
84+
}
85+
7986
/**
8087
* Build a new {@link ProjectState} with the updated {@code project}.
8188
*/

x-pack/plugin/apm-data/src/main/resources/component-templates/[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ template:
4343
# span.*
4444
span.duration.us:
4545
type: long
46+
meta:
47+
unit: micros
4648
span.representative_count:
4749
type: scaled_float
4850
scaling_factor: 1000
@@ -57,6 +59,8 @@ template:
5759
dynamic: false
5860
transaction.duration.us:
5961
type: long
62+
meta:
63+
unit: micros
6064
transaction.representative_count:
6165
type: scaled_float
6266
scaling_factor: 1000

x-pack/plugin/apm-data/src/main/resources/resources.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# "version" holds the version of the templates and ingest pipelines installed
22
# by xpack-plugin apm-data. This must be increased whenever an existing template or
33
# pipeline is changed, in order for it to be updated on Elasticsearch upgrade.
4-
version: 14
4+
version: 15
55

66
component-templates:
77
# Data lifecycle.

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/KibanaOwnedReservedRoleDescriptors.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ static RoleDescriptor kibanaSystem(String name) {
223223
.privileges("all")
224224
.allowRestrictedIndices(true)
225225
.build(),
226+
// Fleet writes to this datastream for Agent status alerting feature
227+
RoleDescriptor.IndicesPrivileges.builder().indices("logs-elastic_agent.status_change-*").privileges("all").build(),
226228
// Fleet telemetry queries Agent Logs indices in kibana task runner
227229
RoleDescriptor.IndicesPrivileges.builder().indices("logs-elastic_agent*").privileges("read").build(),
228230
// Fleet publishes Agent metrics in kibana task runner

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/EsqlQueryGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.DropGenerator;
1414
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.EnrichGenerator;
1515
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.EvalGenerator;
16+
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.ForkGenerator;
1617
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.GrokGenerator;
1718
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.KeepGenerator;
1819
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.LimitGenerator;
@@ -53,6 +54,7 @@ public record QueryExecuted(String query, int depth, List<Column> outputSchema,
5354
DropGenerator.INSTANCE,
5455
EnrichGenerator.INSTANCE,
5556
EvalGenerator.INSTANCE,
57+
ForkGenerator.INSTANCE,
5658
GrokGenerator.INSTANCE,
5759
KeepGenerator.INSTANCE,
5860
LimitGenerator.INSTANCE,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe;
9+
10+
import org.elasticsearch.xpack.esql.qa.rest.generative.EsqlQueryGenerator;
11+
import org.elasticsearch.xpack.esql.qa.rest.generative.command.CommandGenerator;
12+
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
17+
18+
public class ForkGenerator implements CommandGenerator {
19+
20+
public static final String FORK = "fork";
21+
public static final CommandGenerator INSTANCE = new ForkGenerator();
22+
23+
@Override
24+
public CommandDescription generate(
25+
List<CommandDescription> previousCommands,
26+
List<EsqlQueryGenerator.Column> previousOutput,
27+
QuerySchema schema
28+
) {
29+
// FORK can only be allowed once - so we skip adding another FORK if we already have one
30+
// otherwise, most generated queries would only result in a validation error
31+
for (CommandDescription command : previousCommands) {
32+
if (command.commandName().equals(FORK)) {
33+
return new CommandDescription(FORK, this, " ", Map.of());
34+
}
35+
}
36+
37+
int n = randomIntBetween(2, 10);
38+
39+
String cmd = " | FORK " + "( WHERE true ) ".repeat(n) + " | WHERE _fork == \"fork" + randomIntBetween(1, n) + "\" | DROP _fork";
40+
41+
return new CommandDescription(FORK, this, cmd, Map.of());
42+
}
43+
44+
@Override
45+
public ValidationResult validateOutput(
46+
List<CommandDescription> previousCommands,
47+
CommandDescription command,
48+
List<EsqlQueryGenerator.Column> previousColumns,
49+
List<List<Object>> previousOutput,
50+
List<EsqlQueryGenerator.Column> columns,
51+
List<List<Object>> output
52+
) {
53+
return CommandGenerator.expectSameRowCount(previousCommands, previousOutput, output);
54+
}
55+
}

0 commit comments

Comments
 (0)