-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spring boot custom actuator worker endpoint sample (#639)
Signed-off-by: Tihomir Surdilovic <[email protected]>
- Loading branch information
Showing
7 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
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
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
13 changes: 13 additions & 0 deletions
13
springboot/src/main/java/io/temporal/samples/springboot/actuator/README.md
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,13 @@ | ||
# SpringBoot Actuator Worker Info Endpoint - Sample | ||
|
||
1. Start SpringBoot from main samples repo directory: | ||
|
||
./gradlew bootRun | ||
|
||
2. In your browser navigate to: | ||
|
||
http://localhost:3030/actuator/temporalworkerinfo | ||
|
||
This sample shows how to create a custom Actuator Endpoint that | ||
displays registered workflow and activity implementations per task queue. | ||
This information comes from actually registered workers done by autoconfig module. |
107 changes: 107 additions & 0 deletions
107
springboot/src/main/java/io/temporal/samples/springboot/actuator/WorkerActuatorEndpoint.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,107 @@ | ||
/* | ||
* Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved | ||
* | ||
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* 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://aws.amazon.com/apache2.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. | ||
*/ | ||
|
||
package io.temporal.samples.springboot.actuator; | ||
|
||
import io.temporal.common.metadata.*; | ||
import io.temporal.spring.boot.autoconfigure.template.WorkersTemplate; | ||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; | ||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Endpoint(id = "temporalworkerinfo") | ||
public class WorkerActuatorEndpoint { | ||
@Autowired | ||
@Qualifier("temporalWorkersTemplate") | ||
private WorkersTemplate workersTemplate; | ||
|
||
@ReadOperation | ||
public String workerInfo() { | ||
StringBuilder sb = new StringBuilder(); | ||
Map<String, WorkersTemplate.RegisteredInfo> registeredInfo = | ||
workersTemplate.getRegisteredInfo(); | ||
sb.append("Worker Info:"); | ||
registeredInfo.forEach( | ||
(taskQueue, info) -> { | ||
sb.append("\n\n\tTask Queue: ").append(taskQueue); | ||
info.getRegisteredWorkflowInfo() | ||
.forEach( | ||
(workflowInfo) -> { | ||
sb.append("\n\t\t Workflow Interface: ").append(workflowInfo.getClassName()); | ||
POJOWorkflowImplMetadata metadata = workflowInfo.getMetadata(); | ||
sb.append("\n\t\t\t Workflow Methods: "); | ||
sb.append( | ||
metadata.getWorkflowMethods().stream() | ||
.map(POJOWorkflowMethodMetadata::getWorkflowMethod) | ||
.map(Method::getName) | ||
.collect(Collectors.joining(", "))); | ||
sb.append("\n\t\t\t Query Methods: "); | ||
sb.append( | ||
metadata.getQueryMethods().stream() | ||
.map(POJOWorkflowMethodMetadata::getWorkflowMethod) | ||
.map(Method::getName) | ||
.collect(Collectors.joining(", "))); | ||
sb.append("\n\t\t\t Signal Methods: "); | ||
sb.append( | ||
metadata.getSignalMethods().stream() | ||
.map(POJOWorkflowMethodMetadata::getWorkflowMethod) | ||
.map(Method::getName) | ||
.collect(Collectors.joining(", "))); | ||
sb.append("\n\t\t\t Update Methods: "); | ||
sb.append( | ||
metadata.getUpdateMethods().stream() | ||
.map(POJOWorkflowMethodMetadata::getWorkflowMethod) | ||
.map(Method::getName) | ||
.collect(Collectors.joining(","))); | ||
sb.append("\n\t\t\t Update Validator Methods: "); | ||
sb.append( | ||
metadata.getUpdateValidatorMethods().stream() | ||
.map(POJOWorkflowMethodMetadata::getWorkflowMethod) | ||
.map(Method::getName) | ||
.collect(Collectors.joining(", "))); | ||
}); | ||
info.getRegisteredActivityInfo() | ||
.forEach( | ||
(activityInfo) -> { | ||
sb.append("\n\t\t Activity Impl: ").append(activityInfo.getClassName()); | ||
POJOActivityImplMetadata metadata = activityInfo.getMetadata(); | ||
sb.append("\n\t\t\t Activity Interfaces: "); | ||
sb.append( | ||
metadata.getActivityInterfaces().stream() | ||
.map(POJOActivityInterfaceMetadata::getInterfaceClass) | ||
.map(Class::getName) | ||
.collect(Collectors.joining(","))); | ||
sb.append("\n\t\t\t Activity Methods: "); | ||
sb.append( | ||
metadata.getActivityMethods().stream() | ||
.map(POJOActivityMethodMetadata::getMethod) | ||
.map(Method::getName) | ||
.collect(Collectors.joining(", "))); | ||
}); | ||
}); | ||
|
||
return sb.toString(); | ||
} | ||
} |
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
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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html"> | ||
<head th:replace="fragments :: samples-header"></head> | ||
<body> | ||
<div class="container"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h4 class="card-title" th:text="'Temporal Java SDK Samples: ' + ${sample}">Temporal Java SDK Samples</h4> | ||
<h6>In this sample we show how to create a custom Actuator Endpoint showing Worker Info.</h6> | ||
<br/><br/> | ||
<div> | ||
<h6><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html" target="_blank">Spring Actuator</a> allows | ||
us to create custom endpoints. This sample shows how to create a Worker Info custom endpoint that shows registered Workflow and Activity impls per task queue.</h6><br/> | ||
View the custom endpoint at <a href="http://localhost:3030/actuator/temporalworkerinfo" target="_blank">localhost:3030/actuator/temporalworkerinfo</a> | ||
</div> | ||
</div> | ||
</div> | ||
<footer th:replace="fragments :: samples-footer"></footer> | ||
</body> | ||
</html> |
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