Add properties task demo prmehteus and doc
This commit is contained in:
@@ -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
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<relativePath/>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
```
|
||||
* 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
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>Hoxton.RC1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-dependencies</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
```
|
||||
|
||||
* 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
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-task</artifactId>
|
||||
<version>2.2.0.RC1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-core</artifactId>
|
||||
<version>2.2.0.RC1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Required when Spring Batch is used -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-batch</artifactId>
|
||||
<version>2.2.0.RC1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-stream</artifactId>
|
||||
<version>2.2.0.RC1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-batch</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-dependencies</artifactId>
|
||||
<version>2.2.0.RC1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
```
|
||||
|
||||
* Add dependencies to configure the jdbc dependencies for the task repository:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
@@ -97,18 +68,114 @@ To enable Prometheus metrics collection add:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>io.micrometer.prometheus</groupId>
|
||||
<artifactId>prometheus-rsocket-spring</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer.prometheus</groupId>
|
||||
<artifactId>prometheus-rsocket-spring</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer.prometheus</groupId>
|
||||
<artifactId>prometheus-rsocket-client</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
```
|
||||
Note that the version must be `0.9.0` or newer.
|
||||
|
||||
* Configure the Application metadata generation
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
```xml
|
||||
<plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dataflow-apps-metadata-plugin</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<configuration>
|
||||
<storeFilteredMetadata>true</storeFilteredMetadata>
|
||||
<metadataFilter>
|
||||
<names>
|
||||
</names>
|
||||
<sourceTypes>
|
||||
<filter>io.spring.task.taskdemometrics.TaskDemoMetricsProperties</filter>
|
||||
</sourceTypes>
|
||||
</metadataFilter>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>aggregate-metadata</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>aggregate-metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>${project.build.outputDirectory}/META-INF/spring-configuration-metadata-encoded.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>0.33.0</version>
|
||||
<configuration>
|
||||
<images>
|
||||
<image>
|
||||
<name>springcloudtask/${project.artifactId}</name>
|
||||
<build>
|
||||
<tags>
|
||||
<tag>latest</tag>
|
||||
<tag>${project.version}</tag>
|
||||
</tags>
|
||||
<from>springcloud/baseimage:1.0.0</from>
|
||||
<volumes>
|
||||
<volume>/tmp</volume>
|
||||
</volumes>
|
||||
<labels>
|
||||
<org.springframework.cloud.dataflow.spring-configuration-metadata.json>
|
||||
${org.springframework.cloud.dataflow.spring.configuration.metadata.json}
|
||||
</org.springframework.cloud.dataflow.spring-configuration-metadata.json>
|
||||
</labels>
|
||||
<entryPoint>
|
||||
<exec>
|
||||
<arg>java</arg>
|
||||
<arg>-jar</arg>
|
||||
<arg>/maven/task-demo-metrics-prometheus.jar</arg>
|
||||
</exec>
|
||||
</entryPoint>
|
||||
<assembly>
|
||||
<descriptor>assembly.xml</descriptor>
|
||||
</assembly>
|
||||
</build>
|
||||
</image>
|
||||
</images>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
```
|
||||
|
||||
@@ -56,6 +56,11 @@
|
||||
|
||||
<!-- Enable Prometheus metrics collection (via Prometheus RSocket Proxy) -->
|
||||
<!-- Internally it imports the org.springframework.boot:spring-boot-actuator-autoconfigure dependency -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer.prometheus</groupId>
|
||||
<artifactId>prometheus-rsocket-spring</artifactId>
|
||||
@@ -65,11 +70,6 @@
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer.prometheus</groupId>
|
||||
<artifactId>prometheus-rsocket-client</artifactId>
|
||||
@@ -95,6 +95,48 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dataflow-apps-metadata-plugin</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<configuration>
|
||||
<storeFilteredMetadata>true</storeFilteredMetadata>
|
||||
<metadataFilter>
|
||||
<names>
|
||||
</names>
|
||||
<sourceTypes>
|
||||
<filter>io.spring.task.taskdemometrics.TaskDemoMetricsProperties</filter>
|
||||
</sourceTypes>
|
||||
</metadataFilter>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>aggregate-metadata</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>aggregate-metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>${project.build.outputDirectory}/META-INF/spring-configuration-metadata-encoded.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
@@ -112,6 +154,11 @@
|
||||
<volumes>
|
||||
<volume>/tmp</volume>
|
||||
</volumes>
|
||||
<labels>
|
||||
<org.springframework.cloud.dataflow.spring-configuration-metadata.json>
|
||||
${org.springframework.cloud.dataflow.spring.configuration.metadata.json}
|
||||
</org.springframework.cloud.dataflow.spring-configuration-metadata.json>
|
||||
</labels>
|
||||
<entryPoint>
|
||||
<exec>
|
||||
<arg>java</arg>
|
||||
|
||||
@@ -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")
|
||||
.<Integer, Integer>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())
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
configuration-properties.classes=io.spring.task.taskdemometrics.TaskDemoMetricsProperties
|
||||
Reference in New Issue
Block a user