Skip to content

Commit bd89d84

Browse files
authored
[improve][API] support metrics interface in rest v2 (#8312)
1 parent eae32bf commit bd89d84

File tree

17 files changed

+382
-183
lines changed

17 files changed

+382
-183
lines changed

docs/en/seatunnel-engine/rest-api-v2.md

+15
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,18 @@ To get a list of logs from the current node: `http://localhost:5801/log`
845845
To get the content of a log file: `http://localhost:5801/log/job-898380162133917698.log`
846846

847847
</details>
848+
849+
850+
### Get Node Metrics
851+
852+
<details>
853+
<summary>
854+
<code>GET</code> <code><b>/metrics</b></code>
855+
<code>GET</code> <code><b>/openmetrics</b></code>
856+
</summary>
857+
858+
To get the metrics, you need to open `Telemetry` first, or you will get an empty response.
859+
860+
More information about `Telemetry` can be found in the [Telemetry](telemetry.md) documentation.
861+
862+
</details>

docs/zh/seatunnel-engine/rest-api-v2.md

+13
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,16 @@ sink {
850850
获取日志文件内容:`http://localhost:5801/log/job-898380162133917698.log``
851851

852852
</details>
853+
854+
### 获取节点指标信息
855+
856+
<details>
857+
<summary>
858+
<code>GET</code> <code><b>/metrics</b></code>
859+
<code>GET</code> <code><b>/openmetrics</b></code>
860+
</summary>
861+
你需要先打开`Telemetry`才能获取集群指标信息。否则将返回空信息。
862+
863+
更多关于`Telemetry`的信息可以在[Telemetry](telemetry.md)文档中找到。
864+
865+
</details>

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<jcommander.version>1.81</jcommander.version>
123123
<junit4.version>4.13.2</junit4.version>
124124
<junit5.version>5.9.0</junit5.version>
125+
<rest-assured.version>5.4.0</rest-assured.version>
125126
<mockito.version>4.11.0</mockito.version>
126127
<config.version>1.3.3</config.version>
127128
<maven-shade-plugin.version>3.4.1</maven-shade-plugin.version>

seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/ClusterSeaTunnelEngineContainer.java

+35-35
Large diffs are not rendered by default.

seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/MultiTableMetricsIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void multiTableMetrics() {
9191
.getAddress()
9292
.getPort()
9393
+ RestConstant.CONTEXT_PATH
94-
+ RestConstant.JOB_INFO_URL
94+
+ RestConstant.REST_URL_JOB_INFO
9595
+ "/"
9696
+ batchJobProxy.getJobId());
9797
// In the test example, the data size of a single [3, "C", 100] is 13

seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RestApiIT.java

+51-35
Large diffs are not rendered by default.

seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/classloader/ClassLoaderITBase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void testFakeSourceToInMemorySinkForRestApi() throws IOException, Interru
136136
+ colon
137137
+ server.getFirstMappedPort()
138138
+ RestConstant.CONTEXT_PATH
139-
+ RestConstant.SUBMIT_JOB_URL)
139+
+ RestConstant.REST_URL_SUBMIT_JOB)
140140
.then()
141141
.statusCode(200);
142142

@@ -150,7 +150,7 @@ public void testFakeSourceToInMemorySinkForRestApi() throws IOException, Interru
150150
+ colon
151151
+ server.getFirstMappedPort()
152152
+ RestConstant.CONTEXT_PATH
153-
+ RestConstant.FINISHED_JOBS_INFO
153+
+ RestConstant.REST_URL_FINISHED_JOBS
154154
+ "/FINISHED")
155155
.then()
156156
.statusCode(200)

seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/joblog/JobLogIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ private Response submitJob(
269269
+ ":"
270270
+ container.getFirstMappedPort()
271271
+ RestConstant.CONTEXT_PATH
272-
+ RestConstant.SUBMIT_JOB_URL
272+
+ RestConstant.REST_URL_SUBMIT_JOB
273273
: "http://"
274274
+ container.getHost()
275275
+ ":"
276276
+ container.getFirstMappedPort()
277277
+ RestConstant.CONTEXT_PATH
278-
+ RestConstant.SUBMIT_JOB_URL
278+
+ RestConstant.REST_URL_SUBMIT_JOB
279279
+ "?"
280280
+ parameters);
281281
return response;

seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/telemetry/MasterWorkerClusterSeaTunnelWithTelemetryIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void startUp() throws Exception {
121121
+ colon
122122
+ server.getFirstMappedPort()
123123
+ CONTEXT_PATH
124-
+ RestConstant.JOB_INFO_URL
124+
+ RestConstant.REST_URL_JOB_INFO
125125
+ "/"
126126
+ JobId)
127127
.then()
@@ -652,13 +652,13 @@ private Response submitJob(
652652
+ colon
653653
+ port
654654
+ contextPath
655-
+ RestConstant.SUBMIT_JOB_URL
655+
+ RestConstant.REST_URL_SUBMIT_JOB
656656
: http
657657
+ container.getHost()
658658
+ colon
659659
+ port
660660
+ contextPath
661-
+ RestConstant.SUBMIT_JOB_URL
661+
+ RestConstant.REST_URL_SUBMIT_JOB
662662
+ "?"
663663
+ parameters);
664664
return response;

seatunnel-engine/seatunnel-engine-server/pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@
108108
<classifier>optional</classifier>
109109
<scope>provided</scope>
110110
</dependency>
111+
112+
<dependency>
113+
<groupId>io.rest-assured</groupId>
114+
<artifactId>rest-assured</artifactId>
115+
<version>${rest-assured.version}</version>
116+
<scope>test</scope>
117+
<exclusions>
118+
<exclusion>
119+
<groupId>org.codehaus.groovy</groupId>
120+
<artifactId>groovy</artifactId>
121+
</exclusion>
122+
</exclusions>
123+
</dependency>
111124
<dependency>
112125
<groupId>org.apache.seatunnel</groupId>
113126
<artifactId>seatunnel-e2e-common</artifactId>

seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/JettyService.java

+45-37
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.seatunnel.engine.server.rest.servlet.EncryptConfigServlet;
3232
import org.apache.seatunnel.engine.server.rest.servlet.FinishedJobsServlet;
3333
import org.apache.seatunnel.engine.server.rest.servlet.JobInfoServlet;
34+
import org.apache.seatunnel.engine.server.rest.servlet.MetricsServlet;
3435
import org.apache.seatunnel.engine.server.rest.servlet.OverviewServlet;
3536
import org.apache.seatunnel.engine.server.rest.servlet.RunningJobsServlet;
3637
import org.apache.seatunnel.engine.server.rest.servlet.RunningThreadsServlet;
@@ -53,23 +54,25 @@
5354
import java.net.URL;
5455
import java.util.EnumSet;
5556

56-
import static org.apache.seatunnel.engine.server.rest.RestConstant.ENCRYPT_CONFIG;
57-
import static org.apache.seatunnel.engine.server.rest.RestConstant.FINISHED_JOBS_INFO;
58-
import static org.apache.seatunnel.engine.server.rest.RestConstant.GET_ALL_LOG_NAME;
59-
import static org.apache.seatunnel.engine.server.rest.RestConstant.GET_LOG;
60-
import static org.apache.seatunnel.engine.server.rest.RestConstant.GET_LOGS;
61-
import static org.apache.seatunnel.engine.server.rest.RestConstant.JOB_INFO_URL;
62-
import static org.apache.seatunnel.engine.server.rest.RestConstant.OVERVIEW;
63-
import static org.apache.seatunnel.engine.server.rest.RestConstant.RUNNING_JOBS_URL;
64-
import static org.apache.seatunnel.engine.server.rest.RestConstant.RUNNING_JOB_URL;
65-
import static org.apache.seatunnel.engine.server.rest.RestConstant.RUNNING_THREADS;
66-
import static org.apache.seatunnel.engine.server.rest.RestConstant.STOP_JOBS_URL;
67-
import static org.apache.seatunnel.engine.server.rest.RestConstant.STOP_JOB_URL;
68-
import static org.apache.seatunnel.engine.server.rest.RestConstant.SUBMIT_JOBS_URL;
69-
import static org.apache.seatunnel.engine.server.rest.RestConstant.SUBMIT_JOB_URL;
70-
import static org.apache.seatunnel.engine.server.rest.RestConstant.SYSTEM_MONITORING_INFORMATION;
71-
import static org.apache.seatunnel.engine.server.rest.RestConstant.THREAD_DUMP;
72-
import static org.apache.seatunnel.engine.server.rest.RestConstant.UPDATE_TAGS_URL;
57+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_ENCRYPT_CONFIG;
58+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_FINISHED_JOBS;
59+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_GET_ALL_LOG_NAME;
60+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_JOB_INFO;
61+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_LOG;
62+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_LOGS;
63+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_METRICS;
64+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_OPEN_METRICS;
65+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_OVERVIEW;
66+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_RUNNING_JOB;
67+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_RUNNING_JOBS;
68+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_RUNNING_THREADS;
69+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_STOP_JOB;
70+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_STOP_JOBS;
71+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_SUBMIT_JOB;
72+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_SUBMIT_JOBS;
73+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_SYSTEM_MONITORING_INFORMATION;
74+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_THREAD_DUMP;
75+
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_UPDATE_TAGS;
7376

7477
/** The Jetty service for SeaTunnel engine server. */
7578
@Slf4j
@@ -134,26 +137,31 @@ public void createJettyServer() {
134137
new ServletHolder(new CurrentNodeLogServlet(nodeEngine));
135138
ServletHolder allLogNameServlet = new ServletHolder(new AllLogNameServlet(nodeEngine));
136139

137-
context.addServlet(overviewHolder, convertUrlToPath(OVERVIEW));
138-
context.addServlet(runningJobsHolder, convertUrlToPath(RUNNING_JOBS_URL));
139-
context.addServlet(finishedJobsHolder, convertUrlToPath(FINISHED_JOBS_INFO));
140-
context.addServlet(systemMonitoringHolder, convertUrlToPath(SYSTEM_MONITORING_INFORMATION));
141-
context.addServlet(jobInfoHolder, convertUrlToPath(JOB_INFO_URL));
142-
context.addServlet(jobInfoHolder, convertUrlToPath(RUNNING_JOB_URL));
143-
context.addServlet(threadDumpHolder, convertUrlToPath(THREAD_DUMP));
144-
145-
context.addServlet(submitJobHolder, convertUrlToPath(SUBMIT_JOB_URL));
146-
context.addServlet(submitJobsHolder, convertUrlToPath(SUBMIT_JOBS_URL));
147-
context.addServlet(stopJobHolder, convertUrlToPath(STOP_JOB_URL));
148-
context.addServlet(stopJobsHolder, convertUrlToPath(STOP_JOBS_URL));
149-
context.addServlet(encryptConfigHolder, convertUrlToPath(ENCRYPT_CONFIG));
150-
context.addServlet(updateTagsHandler, convertUrlToPath(UPDATE_TAGS_URL));
151-
152-
context.addServlet(runningThreadsHolder, convertUrlToPath(RUNNING_THREADS));
153-
154-
context.addServlet(allNodeLogServletHolder, convertUrlToPath(GET_LOGS));
155-
context.addServlet(currentNodeLogServlet, convertUrlToPath(GET_LOG));
156-
context.addServlet(allLogNameServlet, convertUrlToPath(GET_ALL_LOG_NAME));
140+
ServletHolder metricsServlet = new ServletHolder(new MetricsServlet(nodeEngine));
141+
142+
context.addServlet(overviewHolder, convertUrlToPath(REST_URL_OVERVIEW));
143+
context.addServlet(runningJobsHolder, convertUrlToPath(REST_URL_RUNNING_JOBS));
144+
context.addServlet(finishedJobsHolder, convertUrlToPath(REST_URL_FINISHED_JOBS));
145+
context.addServlet(
146+
systemMonitoringHolder, convertUrlToPath(REST_URL_SYSTEM_MONITORING_INFORMATION));
147+
context.addServlet(jobInfoHolder, convertUrlToPath(REST_URL_JOB_INFO));
148+
context.addServlet(jobInfoHolder, convertUrlToPath(REST_URL_RUNNING_JOB));
149+
context.addServlet(threadDumpHolder, convertUrlToPath(REST_URL_THREAD_DUMP));
150+
151+
context.addServlet(submitJobHolder, convertUrlToPath(REST_URL_SUBMIT_JOB));
152+
context.addServlet(submitJobsHolder, convertUrlToPath(REST_URL_SUBMIT_JOBS));
153+
context.addServlet(stopJobHolder, convertUrlToPath(REST_URL_STOP_JOB));
154+
context.addServlet(stopJobsHolder, convertUrlToPath(REST_URL_STOP_JOBS));
155+
context.addServlet(encryptConfigHolder, convertUrlToPath(REST_URL_ENCRYPT_CONFIG));
156+
context.addServlet(updateTagsHandler, convertUrlToPath(REST_URL_UPDATE_TAGS));
157+
158+
context.addServlet(runningThreadsHolder, convertUrlToPath(REST_URL_RUNNING_THREADS));
159+
160+
context.addServlet(allNodeLogServletHolder, convertUrlToPath(REST_URL_LOGS));
161+
context.addServlet(currentNodeLogServlet, convertUrlToPath(REST_URL_LOG));
162+
context.addServlet(allLogNameServlet, convertUrlToPath(REST_URL_GET_ALL_LOG_NAME));
163+
context.addServlet(metricsServlet, convertUrlToPath(REST_URL_METRICS));
164+
context.addServlet(metricsServlet, convertUrlToPath(REST_URL_OPEN_METRICS));
157165

158166
server.setHandler(context);
159167

seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestConstant.java

+24-25
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,33 @@ public class RestConstant {
6060
public static final String TABLE_SINK_WRITE_BYTES_PER_SECONDS = "TableSinkWriteBytesPerSeconds";
6161

6262
public static final String CONTEXT_PATH = "/hazelcast/rest/maps";
63-
64-
public static final String OVERVIEW = "/overview";
65-
66-
public static final String RUNNING_JOBS_URL = "/running-jobs";
67-
@Deprecated public static final String RUNNING_JOB_URL = "/running-job";
68-
public static final String JOB_INFO_URL = "/job-info";
69-
public static final String FINISHED_JOBS_INFO = "/finished-jobs";
70-
public static final String ENCRYPT_CONFIG = "/encrypt-config";
71-
public static final String THREAD_DUMP = "/thread-dump";
72-
63+
public static final String INSTANCE_CONTEXT_PATH = "/hazelcast/rest/instance";
64+
65+
// api path start
66+
public static final String REST_URL_OVERVIEW = "/overview";
67+
public static final String REST_URL_RUNNING_JOBS = "/running-jobs";
68+
@Deprecated public static final String REST_URL_RUNNING_JOB = "/running-job";
69+
public static final String REST_URL_JOB_INFO = "/job-info";
70+
public static final String REST_URL_FINISHED_JOBS = "/finished-jobs";
71+
public static final String REST_URL_ENCRYPT_CONFIG = "/encrypt-config";
72+
public static final String REST_URL_THREAD_DUMP = "/thread-dump";
7373
// only for test use
74-
public static final String RUNNING_THREADS = "/running-threads";
75-
76-
public static final String SYSTEM_MONITORING_INFORMATION = "/system-monitoring-information";
77-
78-
public static final String SUBMIT_JOB_URL = "/submit-job";
79-
public static final String SUBMIT_JOBS_URL = "/submit-jobs";
80-
public static final String STOP_JOB_URL = "/stop-job";
81-
public static final String STOP_JOBS_URL = "/stop-jobs";
82-
public static final String UPDATE_TAGS_URL = "/update-tags";
74+
public static final String REST_URL_RUNNING_THREADS = "/running-threads";
75+
public static final String REST_URL_SYSTEM_MONITORING_INFORMATION =
76+
"/system-monitoring-information";
77+
public static final String REST_URL_SUBMIT_JOB = "/submit-job";
78+
public static final String REST_URL_SUBMIT_JOBS = "/submit-jobs";
79+
public static final String REST_URL_STOP_JOB = "/stop-job";
80+
public static final String REST_URL_STOP_JOBS = "/stop-jobs";
81+
public static final String REST_URL_UPDATE_TAGS = "/update-tags";
8382
// Get All Nodes Log
84-
public static final String GET_LOGS = "/logs";
83+
public static final String REST_URL_LOGS = "/logs";
8584
// Get Current Node Log
86-
public static final String GET_LOG = "/log";
85+
public static final String REST_URL_LOG = "/log";
8786
// Code internal Use , Get Node Log Name
88-
public static final String GET_ALL_LOG_NAME = "/get-all-log-name";
87+
public static final String REST_URL_GET_ALL_LOG_NAME = "/get-all-log-name";
88+
public static final String REST_URL_METRICS = "/metrics";
89+
public static final String REST_URL_OPEN_METRICS = "/openmetrics";
90+
// api path end
8991

90-
// metrics
91-
public static final String TELEMETRY_METRICS_URL = "/hazelcast/rest/instance/metrics";
92-
public static final String TELEMETRY_OPEN_METRICS_URL = "/hazelcast/rest/instance/openmetrics";
9392
}

0 commit comments

Comments
 (0)