forked from opensearch-project/performance-analyzer-rca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
805 lines (702 loc) · 27.8 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
buildDockerJdkVersion = System.getProperty("build.docker_jdk_ver", "11")
// The PA Commons (https://github.com/opensearch-project/performance-analyzer-commons)
// is a library dependency with hardcoded versioning in PA and RCA repos.
paCommonsVersion = "1.6.0"
// 3.0.0-SNAPSHOT -> 3.0.0.0-SNAPSHOT
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
if (buildVersionQualifier) {
opensearch_build += "-${buildVersionQualifier}"
}
if (isSnapshot) {
opensearch_build += "-SNAPSHOT"
paCommonsVersion += "-SNAPSHOT"
}
gitPaBranch = 'main'
gitPaRepo = "https://github.com/opensearch-project/performance-analyzer.git"
runGauntletTests = "true" == System.getProperty("run.gauntlet.tests", "false")
}
repositories {
mavenLocal()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
}
}
plugins {
id 'java'
id 'application'
id 'maven-publish'
id 'com.google.protobuf' version '0.9.4'
id 'jacoco'
id 'idea'
id 'eclipse'
id 'com.github.spotbugs' version '6.0.7'
id "de.undercouch.download" version "5.5.0"
id 'com.adarshr.test-logger' version '4.0.0'
id 'org.gradle.test-retry' version '1.5.8'
id 'com.diffplug.spotless' version '6.25.0'
}
application {
mainClassName = 'org.opensearch.performanceanalyzer.PerformanceAnalyzerApp'
applicationDefaultJvmArgs = ['-Xms64M',
'-Xmx64M',
'-XX:+UseSerialGC',
'-XX:CICompilerCount=1',
'-XX:-TieredCompilation',
'-XX:InitialCodeCacheSize=4096',
'-XX:MaxRAM=400m']
}
// Include PA related folder in the distribution.
applicationDistribution.from(".") {
include 'config/*'
include 'bin/*'
}
distributions {
main {
contents {
eachFile {
it.path = it.path.replace("-$version/", '/')
}
}
}
}
spotless {
java {
licenseHeaderFile(file('license-header'))
googleJavaFormat('1.17.0').aosp()
importOrder()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
// add support for spotless:off and spotless:on tags to exclude sections of code
toggleOffOn()
}
}
tasks.withType(Checkstyle) {
reports {
xml.enabled false
html.enabled true
html.stylesheet resources.text.fromFile('configs/xsl/severity-sorted.xsl')
}
}
testlogger {
theme 'standard'
showExceptions true
showStackTraces false
showFullStackTraces false
showCauses true
slowThreshold 4000
showSummary true
showSimpleNames false
showPassed true
showSkipped true
showFailed true
showStandardStreams false
showPassedStandardStreams true
showSkippedStandardStreams true
showFailedStandardStreams true
logLevel 'lifecycle'
}
spotbugsMain {
excludeFilter = file("checkstyle/findbugs-exclude.xml")
effort = com.github.spotbugs.snom.Effort.MAX
ignoreFailures = true // TODO: Set this to false later as they are too many warnings to be fixed.
reports {
xml.enabled = false
html.enabled = true
}
}
spotbugsTest {
ignoreFailures = true
}
check {
dependsOn spotbugsMain
//dependsOn spotbugsTest
}
jacoco {
toolVersion = "0.8.11"
}
jacocoTestReport {
reports {
xml.required = true
html.required = true
csv.required = false
}
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/org/opensearch/performanceanalyzer/**'
],
exclude: [
'**/org/opensearch/performanceanalyzer/grpc/**',
'**/org/opensearch/performanceanalyzer/rca/framework/api/metrics/**',
'**/org/opensearch/performanceanalyzer/rca/net/requests**'
])
})
}
}
jacocoTestCoverageVerification {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/org/opensearch/performanceanalyzer/rca/**',
'**/org/opensearch/performanceanalyzer/reader/**'
],
exclude: [
'**/org/opensearch/performanceanalyzer/grpc/**'])
})
}
if (runGauntletTests) {
violationRules {
rule {
limit {
minimum = 0.4
}
}
}
}
else {
violationRules {
rule {
limit {
minimum = 0.6
}
}
}
}
}
// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification
version = opensearch_build
distZip {
archiveFileName = "performance-analyzer-rca-${version}.zip"
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.opensearch'
artifactId = 'performanceanalyzer-rca'
from components.java
}
}
}
test {
if (!runGauntletTests) {
filter {
excludeTestsMatching 'org.opensearch.performanceanalyzer.rca.integTests.*'
// TODO: Fix this test as it causes OutOfMemoryError: Java heap space error and runs forever
excludeTestsMatching 'org.opensearch.performanceanalyzer.reader.OSMetricsSnapshotTests'
}
}
else {
filter {
includeTestsMatching 'org.opensearch.performanceanalyzer.rca.integTests.*'
// Ignore failing tests (known issues with the test)
excludeTestsMatching 'org.opensearch.performanceanalyzer.rca.integTests.tests.jvmsizing.HeapSizeIncreaseMissingMetricsTest'
excludeTestsMatching 'org.opensearch.performanceanalyzer.rca.integTests.tests.consolidate_tuning.JvmFlipFlopITest'
}
}
enabled = true
retry {
maxRetries = 2
maxFailures = 20
filter {
// filter by qualified class name (* matches zero or more of any character)
// ignoring retries on all the integ test as the retries on them fails
// retry plugin is unable to retry the following test methods as the method name differs for these tests.
// java.lang.Class#testDataNodeMissingGcMetrics
excludeClasses.add("*integTests*")
}
}
}
tasks.withType(Test) {
jvmArgs('--add-opens=java.base/java.io=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.util.concurrent=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.time=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.util.stream=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/sun.nio.fs=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.nio.file=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.lang=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.util=ALL-UNNAMED')
if (JavaVersion.current().compareTo(JavaVersion.VERSION_17) > 0) {
jvmArgs += ["-Djava.security.manager=allow"]
}
}
task rcaTest(type: Test) {
useJUnit {
includeCategories 'org.opensearch.performanceanalyzer.rca.GradleTaskForRca'
}
testLogging.showStandardStreams = true
}
task rcaIt(type: Test) {
dependsOn spotbugsMain
useJUnit {
includeCategories 'org.opensearch.performanceanalyzer.rca.integTests.framework.RcaItMarker'
}
//testLogging.showStandardStreams = true
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
compileJava {
dependsOn spotlessApply
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
if (targetVersion.isJava9Compatible()) {
options.compilerArgs += ["--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED"]
options.compilerArgs += ["--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"]
}
}
javadoc {
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
if (targetVersion.isJava9Compatible()) {
options.addStringOption("-add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED")
options.addStringOption("-add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED")
}
}
project.afterEvaluate {
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility)
// cannot contain the first version
// should be '8' or '11' etc.
String version = targetVersion.toString()
if (version.length() > 2) {
version = targetVersion.toString().substring(2)
}
compileJava.options.compilerArgs.removeAll(['--release', version])
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
}
configurations {
includeJars
dockerBuild
}
tasks.withType(JavaCompile) {
options.warnings = false
}
import org.opensearch.gradle.VersionProperties
dependencies {
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
implementation files("${System.properties['java.home']}/../lib/tools.jar")
}
def versions = VersionProperties.versions
def commonslangVersion = "${versions.commonslang}"
def jacksonVersion = "${versions.jackson}"
def jacksonDataBindVersion = "${versions.jackson_databind}"
def nettyVersion = "${versions.netty}"
def junitVersion = "${versions.junit}"
def log4jVersion = "${versions.log4j}"
def protobufVersion = "${versions.protobuf}"
def guavaVersion = "${versions.guava}"
def jakartaVersion = "${versions.jakarta_annotation}"
// Sqlite and JOOQ version are coupled, see https://www.jooq.org/download/support-matrix
// In case they fall out of compatibility, JOOQ will throw error message:
// 'No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse>
def jooqVersion = "3.16.20"
def sqliteVersion = "3.41.2.2"
implementation "org.jooq:jooq:${jooqVersion}"
implementation 'org.bouncycastle:bcprov-jdk15to18:1.78.1'
implementation 'org.bouncycastle:bcpkix-jdk15to18:1.78.1'
implementation "org.xerial:sqlite-jdbc:${sqliteVersion}"
implementation "com.google.guava:guava:${guavaVersion}"
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.checkerframework:checker-qual:3.29.0'
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonDataBindVersion}"
implementation "org.opensearch:performance-analyzer-commons:${paCommonsVersion}"
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: "${log4jVersion}"
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${log4jVersion}"
implementation group: 'org.apache.commons', name: 'commons-lang3', version: "${commonslangVersion}"
implementation group: 'commons-io', name: 'commons-io', version: '2.7'
implementation group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.9.0'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: "${protobufVersion}"
implementation 'io.grpc:grpc-netty:1.56.1'
implementation 'io.grpc:grpc-protobuf:1.56.1'
implementation("io.netty:netty-codec-http2:${nettyVersion}")
implementation("io.netty:netty-handler-proxy:${nettyVersion}")
implementation 'io.grpc:grpc-stub:1.52.1'
implementation "jakarta.annotation:jakarta.annotation-api:${jakartaVersion}"
// JDK9+ has to run powermock 2+. https://github.com/powermock/powermock/issues/888
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0'
testImplementation("org.mockito:mockito-core") {
version {
strictly "2.23.0"
}
}
testImplementation group: 'org.powermock', name: 'powermock-core', version: '2.0.2'
testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.2'
testImplementation group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.2'
testImplementation group: 'org.powermock', name: 'powermock-reflect', version: '2.0.2'
testImplementation group: 'org.javassist', name: 'javassist', version: '3.28.0-GA'
testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.7'
testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.2'
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
testImplementation group: 'junit', name: 'junit', version: "${junitVersion}"
testImplementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.41.2.2'
testImplementation group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.19.0'
// Required for Docker build
dockerBuild group: 'org.opensearch.plugin', name:'performance-analyzer', version: "${opensearch_build}"
}
configurations.each {
c -> c.resolutionStrategy.dependencySubstitution {
all { DependencySubstitution dependency ->
if (dependency.requested.group == 'org.apache.bcel') {
dependency.useTarget 'org.apache.bcel:bcel:6.6.1'
}
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.21.12"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.52.1'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
idea {
module {
sourceDirs += file("${projectDir}/build/generated/source/proto/main/java");
sourceDirs += file("${projectDir}/build/generated/source/proto/main/grpc");
}
}
import groovy.json.JsonSlurper
import java.nio.file.Paths
String paDir
String dockerBuildDir
String dockerArtifactsDir
String file_ext = "zip"
task pullPAPlugin(type: Copy) {
dockerBuildDir = Paths.get(getProject().getBuildDir().toString(), "docker-build").toString()
mkdir dockerBuildDir
paDir = Paths.get(dockerBuildDir, "pa")
mkdir paDir
println String.format('opensearch_version: (%s), plugin_version: (%s), snapshot: (%s), qualifier: (%s).', opensearch_version, version, isSnapshot, buildVersionQualifier)
from(configurations.dockerBuild)
into(paDir)
rename "performance-analyzer-${version}.${file_ext}", "opensearch-performance-analyzer-${version}.${file_ext}"
println String.format('Pulled PA Plugin at: (%s), will be used for Docker Build', Paths.get(paDir, "opensearch-performance-analyzer-${version}.${file_ext}"))
}
task copyAllArtifacts(type: Copy) {
dependsOn(assemble, publishToMavenLocal, pullPAPlugin)
def projectPathStr = getProjectDir().toPath().toString()
def dockerArtifacts = Paths.get(projectPathStr, 'docker').toString()
def rcaArtifacts = Paths.get(projectPathStr, 'build', 'distributions', "performance-analyzer-rca-${version}.${file_ext}")
def paArtifacts = Paths.get(dockerBuildDir, 'pa', "opensearch-performance-analyzer-${version}.${file_ext}")
dockerArtifactsDir = Paths.get(dockerBuildDir, 'rca-docker')
mkdir dockerArtifactsDir
from(dockerArtifacts)
from(rcaArtifacts)
from(paArtifacts)
into(dockerArtifactsDir)
}
task copyReaderMetricsFiles(type: Copy) {
dependsOn(pullPAPlugin)
copy {
from ('src/test/resources/reader') {
}
into 'build/private/test_resources'
}
}
task buildDocker(type: Exec) {
dependsOn(copyAllArtifacts)
workingDir(dockerArtifactsDir)
commandLine 'docker', 'build', '-t', 'opensearch/pa-rca:3.0', '.', '--build-arg', "JDK_VER=${buildDockerJdkVersion}"
}
task runDocker(type: Exec) {
dependsOn(buildDocker)
workingDir(dockerArtifactsDir)
// This block is included to make the runDocker task work with Github Actions
// It sets the path to the docker-compose program from an environment variable
// The DOCKER_COMPOSE_LOCATION environment variable is set in the gradle.yml file inside the
// performance-analyzer repository.
def docker_compose_location = "docker-compose"
if (System.getenv("DOCKER_COMPOSE_LOCATION") != null) {
docker_compose_location = System.getenv("DOCKER_COMPOSE_LOCATION")
}
environment 'DATA_VOLUME1', 'opensearchdata1'
environment 'DATA_VOLUME2', 'opensearchdata2'
commandLine(docker_compose_location,
'-f', 'docker-compose.yml',
'-f', 'docker-compose.hostports.yml',
'-f', 'docker-compose.cluster.yml',
'up', 'opensearch1', 'opensearch2')
}
def printCommandOutput(proc) {
Thread.start {
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
System.out.println("Here is the standard output of the command:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}
int exitVal = proc.waitFor()
System.out.println("Process exitValue: " + exitVal);
}
def runCommand(commandArr, envArr, workingDir, printOutput) {
try {
Process proc = Runtime.getRuntime().exec(commandArr, envArr, file(workingDir))
if (printOutput) {
printCommandOutput(proc)
}
} catch (Throwable th) {
th.printStackTrace()
}
}
def runInProcess(commandArr) {
Process proc = new ProcessBuilder(commandArr).start();
printCommandOutput(proc)
}
def runDockerCompose = { executionPath ->
// This block is included to make the runDocker task work with Github Actions
// It sets the path to the docker-compose program from an environment variable
// The DOCKER_COMPOSE_LOCATION environment variable is set in the gradle.yml file inside the
// performance-analyzer repository.
String dockerCompose = System.getenv("DOCKER_COMPOSE_LOCATION") == null ?
"docker-compose" : System.getenv("DOCKER_COMPOSE_LOCATION")
String[] commandArray = [dockerCompose,
'-f', 'docker-compose.yml',
'-f', 'docker-compose.hostports.yml',
'-f', 'docker-compose.cluster.yml',
'up', 'opensearch1', 'opensearch2']
String[] env = ['DATA_VOLUME1=opensearchdata1',
'DATA_VOLUME2=opensearchdata2']
runCommand(commandArray, env, file(executionPath), true)
}
def getHttpResponse(server, timeoutSeconds) {
URL url = new URL(server)
long timeout = timeoutSeconds * 1000
long increments = 1000
long passed = 0
println 'waiting for ' + server
while (passed < timeout) {
try {
HttpURLConnection con = (HttpURLConnection) url.openConnection()
con.setRequestMethod("GET")
InputStreamReader isr = new InputStreamReader(con.getInputStream())
BufferedReader bufR = new BufferedReader(isr)
String inputLine;
StringBuffer content = new StringBuffer()
while ((inputLine = bufR.readLine()) != null) {
content.append(inputLine);
}
println(content.toString())
bufR.close()
break
} catch (IOException) {
Thread.sleep(increments);
passed += increments
}
}
if (passed == timeout) {
throw new GradleException(String.format("ERROR: %s not ready.", server));
}
}
/**
* enableComponent is used to enable PA or RCA based on the given parameters
* @param endpoint the endpoint to make the request against e.g. localhost:9200/pa/rca/example
* @param desiredState
* The list of enabled components is represented as an n-bit binary number
* The LSB represents the state of PA and the LSB+1th bit is RCA
* 0x03 (00000011 in binary) is therefore a state where both PA and RCA are enabled
* @param timeoutSeconds we will attempt to enable the component for this many seconds before
* giving up and throwing a GradleException
*/
def enableComponent(endpoint, desiredState, timeoutSeconds) {
long timeout = timeoutSeconds * 1000
long increments = 1000
long passed = 0
println 'waiting for ' + endpoint
while (passed < timeout) {
try {
def p = ['curl', endpoint, '-H', 'Content-Type: application/json', '-d', '{"enabled": true}'].execute()
def json = new JsonSlurper().parseText(p.text)
if (json.get("currentPerformanceAnalyzerClusterState").equals(desiredState) ||
// desiredState+2 means that the "next" significant component is enabled
json.get("currentPerformanceAnalyzerClusterState").equals(desiredState + 2)) {
break
}
} catch (Exception) {
}
Thread.sleep(increments);
passed += increments
}
if (passed == timeout) {
throw new GradleException(String.format("ERROR: %s not ready.", endpoint));
}
}
Boolean openSearchIsUp
def openSearchUpChecker = {
String server = "http://localhost:9200"
int timeoutSeconds = 2 * 60
getHttpResponse(server, timeoutSeconds)
openSearchIsUp = true
}
// Attempts to enable PA for up to 2 minutes. Returns when PA is successfully enabled or
// throws an Exception if the timeout is exceeded
def paUpChecker = {
String server = "localhost:9200/_plugins/_performanceanalyzer/cluster/config"
int timeoutSeconds = 2 * 60
enableComponent(server, 1, timeoutSeconds)
}
// Attempts to enable RCA for up to 2 minutes. Returns when RCA is successfully enabled or
// throws an Exception if the timeout is exceeded
def rcaUpChecker = {
String server = "localhost:9200/_plugins/_performanceanalyzer/rca/cluster/config"
int timeoutSeconds = 2 * 60
enableComponent(server, 3, timeoutSeconds)
}
Thread openSearchRunnerThread
def runInThread(cl, input) {
return Thread.start {
cl(input)
}
}
task waitForOpenSearch {
dependsOn(buildDocker)
doLast {
openSearchRunnerThread = runInThread(runDockerCompose, dockerArtifactsDir)
openSearchUpChecker()
}
}
String perfTopDir
String perfTopZip
String perfTopBin
task downloadPerfTop(type: Download) {
String zip = 'perf-top-1.9.0.0-MACOS.zip'
perfTopDir = Paths.get(dockerBuildDir, 'perftop').toString()
mkdir perfTopDir
src 'https://d3g5vo6xdbdb9a.cloudfront.net/downloads/perftop/' + zip
dest perfTopDir
overwrite false
perfTopZip = Paths.get(perfTopDir, zip).toString()
File f = file(perfTopZip)
enabled = !f.exists() //to clone only once
}
task unzipPerfTop(type: Copy) {
dependsOn(downloadPerfTop)
perfTopBin = Paths.get(perfTopDir, 'perf-top-macos').toString()
def zipFile = file(perfTopZip)
def outputDir = file(perfTopDir)
from zipTree(zipFile)
into outputDir
enabled = !file(perfTopBin).exists()
}
// Attempts to enable PA for up to 2 minutes. Returns when PA is successfully enabled or
// throws an Exception if the timeout is exceeded
task enablePa() {
dependsOn(waitForOpenSearch)
doLast {
paUpChecker()
}
}
// Attempts to enable RCA for up to 2 minutes. Returns when RCA is successfully enabled or
// throws an Exception if the timeout is exceeded
task enableRca() {
dependsOn(enablePa)
doLast {
rcaUpChecker()
}
}
task runPerftop {
dependsOn(enableRca, unzipPerfTop)
doLast {
println '============================================================================'
println 'invoke perftop as: '
println String.format("%s --dashboard %s", Paths.get(perfTopBin).toString(), 'ClusterOverview')
println '============================================================================'
}
}
task generateLoad {
dependsOn(enableRca, runPerftop)
doLast {
String[] deleteIndex = ['curl', '-X', 'DELETE', 'localhost:9200/accounts?pretty']
String[] bulk = ['curl', '-s', '-H', "Content-Type: application/x-ndjson",
'-XPOST', 'localhost:9200/_bulk', '--data-binary', '@accounts.json']
String[] search = ['curl', '-X', 'GET', 'localhost:9200/_search?pretty', '-H',
'Content-Type:application/json', '-d',
'{"query": {"range": {"balance": {"gte": 100, "lte": 100000}}}}']
String wdir = Paths.get(getProjectDir().getAbsolutePath(), 'src', 'test', 'resources')
.toString()
while (true) {
// runCommand(deleteIndex, null, wdir, false)
//println("starting indexing: " + System.currentTimeMillis())
runCommand(bulk, null, wdir, false)
//println("completed indexing: " + System.currentTimeMillis())
Thread.sleep(3000)
//println("starting search" + System.currentTimeMillis())
runCommand(search, null, wdir, false)
Thread.sleep(1000)
//println("completed search" + System.currentTimeMillis())
runCommand(deleteIndex, null, wdir, false)
Thread.sleep(1000)
}
}
}
task runRally {
dependsOn(enableRca, runPerftop)
doLast {
String rallyTrack='pmc'
String[] opensearchrally = ['docker', 'run', '--network=host', 'elastic/rally',
'--track=' + rallyTrack, '--test-mode', '--pipeline=benchmark-only',
'--target-hosts=localhost:9200']
String wdir = Paths.get(getProjectDir().getAbsolutePath(), 'src', 'test', 'resources')
.toString()
while (true) {
runCommand(opensearchrally, null, wdir, true)
println('Get all RCAs using:')
println('curl localhost:9600/_plugins/_performanceanalyzer/rca?all | python -m json.tool')
Thread.sleep(1000)
}
}
}
// updateVersion: Task to auto increment to the next development iteration
task updateVersion {
onlyIf { System.getProperty('newVersion') }
doLast {
ext.newVersion = System.getProperty('newVersion')
println "Setting version to ${newVersion}."
// String tokenization to support -SNAPSHOT
ant.replaceregexp(match: opensearch_version.tokenize('-')[0], replace: newVersion.tokenize('-')[0], flags:'g', byline:true) {
fileset(dir: projectDir) {
// Include the required files that needs to be updated with new Version
include(name: "INSTALL.md")
include(name: "docker/Dockerfile")
include(name: "src/main/resources/plugin-descriptor.properties")
}
}
ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true)
}
}