Skip to content

Commit

Permalink
Run spotless and exclude checkstyle on client module
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
  • Loading branch information
owaiskazi19 committed Oct 21, 2021
1 parent 2da858c commit 599b36f
Show file tree
Hide file tree
Showing 211 changed files with 8,060 additions and 5,023 deletions.
14 changes: 3 additions & 11 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,15 @@
<!-- Intentionally has long example curl commands to coincide with sibling Painless tests. -->
<suppress files="modules[/\\]lang-painless[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]painless[/\\]ContextExampleTests.java" checks="LineLength" />

<!-- Exclude server to run checkstyle -->
<!-- Excludes checkstyle run on server module -->
<suppress files="server" checks="." />
<!-- Excludes checkstyle run on client module -->
<suppress files="client" checks="." />

<!--
Truly temporary suppressions suppression of snippets included in
documentation that are so wide that they scroll.
-->
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]ClusterClientDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]CRUDDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]IndicesClientDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]IngestClientDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]MiscellaneousDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]SearchDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]SnapshotClientDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]StoredScriptsDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]TasksClientDocumentationIT.java" id="SnippetLength" />
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]WatcherDocumentationIT.java" id="SnippetLength" />
<suppress files="modules[/\\]reindex[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]documentation[/\\]ReindexDocumentationIT.java" id="SnippetLength" />

<!-- Gradle requires inputs to be seriablizable -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public final void run(String[] args) throws Exception {
@SuppressForbidden(reason = "system out is ok for a command line tool")
private void runBulkIndexBenchmark(String[] args) throws Exception {
if (args.length != 7) {
System.err.println(
"usage: 'bulk' benchmarkTargetHostIp indexFilePath indexName typeName numberOfDocuments bulkSize");
System.err.println("usage: 'bulk' benchmarkTargetHostIp indexFilePath indexName typeName numberOfDocuments bulkSize");
System.exit(1);
}
String benchmarkTargetHost = args[1];
Expand All @@ -95,9 +94,11 @@ private void runBulkIndexBenchmark(String[] args) throws Exception {

T client = client(benchmarkTargetHost);

BenchmarkRunner benchmark = new BenchmarkRunner(warmupIterations, iterations,
new BulkBenchmarkTask(
bulkRequestExecutor(client, indexName, typeName), indexFilePath, warmupIterations, iterations, bulkSize));
BenchmarkRunner benchmark = new BenchmarkRunner(
warmupIterations,
iterations,
new BulkBenchmarkTask(bulkRequestExecutor(client, indexName, typeName), indexFilePath, warmupIterations, iterations, bulkSize)
);

try {
runTrials(() -> {
Expand All @@ -113,8 +114,7 @@ private void runBulkIndexBenchmark(String[] args) throws Exception {
@SuppressForbidden(reason = "system out is ok for a command line tool")
private void runSearchBenchmark(String[] args) throws Exception {
if (args.length != 5) {
System.err.println(
"usage: 'search' benchmarkTargetHostIp indexName searchRequestBody throughputRates");
System.err.println("usage: 'search' benchmarkTargetHostIp indexName searchRequestBody throughputRates");
System.exit(1);
}
String benchmarkTargetHost = args[1];
Expand All @@ -127,12 +127,19 @@ private void runSearchBenchmark(String[] args) throws Exception {
try {
runTrials(() -> {
for (int throughput : throughputRates) {
//GC between trials to reduce the likelihood of a GC occurring in the middle of a trial.
// GC between trials to reduce the likelihood of a GC occurring in the middle of a trial.
runGc();
BenchmarkRunner benchmark = new BenchmarkRunner(SEARCH_BENCHMARK_ITERATIONS, SEARCH_BENCHMARK_ITERATIONS,
BenchmarkRunner benchmark = new BenchmarkRunner(
SEARCH_BENCHMARK_ITERATIONS,
SEARCH_BENCHMARK_ITERATIONS,
new SearchBenchmarkTask(
searchRequestExecutor(client, indexName), searchBody, SEARCH_BENCHMARK_ITERATIONS,
SEARCH_BENCHMARK_ITERATIONS, throughput));
searchRequestExecutor(client, indexName),
searchBody,
SEARCH_BENCHMARK_ITERATIONS,
SEARCH_BENCHMARK_ITERATIONS,
throughput
)
);
System.out.printf("Target throughput = %d ops / s%n", throughput);
benchmark.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public BenchmarkRunner(int warmupIterations, int iterations, BenchmarkTask task)
@SuppressForbidden(reason = "system out is ok for a command line tool")
public void run() {
SampleRecorder recorder = new SampleRecorder(iterations);
System.out.printf("Running %s with %d warmup iterations and %d iterations.%n",
task.getClass().getSimpleName(), warmupIterations, iterations);
System.out.printf(
"Running %s with %d warmup iterations and %d iterations.%n",
task.getClass().getSimpleName(),
warmupIterations,
iterations
);

try {
task.setUp(recorder);
Expand All @@ -78,14 +82,26 @@ public void run() {

for (Metrics metrics : summaryMetrics) {
String throughput = String.format(Locale.ROOT, "Throughput [ops/s]: %f", metrics.throughput);
String serviceTimes = String.format(Locale.ROOT,
String serviceTimes = String.format(
Locale.ROOT,
"Service time [ms]: p50 = %f, p90 = %f, p95 = %f, p99 = %f, p99.9 = %f, p99.99 = %f",
metrics.serviceTimeP50, metrics.serviceTimeP90, metrics.serviceTimeP95,
metrics.serviceTimeP99, metrics.serviceTimeP999, metrics.serviceTimeP9999);
String latencies = String.format(Locale.ROOT,
metrics.serviceTimeP50,
metrics.serviceTimeP90,
metrics.serviceTimeP95,
metrics.serviceTimeP99,
metrics.serviceTimeP999,
metrics.serviceTimeP9999
);
String latencies = String.format(
Locale.ROOT,
"Latency [ms]: p50 = %f, p90 = %f, p95 = %f, p99 = %f, p99.9 = %f, p99.99 = %f",
metrics.latencyP50, metrics.latencyP90, metrics.latencyP95,
metrics.latencyP99, metrics.latencyP999, metrics.latencyP9999);
metrics.latencyP50,
metrics.latencyP90,
metrics.latencyP95,
metrics.latencyP99,
metrics.latencyP999,
metrics.latencyP9999
);

int lineLength = Math.max(serviceTimes.length(), latencies.length());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,24 @@ public final class Metrics {
public final double latencyP999;
public final double latencyP9999;

public Metrics(String operation, long successCount, long errorCount, double throughput,
double serviceTimeP50, double serviceTimeP90, double serviceTimeP95, double serviceTimeP99,
double serviceTimeP999, double serviceTimeP9999, double latencyP50, double latencyP90,
double latencyP95, double latencyP99, double latencyP999, double latencyP9999) {
public Metrics(
String operation,
long successCount,
long errorCount,
double throughput,
double serviceTimeP50,
double serviceTimeP90,
double serviceTimeP95,
double serviceTimeP99,
double serviceTimeP999,
double serviceTimeP9999,
double latencyP50,
double latencyP90,
double latencyP95,
double latencyP99,
double latencyP999,
double latencyP9999
) {
this.operation = operation;
this.successCount = successCount;
this.errorCount = errorCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,28 @@ private static List<Metrics> calculateMetricsPerOperation(Map<String, List<Sampl
it++;
}

metrics.add(new Metrics(operationAndMetrics.getKey(),
samples.stream().filter((r) -> r.isSuccess()).count(),
samples.stream().filter((r) -> !r.isSuccess()).count(),
// throughput calculation is based on the total (Wall clock) time it took to generate all samples
calculateThroughput(samples.size(), latestEnd - firstStart),
// convert ns -> ms without losing precision
StatUtils.percentile(serviceTimes, 50.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 90.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 95.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 99.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 99.9d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 99.99d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 50.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 90.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 95.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 99.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 99.9d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 99.99d) / TimeUnit.MILLISECONDS.toNanos(1L)));
metrics.add(
new Metrics(
operationAndMetrics.getKey(),
samples.stream().filter((r) -> r.isSuccess()).count(),
samples.stream().filter((r) -> !r.isSuccess()).count(),
// throughput calculation is based on the total (Wall clock) time it took to generate all samples
calculateThroughput(samples.size(), latestEnd - firstStart),
// convert ns -> ms without losing precision
StatUtils.percentile(serviceTimes, 50.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 90.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 95.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 99.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 99.9d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(serviceTimes, 99.99d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 50.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 90.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 95.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 99.0d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 99.9d) / TimeUnit.MILLISECONDS.toNanos(1L),
StatUtils.percentile(latencies, 99.99d) / TimeUnit.MILLISECONDS.toNanos(1L)
)
);
}
return metrics;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public class BulkBenchmarkTask implements BenchmarkTask {
private LoadGenerator generator;
private ExecutorService executorService;

public BulkBenchmarkTask(BulkRequestExecutor requestExecutor, String indexFilePath, int warmupIterations, int measurementIterations,
int bulkSize) {
public BulkBenchmarkTask(
BulkRequestExecutor requestExecutor,
String indexFilePath,
int warmupIterations,
int measurementIterations,
int bulkSize
) {
this.requestExecutor = requestExecutor;
this.indexFilePath = indexFilePath;
this.warmupIterations = warmupIterations;
Expand All @@ -86,11 +91,11 @@ public void setUp(SampleRecorder sampleRecorder) {

@Override
@SuppressForbidden(reason = "system out is ok for a command line tool")
public void run() throws Exception {
public void run() throws Exception {
generator.execute();
// when the generator is done, there are no more data -> shutdown client
executorService.shutdown();
//We need to wait until the queue is drained
// We need to wait until the queue is drained
final boolean finishedNormally = executorService.awaitTermination(20, TimeUnit.MINUTES);
if (finishedNormally == false) {
System.err.println("Background tasks are still running after timeout on enclosing pool. Forcing pool shutdown.");
Expand All @@ -100,7 +105,7 @@ public void run() throws Exception {

@Override
public void tearDown() {
//no op
// no op
}

private static final class LoadGenerator {
Expand Down Expand Up @@ -146,7 +151,6 @@ private void sendBulk(List<String> bulkData) throws InterruptedException {
}
}


private static final class BulkIndexer implements Runnable {
private static final Logger logger = LogManager.getLogger(BulkIndexer.class);

Expand All @@ -156,8 +160,13 @@ private static final class BulkIndexer implements Runnable {
private final BulkRequestExecutor bulkRequestExecutor;
private final SampleRecorder sampleRecorder;

BulkIndexer(BlockingQueue<List<String>> bulkData, int warmupIterations, int measurementIterations,
SampleRecorder sampleRecorder, BulkRequestExecutor bulkRequestExecutor) {
BulkIndexer(
BlockingQueue<List<String>> bulkData,
int warmupIterations,
int measurementIterations,
SampleRecorder sampleRecorder,
BulkRequestExecutor bulkRequestExecutor
) {
this.bulkData = bulkData;
this.warmupIterations = warmupIterations;
this.measurementIterations = measurementIterations;
Expand All @@ -176,7 +185,7 @@ public void run() {
Thread.currentThread().interrupt();
return;
}
//measure only service time, latency is not that interesting for a throughput benchmark
// measure only service time, latency is not that interesting for a throughput benchmark
long start = System.nanoTime();
try {
success = bulkRequestExecutor.bulkIndex(currentBulk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ public class SearchBenchmarkTask implements BenchmarkTask {

private SampleRecorder sampleRecorder;

public SearchBenchmarkTask(SearchRequestExecutor searchRequestExecutor, String body, int warmupIterations,
int measurementIterations, int targetThroughput) {
public SearchBenchmarkTask(
SearchRequestExecutor searchRequestExecutor,
String body,
int warmupIterations,
int measurementIterations,
int targetThroughput
) {
this.searchRequestExecutor = searchRequestExecutor;
this.searchRequestBody = body;
this.warmupIterations = warmupIterations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public static void main(String[] args) throws Exception {

@Override
protected RestClient client(String benchmarkTargetHost) {
return RestClient
.builder(new HttpHost(benchmarkTargetHost, 9200))
.setHttpClientConfigCallback(b -> b.setDefaultHeaders(
Collections.singleton(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "gzip"))))
return RestClient.builder(new HttpHost(benchmarkTargetHost, 9200))
.setHttpClientConfigCallback(
b -> b.setDefaultHeaders(Collections.singleton(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "gzip")))
)
.setRequestConfigCallback(b -> b.setContentCompressionEnabled(true))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ public class NoopPlugin extends Plugin implements ActionPlugin {
}

@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(
new RestNoopBulkAction(),
new RestNoopSearchAction());
public List<RestHandler> getRestHandlers(
Settings settings,
RestController restController,
ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings,
SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster
) {
return Arrays.asList(new RestNoopBulkAction(), new RestNoopSearchAction());
}
}
Loading

0 comments on commit 599b36f

Please sign in to comment.