-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
688 lines (592 loc) · 21.6 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
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
buildscript {
dependencies {
classpath group: 'com.google.guava', name: 'guava', version: '28.2-jre'
classpath 'org.ajoberstar:gradle-git:0.2.3'
}
}
plugins {
id 'java'
id 'checkstyle'
id 'application'
id 'maven-publish'
id 'com.google.protobuf' version '0.8.8'
id 'jacoco'
id 'idea'
id 'com.github.spotbugs' version '4.0.0'
id "de.undercouch.download" version "4.0.4"
id 'com.adarshr.test-logger' version '2.1.0'
}
application {
mainClassName = 'com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp'
applicationDefaultJvmArgs = ['-Xms64M',
'-Xmx64M',
'-XX:+UseSerialGC',
'-XX:CICompilerCount=1',
'-XX:-TieredCompilation',
'-XX:InitialCodeCacheSize=4096',
'-XX:InitialBootClassLoaderMetaspaceSize=30720',
'-XX:MaxRAM=400m']
}
// Include pa_config folder in the distribution.
applicationDistribution.from(".") {
include 'pa_config/*'
include 'pa_bin/*'
}
distributions {
main {
contents {
eachFile {
it.path = it.path.replace("-$version/", '/')
}
}
}
}
distZip {
archiveName 'performance-analyzer-rca.zip'
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.amazon.opendistro.elasticsearch'
artifactId = 'performanceanalyzer-rca'
version = '1.10'
from components.java
}
}
}
ext {
opendistroVersion = '1.10'
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
}
checkstyle {
toolVersion '8.24'
configFile file("configs/checkstyle/checkstyle.xml")
}
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 = 'max'
ignoreFailures = false
reports {
xml.enabled = false
html.enabled = true
}
}
spotbugsTest {
ignoreFailures = true
}
check {
dependsOn spotbugsMain
//dependsOn spotbugsTest
}
jacoco {
toolVersion = "0.8.5"
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
csv.enabled false
}
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/**'
],
exclude: [
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/grpc/**',
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/api/metrics/**',
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/net/requests**'
])
})
}
}
jacocoTestCoverageVerification {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/**',
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/**'
],
exclude: [
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/grpc/**'])
})
}
violationRules {
rule {
limit {
minimum = 0.8
}
}
}
}
// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification
version = "${opendistroVersion}.0"
if (isSnapshot) {
version += "-SNAPSHOT"
}
test {
enabled = true
}
task rcaTest(type: Test) {
dependsOn checkstyleMain
dependsOn checkstyleTest
useJUnit {
includeCategories 'com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.GradleTaskForRca'
}
testLogging.showStandardStreams = true
}
task rcaIt(type: Test) {
dependsOn checkstyleMain
dependsOn checkstyleTest
dependsOn spotbugsMain
useJUnit {
includeCategories 'com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.integTests.framework.RcaItMarker'
}
//testLogging.showStandardStreams = true
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava {
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
if (targetVersion.isJava9Compatible()) {
options.compilerArgs += ["--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED"]
}
}
javadoc {
options.addStringOption("-add-exports", "jdk.attach/sun.tools.attach=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 {
mavenCentral()
}
configurations {
includeJars
}
tasks.withType(JavaCompile) {
options.warnings = false
}
dependencies {
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
compile files("${System.properties['java.home']}/../lib/tools.jar")
}
compile 'org.jooq:jooq:3.10.8'
compile 'org.bouncycastle:bcprov-jdk15on:1.66'
compile 'org.bouncycastle:bcpkix-jdk15on:1.66'
compile 'org.xerial:sqlite-jdbc:3.8.11.2'
compile 'com.google.guava:guava:28.2-jre'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.10.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.10.4'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
compile group: 'commons-io', name: 'commons-io', version: '2.3'
implementation 'io.grpc:grpc-netty-shaded:1.28.0'
implementation 'io.grpc:grpc-protobuf:1.28.0'
implementation 'io.grpc:grpc-stub:1.28.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
// JDK9+ has to run powermock 2+. https://github.com/powermock/powermock/issues/888
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.0'
testCompile group: 'org.powermock', name: 'powermock-core', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.0'
testCompile group: 'org.javassist', name: 'javassist', version: '3.24.0-GA'
testCompile group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
testCompile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.3'
testCompile group: 'org.objenesis', name: 'objenesis', version: '3.0.1'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'
testCompile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.11.0"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.28.0'
}
}
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
import org.ajoberstar.gradle.git.tasks.GitClone
String paDir
String dockerBuildDir
String dockerArtifactsDir
task cloneGitRepo(type: GitClone) {
dockerBuildDir = Paths.get(getProject().getBuildDir().toString(), "docker-build").toString()
mkdir dockerBuildDir
if (localPaDir != null && !localPaDir.empty) {
// If you already have the performance Analyzer sources checked out then update the
// localPaDir in gradle.properties with the path.
paDir = localPaDir
} else {
paDir = Paths.get(dockerBuildDir, "pa").toString()
}
def destination = file(paDir)
uri = "https://github.com/opendistro-for-elasticsearch/performance-analyzer.git"
destinationPath = destination
bare = false
enabled = !destination.exists() //to clone only once
}
task removeLicenses(type: Delete) {
dependsOn(cloneGitRepo)
def toDelete = Paths.get(paDir, 'licenses', 'performanceanalyzer-rca-1.10.jar.sha1')
delete(toDelete)
}
task regenerateLicenses(type: Exec) {
dependsOn(removeLicenses)
workingDir(paDir)
commandLine './gradlew', 'updateShas'
}
task buildPa(type: Exec) {
dependsOn(assemble, publishToMavenLocal, regenerateLicenses)
workingDir paDir
println String.format('pa in dir: (%s) will be built.', paDir)
commandLine './gradlew', 'assemble'
println "PA repo located at '" + paDir + "' will be used."
}
task copyAllArtifacts(type: Copy) {
dependsOn(buildPa)
def projectPathStr = getProjectDir().toPath().toString()
def dockerArtifacts = Paths.get(projectPathStr, 'docker').toString()
def rcaArtifacts = Paths.get(projectPathStr, 'build', 'distributions', 'performance-analyzer-rca.zip')
def paArtifacts = Paths.get(paDir, 'build', 'distributions', 'opendistro_performance_analyzer-1.10.0.0-SNAPSHOT.zip')
dockerArtifactsDir = Paths.get(dockerBuildDir, 'rca-docker')
from(dockerArtifacts)
from(rcaArtifacts)
from(paArtifacts)
into(dockerArtifactsDir)
}
task copyReaderMetricsFiles(type: Copy) {
dependsOn(buildPa)
copy{
from ('src/test/resources/reader'){
}
into 'build/private/test_resources'
}
}
task buildDocker(type: Exec) {
dependsOn(copyAllArtifacts)
workingDir(dockerArtifactsDir)
commandLine 'docker', 'build', '-t', 'odfe-es/pa-rca:1.0', '.'
}
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', 'esdata1'
environment 'DATA_VOLUME2', 'esdata2'
commandLine(docker_compose_location,
'-f', 'docker-compose.yml',
'-f', 'docker-compose.hostports.yml',
'-f', 'docker-compose.cluster.yml',
'up', 'elasticsearch1', 'elasticsearch2')
}
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', 'elasticsearch1', 'elasticsearch2']
String[] env = ['DATA_VOLUME1=esdata1',
'DATA_VOLUME2=esdata2']
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 esIsUp
def esUpChecker = {
String server = "http://localhost:9200"
int timeoutSeconds = 2 * 60
getHttpResponse(server, timeoutSeconds)
esIsUp = 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/_opendistro/_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/_opendistro/_performanceanalyzer/rca/cluster/config"
int timeoutSeconds = 2 * 60
enableComponent(server, 3, timeoutSeconds)
}
Thread esRunnerThread
def runInThread(cl, input) {
return Thread.start {
cl(input)
}
}
task waitForES {
dependsOn(buildDocker)
doLast {
esRunnerThread = runInThread(runDockerCompose, dockerArtifactsDir)
esUpChecker()
}
}
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(waitForES)
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[] esrally = ['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(esrally, null, wdir, true)
println('Get all RCAs using:')
println('curl localhost:9600/_opendistro/_performanceanalyzer/rca?all | python -m json.tool')
Thread.sleep(1000)
}
}
}