diff --git a/monitoring-samples/task-apps/task-demo-metrics-prometheus/README.md b/monitoring-samples/task-apps/task-demo-metrics-prometheus/README.md
index c3c8ee6..c92ff51 100644
--- a/monitoring-samples/task-apps/task-demo-metrics-prometheus/README.md
+++ b/monitoring-samples/task-apps/task-demo-metrics-prometheus/README.md
@@ -6,84 +6,55 @@ The `task-demo-metrics-prometheus` project creates a sample Spring Cloud Task (a
## Create custom Spring Cloud Task
If you use the provided `task-demo-metrics-prometheus` source code you can skip this section.
-Otherwise follow the instructions below to build your own `monitorable` Task from scratch.
+Otherwise, follow the instructions below to build your own `monitorable` Task from scratch.
-Bootstrap by follow the [Task development instructions](https://docs.spring.io/spring-cloud-task/docs/2.0.0.RELEASE/reference/htmlsingle/#getting-started-developing-first-task) and then:
+Follow the [Task development instructions](https://docs.spring.io/spring-cloud-task/docs/2.3.0/reference/#getting-started-developing-first-task) and then:
-* Set the parent POM version of Boot to 2.2.1.RELEASE or latest
+* Set the parent POM version of Boot to 2.4.3 or latest
```xml
- org.springframework.boot
- spring-boot-starter-parent
- 2.2.1.RELEASE
-
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.4.3
+
```
-* Make sure that `spring-cloud-dependencies` version `Hoxton.RC1` or newer are imported:
+* Make sure that `spring-cloud-task-dependencies` version `2.3.0` or newer are imported:
```xml
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- Hoxton.RC1
- pom
- import
-
+
+
+
+ org.springframework.cloud
+ spring-cloud-task-dependencies
+ 2.3.0
+ pom
+ import
+
+
```
-* Add dependencies to enable the `Spring Cloud Task` (and optionally `Spring Task Batch`) functionality and to configure the jdbc dependencies for the task repository.
-Use version `2.2.0.RC1` or newer!
+* Enable Spring Batch and Spring Cloud Task
```xml
org.springframework.cloud
spring-cloud-starter-task
- 2.2.0.RC1
-
-
- org.springframework.cloud
- spring-cloud-task-core
- 2.2.0.RC1
-
-
-
-
- org.springframework.cloud
- spring-cloud-task-batch
- 2.2.0.RC1
-
-
- org.springframework.cloud
- spring-cloud-task-stream
- 2.2.0.RC1
+
+ org.springframework.boot
+ spring-boot-starter-batch
+
-
-
-
- org.springframework.cloud
- spring-cloud-task-dependencies
- 2.2.0.RC1
- pom
- import
-
-
-
```
* Add dependencies to configure the jdbc dependencies for the task repository:
```xml
-
- org.springframework.boot
- spring-boot-starter-jdbc
-
org.mariadb.jdbc
mariadb-java-client
@@ -97,18 +68,114 @@ To enable Prometheus metrics collection add:
```xml
- io.micrometer.prometheus
- prometheus-rsocket-spring
- 0.9.0
+ io.micrometer
+ micrometer-registry-prometheus
+
+
+ io.micrometer.prometheus
+ prometheus-rsocket-spring
+ 1.3.0
io.micrometer.prometheus
prometheus-rsocket-client
- 0.9.0
+ 1.3.0
```
-Note that the version must be `0.9.0` or newer.
+* Configure the Application metadata generation
+
+```xml
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+```
+
+```xml
+
+ org.springframework.cloud
+ spring-cloud-dataflow-apps-metadata-plugin
+ 1.0.2
+
+ true
+
+
+
+
+ io.spring.task.taskdemometrics.TaskDemoMetricsProperties
+
+
+
+
+
+ aggregate-metadata
+ compile
+
+ aggregate-metadata
+
+
+
+
+
+ org.codehaus.mojo
+ properties-maven-plugin
+ 1.0.0
+
+
+ process-classes
+
+ read-project-properties
+
+
+
+ ${project.build.outputDirectory}/META-INF/spring-configuration-metadata-encoded.properties
+
+
+
+
+
+
+ io.fabric8
+ docker-maven-plugin
+ 0.33.0
+
+
+
+ springcloudtask/${project.artifactId}
+
+
+ latest
+ ${project.version}
+
+ springcloud/baseimage:1.0.0
+
+ /tmp
+
+
+
+ ${org.springframework.cloud.dataflow.spring.configuration.metadata.json}
+
+
+
+
+ java
+ -jar
+ /maven/task-demo-metrics-prometheus.jar
+
+
+
+ assembly.xml
+
+
+
+
+
+
+
+```
+
## Build
Run
@@ -116,7 +183,7 @@ Run
./mvnw clean install
```
-Will produce `task-demo-metrics-prometheus-0.0.1-SNAPSHOT.jar` task application under the `target` folder.
+Will produce `task-demo-metrics-prometheus-0.0.4-SNAPSHOT.jar` task application under the `target` folder.
## Spring Cloud Data FLow server
@@ -129,5 +196,4 @@ Build and publish docker image
```
./mvnw clean install docker:build
./mvnw docker:push
-
```
diff --git a/monitoring-samples/task-apps/task-demo-metrics-prometheus/pom.xml b/monitoring-samples/task-apps/task-demo-metrics-prometheus/pom.xml
index a45dbe5..6c9bf6d 100644
--- a/monitoring-samples/task-apps/task-demo-metrics-prometheus/pom.xml
+++ b/monitoring-samples/task-apps/task-demo-metrics-prometheus/pom.xml
@@ -56,6 +56,11 @@
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
io.micrometer.prometheus
prometheus-rsocket-spring
@@ -65,11 +70,6 @@
io.micrometer
micrometer-registry-prometheus
-
- org.springframework.boot
- spring-boot-configuration-processor
- true
-
io.micrometer.prometheus
prometheus-rsocket-client
@@ -95,6 +95,48 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ org.springframework.cloud
+ spring-cloud-dataflow-apps-metadata-plugin
+ 1.0.2
+
+ true
+
+
+
+
+ io.spring.task.taskdemometrics.TaskDemoMetricsProperties
+
+
+
+
+
+ aggregate-metadata
+ compile
+
+ aggregate-metadata
+
+
+
+
+
+ org.codehaus.mojo
+ properties-maven-plugin
+ 1.0.0
+
+
+ process-classes
+
+ read-project-properties
+
+
+
+ ${project.build.outputDirectory}/META-INF/spring-configuration-metadata-encoded.properties
+
+
+
+
+
io.fabric8
docker-maven-plugin
@@ -112,6 +154,11 @@
/tmp
+
+
+ ${org.springframework.cloud.dataflow.spring.configuration.metadata.json}
+
+
java
diff --git a/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsApplication.java b/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsApplication.java
index 5739a80..ca08be4 100644
--- a/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsApplication.java
+++ b/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsApplication.java
@@ -15,12 +15,14 @@ import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableTask
@EnableBatchProcessing
+@EnableConfigurationProperties(TaskDemoMetricsProperties.class)
public class TaskDemoMetricsApplication {
@Autowired
@@ -29,6 +31,9 @@ public class TaskDemoMetricsApplication {
@Autowired
public StepBuilderFactory stepBuilderFactory;
+ @Autowired
+ private TaskDemoMetricsProperties properties;
+
private Random random = new Random();
public static void main(String[] args) {
@@ -48,7 +53,7 @@ public class TaskDemoMetricsApplication {
public Step step1() {
return this.stepBuilderFactory.get("step1")
.chunk(10)
- .reader(new ListItemReader<>(IntStream.rangeClosed(0, this.random.nextInt(100))
+ .reader(new ListItemReader<>(IntStream.rangeClosed(0, this.random.nextInt(properties.getRange()))
.boxed().collect(Collectors.toList())))
.writer(list -> list.forEach(e -> {
if ((e % 100) == 0) {
@@ -61,7 +66,8 @@ public class TaskDemoMetricsApplication {
public Step step2() {
return this.stepBuilderFactory.get("step2")
.tasklet((contribution, context) -> {
- Thread.sleep(2 * 60 * 1000 + this.random.nextInt(10000));
+ Thread.sleep(properties.getDelay().getFixed().toMillis()
+ + this.random.nextInt((int) properties.getDelay().getRandom().toMillis()));
return RepeatStatus.FINISHED;
}).build();
}
@@ -71,7 +77,8 @@ public class TaskDemoMetricsApplication {
return jobBuilderFactory.get("job2")
.start(stepBuilderFactory.get("job2step1")
.tasklet((contribution, chunkContext) -> {
- Thread.sleep(this.random.nextInt(10000));
+ Thread.sleep(properties.getDelay().getFixed().toMillis()
+ + this.random.nextInt((int) properties.getDelay().getRandom().toMillis()));
return RepeatStatus.FINISHED;
})
.build())
diff --git a/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsProperties.java b/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsProperties.java
new file mode 100644
index 0000000..c987620
--- /dev/null
+++ b/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/java/io/spring/task/taskdemometrics/TaskDemoMetricsProperties.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License 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.
+ */
+package io.spring.task.taskdemometrics;
+
+import java.time.Duration;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author Christian Tzolov
+ */
+@ConfigurationProperties(prefix = "task.demo")
+public class TaskDemoMetricsProperties {
+
+ private int range = 100;
+ private Delay delay = new Delay(Duration.ofMinutes(1), Duration.ofSeconds(10));
+
+ public static class Delay {
+
+ private Duration fixed = Duration.ofSeconds(0);
+ private Duration random = Duration.ofSeconds(1);
+
+ public Delay(Duration fixed, Duration random) {
+ this.fixed = fixed;
+ this.random = random;
+ }
+
+ public Duration getFixed() {
+ return fixed;
+ }
+
+ public void setFixed(Duration fixed) {
+ this.fixed = fixed;
+ }
+
+ public Duration getRandom() {
+ return random;
+ }
+
+ public void setRandom(Duration random) {
+ this.random = random;
+ }
+ }
+
+ public int getRange() {
+ return range;
+ }
+
+ public Delay getDelay() {
+ return delay;
+ }
+}
diff --git a/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/resources/dataflow-configuration-metadata.properties b/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/resources/dataflow-configuration-metadata.properties
new file mode 100644
index 0000000..35bf636
--- /dev/null
+++ b/monitoring-samples/task-apps/task-demo-metrics-prometheus/src/main/resources/dataflow-configuration-metadata.properties
@@ -0,0 +1 @@
+configuration-properties.classes=io.spring.task.taskdemometrics.TaskDemoMetricsProperties