Skip to content

Commit 03df0ce

Browse files
Add tokio runtime and task metrics to stats API (#20985)
* Add tokio runtime and task metrics to stats Signed-off-by: Ajay Raj Nelapudi <ajnelapu@amazon.com> * Expose limited fields from tokio-metrics Signed-off-by: Ajay Raj Nelapudi <ajnelapu@amazon.com> * Move from proto to long[] for returning metrics across JNI Signed-off-by: Ajay Raj Nelapudi <ajnelapu@amazon.com> * Remove unused proto dependencies Signed-off-by: Ajay Raj Nelapudi <ajnelapu@amazon.com> --------- Signed-off-by: Ajay Raj Nelapudi <ajnelapu@amazon.com> Co-authored-by: Ajay Raj Nelapudi <ajnelapu@amazon.com>
1 parent 0ca3069 commit 03df0ce

43 files changed

Lines changed: 1930 additions & 77 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libs/vectorized-exec-spi/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ dependencies {
2020
testImplementation(project(":test:framework")) {
2121
exclude group: 'org.opensearch', module: 'vectorized-exec-spi'
2222
}
23+
24+
// jqwik for property-based testing (requires JUnit 5 Platform)
25+
testImplementation 'net.jqwik:jqwik-api:1.9.2'
26+
testImplementation 'org.apiguardian:apiguardian-api:1.1.2'
27+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
28+
testRuntimeOnly 'net.jqwik:jqwik-engine:1.9.2'
29+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.3'
30+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.11.3'
2331
}
2432

2533
tasks.named('forbiddenApisMain').configure {
@@ -30,4 +38,5 @@ jarHell.enabled = false
3038

3139
test {
3240
systemProperty 'tests.security.manager', 'false'
41+
useJUnitPlatform()
3342
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.vectorized.execution.metrics;
10+
11+
import org.opensearch.common.annotation.InternalApi;
12+
13+
/**
14+
* A forward-only cursor over a flat {@code long[]} array received from the
15+
* native (Rust) side via JNI.
16+
*
17+
* <p>Each call to {@link #read(NativeStatsBlockFactory)} creates a typed
18+
* {@link NativeStatsBlock} starting at the current position and advances
19+
* the cursor by the block's {@link NativeStatsBlock#size() size}.
20+
*
21+
* <p>After all blocks have been read, call {@link #assertFullyConsumed()}
22+
* to verify that every element in the array was consumed.
23+
*/
24+
@InternalApi
25+
public class ArrayCursor {
26+
27+
private final long[] data;
28+
private int pos;
29+
30+
/**
31+
* Creates a cursor over the given array, starting at position 0.
32+
*
33+
* @param data the source array (typically the full JNI payload)
34+
*/
35+
public ArrayCursor(long[] data) {
36+
this.data = data;
37+
this.pos = 0;
38+
}
39+
40+
/**
41+
* Reads a stats block from the current position and advances the cursor.
42+
*
43+
* @param factory a factory (typically a constructor reference such as
44+
* {@code RuntimeValues::new}) that creates a block from
45+
* the array and an offset
46+
* @param <T> the concrete stats block type
47+
* @return the newly created stats block
48+
*/
49+
public <T extends NativeStatsBlock> T read(NativeStatsBlockFactory<T> factory) {
50+
T block = factory.create(data, pos);
51+
pos += block.size();
52+
return block;
53+
}
54+
55+
/**
56+
* Asserts that the cursor has consumed every element in the array.
57+
*
58+
* @throws IllegalArgumentException if the current position does not equal
59+
* the array length
60+
*/
61+
public void assertFullyConsumed() {
62+
if (pos != data.length) {
63+
throw new IllegalArgumentException(
64+
"Array not fully consumed: position=" + pos + ", length=" + data.length
65+
);
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)