forked from mitch-seymour/mastering-kafka-streams-and-ksqldb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
124 lines (105 loc) · 3.68 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
plugins {
id 'application'
// https://plugins.gradle.org/plugin/com.github.sherter.google-java-format
id 'com.github.sherter.google-java-format' version '0.9'
// used for containerizing the app
id 'com.google.cloud.tools.jib' version '3.2.1'
// for downloading a Prometheus JMX Exporter JAR that can run as a Java agent
id 'de.undercouch.download' version '5.0.5'
// for benchmarking
id 'me.champeau.gradle.jmh' version '0.5.3'
}
ext {
kafkaVersion = '2.6.2'
opencensusVersion = '0.31.1'
simpleclientVersion = '0.6.0'
prometheusJmxExporterVersion='0.16.1'
}
/**
* The below task will download the JAR needed for running the Prometheus JMX
* exporter as a Java agent. If you prefer to run the exporter as a standalone
* HTTP server instead (which allows us to add custom metrics to our Kafka
* Streams app, and is what we've implemented in App.java), feel free to delete
* this Gradle task.
*/
task downloadPrometheusExporter(type: Download) {
src "https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${prometheusJmxExporterVersion}/jmx_prometheus_javaagent-${prometheusJmxExporterVersion}.jar"
dest new File('files', 'jmx_prometheus_javaagent.jar')
}
jib {
to {
image = 'magicalpipelines/myapp:0.1.0'
}
extraDirectories.paths = ['files']
container {
jvmFlags = [
/**
* The port we expose JMX metrics on should match the port in the JMX
* url that is defined in jmx_prometheus_exporter.yaml
*/
'-Dcom.sun.management.jmxremote.port=5555',
'-Dcom.sun.management.jmxremote.local.only=true',
'-Dcom.sun.management.jmxremote.authenticate=false',
'-Dcom.sun.management.jmxremote.ssl=false',
/**
* Uncomment the line below to run the Prometheus JMX exporter as a
* Java agent. Agent mode is suitable if you don't have any custom
* metrics that you want to instrument in your Kafka Streams app.
*/
//'-javaagent:./jmx_prometheus_javaagent.jar=8080:jmx_prometheus_exporter.yaml',
]
mainClass = application.mainClassName
ports = ['8080', '9010']
labels = [key1:'value1', key2:'value2']
format = 'OCI'
}
}
tasks.build.dependsOn tasks.jibDockerBuild
tasks.jibDockerBuild.dependsOn tasks.downloadPrometheusExporter
application {
// run the DSL example by default
mainClassName = 'com.magicalpipelines.App'
}
repositories {
mavenCentral()
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
implementation "org.apache.kafka:kafka-streams:${kafkaVersion}"
implementation 'ch.qos.logback:logback-classic:1.2.11'
// configuration
implementation "com.typesafe:config:1.4.2"
// observability dependencies
implementation "io.prometheus.jmx:jmx_prometheus_httpserver:${prometheusJmxExporterVersion}"
implementation "io.opencensus:opencensus-api:${opencensusVersion}"
implementation "io.opencensus:opencensus-impl:${opencensusVersion}"
implementation "io.opencensus:opencensus-exporter-stats-prometheus:${opencensusVersion}"
// test dependencies
testImplementation "org.apache.kafka:kafka-streams-test-utils:${kafkaVersion}"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
}
// code formatting
tasks.withType(JavaCompile).configureEach { javaCompile ->
javaCompile.dependsOn 'googleJavaFormat'
options.encoding = 'UTF-8'
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
// for benchmarking
jmh {
iterations = 4
benchmarkMode = ['thrpt']
threads = 1
fork = 1
timeOnIteration = '3s'
resultFormat = 'TEXT'
profilers = []
warmupIterations = 3
warmup = '1s'
}