-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2882: add server telemetry example implementation
- Loading branch information
Mattia Brescia
committed
Jun 10, 2024
1 parent
64987f4
commit 749833f
Showing
18 changed files
with
322 additions
and
6 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
factcast-examples/factcast-example-server-telemetry/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.factcast</groupId> | ||
<artifactId>factcast-examples</artifactId> | ||
<version>0.7.9-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>factcast-example-server-telemetry</artifactId> | ||
<properties> | ||
<!-- Pin your own Spring Boot version. --> | ||
<spring-boot.version>3.3.0</spring-boot.version> | ||
<docker.image.prefix>factcast</docker.image.prefix> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.factcast</groupId> | ||
<artifactId>factcast-bom</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.factcast</groupId> | ||
<artifactId>factcast-spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.factcast</groupId> | ||
<artifactId>factcast-server-grpc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.factcast</groupId> | ||
<artifactId>factcast-store</artifactId> | ||
</dependency> | ||
<!-- you want to remove this --> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>${testcontainers.version}</version> | ||
</dependency> | ||
<!-- /you want to remove this --> | ||
</dependencies> | ||
<build> | ||
<finalName>factcast</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
<configuration> | ||
<executable>true</executable> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.spotify</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<version>1.2.2</version> | ||
<configuration> | ||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName> | ||
<dockerDirectory>src/main/docker</dockerDirectory> | ||
<resources> | ||
<resource> | ||
<targetPath>/</targetPath> | ||
<directory>${project.build.directory}</directory> | ||
<include>${project.build.finalName}.jar</include> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
factcast-examples/factcast-example-server-telemetry/src/main/docker/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM frolvlad/alpine-oraclejdk8:slim | ||
MAINTAINER uwe.schaefer <factcast-auth-7234@codesmell.de> | ||
VOLUME /tmp | ||
COPY factcast.jar app.jar | ||
RUN sh -c 'touch /app.jar' | ||
ENV JAVA_OPTS="" | ||
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] |
18 changes: 18 additions & 0 deletions
18
...ample-server-telemetry/src/main/java/org/factcast/example/server/ActuatorContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.factcast.example.server; | ||
|
||
import org.factcast.example.server.telemetry.MyTelemetryListener; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.info.Info; | ||
import org.springframework.boot.actuate.info.InfoContributor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ActuatorContributor implements InfoContributor { | ||
|
||
@Autowired | ||
MyTelemetryListener listener; | ||
|
||
public void contribute(Info.Builder builder) { | ||
builder.withDetail("followingSubscriptionsInfo", listener.getFollowingSubscriptionsInfo()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...server-telemetry/src/main/java/org/factcast/example/server/ExampleServerWithTelemtry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright © 2017-2020 factcast.org | ||
* | ||
* 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 org.factcast.example.server; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.postgresql.Driver; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
/** | ||
* Spring boot starter for running a factcast server. | ||
* | ||
* <p>This should contain a pgsql backend and grpc API frontend. | ||
* | ||
* @author uwe.schaefer@prisma-capacity.eu | ||
*/ | ||
@SuppressWarnings("ALL") | ||
@SpringBootApplication | ||
@Slf4j | ||
public class ExampleServerWithTelemtry { | ||
|
||
public static void main(String[] args) { | ||
// you will want to replace this with RDS, a local pgsql database or | ||
// whatever your usecase is. | ||
startPostgresContainer(); | ||
|
||
SpringApplication.run(ExampleServerWithTelemtry.class, args); | ||
} | ||
|
||
private static void startPostgresContainer() { | ||
log.info("Trying to start postgres testcontainer"); | ||
PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:15.2"); | ||
postgres.start(); | ||
String url = postgres.getJdbcUrl(); | ||
System.setProperty("spring.datasource.driver-class-name", Driver.class.getName()); | ||
System.setProperty("spring.datasource.url", url); | ||
System.setProperty("spring.datasource.username", postgres.getUsername()); | ||
System.setProperty("spring.datasource.password", postgres.getPassword()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...cast-examples/factcast-example-server-telemetry/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
spring.datasource.tomcat.max-wait=20000 | ||
spring.datasource.tomcat.remove-abandoned-timeout=360000 | ||
spring.datasource.tomcat.test-on-borrow=true | ||
# ensure RDS reconnect behavior (issue #53) | ||
spring.datasource.tomcat.connectionProperties=socketTimeout=20;connectTimeout=10;loginTimeout=10; | ||
factcast.security.enabled=false | ||
#spring.datasource.url=jdbc:postgresql://localhost/factcast | ||
#spring.datasource.username=doc | ||
#spring.datasource.password=doc | ||
factcast.store.schemaRegistryUrl=classpath:example-registry | ||
#factcast.store.allowUnvalidatedPublish=true | ||
#factcast.store.persistentSchemaStore=false | ||
management.server.port=9091 | ||
management.endpoints.web.exposure.include=* | ||
management.endpoint.info.enabled=true |
10 changes: 10 additions & 0 deletions
10
factcast-examples/factcast-example-server-telemetry/src/main/resources/banner.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
███████╗ █████╗ ██████╗████████╗ ██████╗ █████╗ ███████╗████████╗ | ||
██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗██╔════╝╚══██╔══╝ | ||
█████╗ ███████║██║ ██║ ██║ ███████║███████╗ ██║ | ||
██╔══╝ ██╔══██║██║ ██║ ██║ ██╔══██║╚════██║ ██║ | ||
██║ ██║ ██║╚██████╗ ██║ ╚██████╗██║ ██║███████║ ██║ | ||
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ | ||
factcast-example-server-telemetry | ||
|
1 change: 1 addition & 0 deletions
1
...examples/factcast-example-server-telemetry/src/main/resources/example-registry/index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"schemes":[{"id":"users/UserCreated/1/schema.json","ns":"users","type":"UserCreated","version":1,"hash":"24d48268356e3cb7ac2f148850e4aac1"},{"id":"users/UserCreated/2/schema.json","ns":"users","type":"UserCreated","version":2,"hash":"8fb5294baa827a46f5f0138fe08f04f3"},{"id":"users/UserCreated/3/schema.json","ns":"users","type":"UserCreated","version":3,"hash":"f61380a21bcd935a3a1b919b90374d61"}],"transformations":[{"id":"users/UserCreated/1-2/transform.js","ns":"users","type":"UserCreated","from":1,"to":2,"hash":"546d80170d224d6f24b276f3b8c4656e"},{"id":"users/UserCreated/3-2/transform.js","ns":"users","type":"UserCreated","from":3,"to":2,"hash":"e32be57fbe84391b9415b49cf730d400"},{"id":"users/UserCreated/2-3/transform.js","ns":"users","type":"UserCreated","from":2,"to":3,"hash":"bf85130f22ed18a0b559dc904059457d"},{"ns":"users","type":"UserCreated","from":2,"to":1,"id":"synthetic/users/UserCreated/2-1/transform.js"}]} |
3 changes: 3 additions & 0 deletions
3
...e-server-telemetry/src/main/resources/example-registry/users/UserCreated/1-2/transform.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function transform(event) { | ||
event.salutation = "NA" | ||
} |
12 changes: 12 additions & 0 deletions
12
...mple-server-telemetry/src/main/resources/example-registry/users/UserCreated/1/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"additionalProperties" : true, | ||
"properties" : { | ||
"firstName" : { | ||
"type": "string" | ||
}, | ||
"lastName" : { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["firstName", "lastName"] | ||
} |
3 changes: 3 additions & 0 deletions
3
...e-server-telemetry/src/main/resources/example-registry/users/UserCreated/2-3/transform.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function transform(event) { | ||
event.displayName = event.firstName + " " + event.lastName | ||
} |
16 changes: 16 additions & 0 deletions
16
...mple-server-telemetry/src/main/resources/example-registry/users/UserCreated/2/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"additionalProperties" : true, | ||
"properties" : { | ||
"firstName" : { | ||
"type": "string" | ||
}, | ||
"lastName" : { | ||
"type": "string" | ||
}, | ||
"salutation": { | ||
"type": "string", | ||
"enum": ["Mr", "Mrs", "NA"] | ||
} | ||
}, | ||
"required": ["firstName", "lastName", "salutation"] | ||
} |
3 changes: 3 additions & 0 deletions
3
...e-server-telemetry/src/main/resources/example-registry/users/UserCreated/3-2/transform.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function transform(event) { | ||
// just a dummy downcast transformation | ||
} |
19 changes: 19 additions & 0 deletions
19
...mple-server-telemetry/src/main/resources/example-registry/users/UserCreated/3/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"additionalProperties" : true, | ||
"properties" : { | ||
"firstName" : { | ||
"type": "string" | ||
}, | ||
"lastName" : { | ||
"type": "string" | ||
}, | ||
"salutation": { | ||
"type": "string", | ||
"enum": ["Mr", "Mrs", "NA"] | ||
}, | ||
"displayName": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["firstName", "lastName", "salutation", "displayName"] | ||
} |
20 changes: 20 additions & 0 deletions
20
factcast-examples/factcast-example-server-telemetry/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="STDOUT" | ||
class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder | ||
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<pattern> | ||
%-5level %logger - %msg%n | ||
</pattern> | ||
</encoder> | ||
</appender> | ||
<logger name="org.testcontainers" level="warn"> | ||
<appender-ref ref="STDOUT" /> | ||
</logger> | ||
<root level="warn"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<logger name="org.factcast" level="DEBUG"> | ||
</logger> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.