forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Core] Support record metrics in flink engine (apache#6035)
- Loading branch information
1 parent
456cd17
commit a9ec9d5
Showing
19 changed files
with
1,092 additions
and
20 deletions.
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
57 changes: 57 additions & 0 deletions
57
seatunnel-common/src/test/java/org/apache/seatunnel/common/utils/DateTimeUtilsTest.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,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.seatunnel.common.utils; | ||
|
||
import org.apache.seatunnel.common.utils.DateTimeUtils.Formatter; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
|
||
public class DateTimeUtilsTest { | ||
|
||
@Test | ||
public void testParseDateString() { | ||
final String datetime = "2023-12-22 00:00:00"; | ||
LocalDateTime parse = DateTimeUtils.parse(datetime, Formatter.YYYY_MM_DD_HH_MM_SS); | ||
Assertions.assertEquals(0, parse.getMinute()); | ||
Assertions.assertEquals(0, parse.getHour()); | ||
Assertions.assertEquals(0, parse.getSecond()); | ||
Assertions.assertEquals(22, parse.getDayOfMonth()); | ||
Assertions.assertEquals(12, parse.getMonth().getValue()); | ||
Assertions.assertEquals(2023, parse.getYear()); | ||
Assertions.assertEquals(22, parse.getDayOfMonth()); | ||
} | ||
|
||
@Test | ||
public void testParseTimestamp() { | ||
// 2023-12-22 12:55:20 | ||
final long timestamp = 1703220920013L; | ||
LocalDateTime parse = DateTimeUtils.parse(timestamp, ZoneId.of("Asia/Shanghai")); | ||
|
||
Assertions.assertEquals(55, parse.getMinute()); | ||
Assertions.assertEquals(12, parse.getHour()); | ||
Assertions.assertEquals(20, parse.getSecond()); | ||
Assertions.assertEquals(22, parse.getDayOfMonth()); | ||
Assertions.assertEquals(12, parse.getMonth().getValue()); | ||
Assertions.assertEquals(2023, parse.getYear()); | ||
Assertions.assertEquals(22, parse.getDayOfMonth()); | ||
} | ||
} |
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
156 changes: 156 additions & 0 deletions
156
...nector-fake-e2e/src/test/java/org/apache/seatunnel/e2e/connector/fake/FlinkMetricsIT.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,156 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.seatunnel.e2e.connector.fake; | ||
|
||
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import org.apache.seatunnel.api.common.metrics.MetricNames; | ||
import org.apache.seatunnel.common.utils.JsonUtils; | ||
import org.apache.seatunnel.e2e.common.TestSuiteBase; | ||
import org.apache.seatunnel.e2e.common.container.EngineType; | ||
import org.apache.seatunnel.e2e.common.container.TestContainer; | ||
import org.apache.seatunnel.e2e.common.container.flink.Flink13Container; | ||
import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer; | ||
|
||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.Container; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@DisabledOnContainer( | ||
value = {}, | ||
type = {EngineType.SPARK, EngineType.SEATUNNEL}) | ||
public class FlinkMetricsIT extends TestSuiteBase { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FlinkMetricsIT.class); | ||
|
||
@TestTemplate | ||
public void testFlinkMetrics(TestContainer container) throws IOException, InterruptedException { | ||
Container.ExecResult executeResult = | ||
container.executeJob("/fake_to_assert_verify_flink_metrics.conf"); | ||
Assertions.assertEquals(0, executeResult.getExitCode()); | ||
final String jobListUrl = "http://%s:8081/jobs/overview"; | ||
final String jobDetailsUrl = "http://%s:8081/jobs/%s"; | ||
final String jobAccumulatorUrl = "http://%s:8081/jobs/%s/vertices/%s/accumulators"; | ||
final String jobManagerHost; | ||
String dockerHost = System.getenv("DOCKER_HOST"); | ||
if (dockerHost == null) { | ||
jobManagerHost = "localhost"; | ||
} else { | ||
URI uri = URI.create(dockerHost); | ||
jobManagerHost = uri.getHost(); | ||
} | ||
// create http client | ||
CloseableHttpClient httpClient = HttpClients.createDefault(); | ||
|
||
// get job id | ||
HttpGet httpGet = new HttpGet(String.format(jobListUrl, jobManagerHost)); | ||
CloseableHttpResponse response = httpClient.execute(httpGet); | ||
Assertions.assertEquals(response.getStatusLine().getStatusCode(), 200); | ||
String responseContent = EntityUtils.toString(response.getEntity()); | ||
ObjectNode jsonNode = JsonUtils.parseObject(responseContent); | ||
String jobId = jsonNode.get("jobs").get(0).get("jid").asText(); | ||
Assertions.assertNotNull(jobId); | ||
|
||
// get job vertices | ||
httpGet = new HttpGet(String.format(jobDetailsUrl, jobManagerHost, jobId)); | ||
response = httpClient.execute(httpGet); | ||
Assertions.assertEquals(response.getStatusLine().getStatusCode(), 200); | ||
|
||
responseContent = EntityUtils.toString(response.getEntity()); | ||
jsonNode = JsonUtils.parseObject(responseContent); | ||
String verticeId = jsonNode.get("vertices").get(0).get("id").asText(); | ||
|
||
Awaitility.given() | ||
.ignoreExceptions() | ||
.await() | ||
.atMost(10L, TimeUnit.SECONDS) | ||
.untilAsserted( | ||
() -> { | ||
HttpGet httpGetTemp = | ||
new HttpGet( | ||
String.format( | ||
jobAccumulatorUrl, | ||
jobManagerHost, | ||
jobId, | ||
verticeId)); | ||
CloseableHttpResponse responseTemp = httpClient.execute(httpGetTemp); | ||
String responseContentTemp = | ||
EntityUtils.toString(responseTemp.getEntity()); | ||
JsonNode jsonNodeTemp = JsonUtils.parseObject(responseContentTemp); | ||
JsonNode metrics = jsonNodeTemp.get("user-accumulators"); | ||
int size = metrics.size(); | ||
if (size <= 0) { | ||
throw new IllegalStateException( | ||
"Flink metrics not synchronized yet, next round"); | ||
} | ||
}); | ||
|
||
// get metrics | ||
httpGet = new HttpGet(String.format(jobAccumulatorUrl, jobManagerHost, jobId, verticeId)); | ||
response = httpClient.execute(httpGet); | ||
responseContent = EntityUtils.toString(response.getEntity()); | ||
jsonNode = JsonUtils.parseObject(responseContent); | ||
JsonNode metrics = jsonNode.get("user-accumulators"); | ||
|
||
int size = metrics.size(); | ||
|
||
Assertions.assertTrue(size > 0); | ||
|
||
Map<String, String> metricsMap = new HashMap<>(); | ||
|
||
for (JsonNode metric : metrics) { | ||
String name = metric.get("name").asText(); | ||
String value = metric.get("value").asText(); | ||
metricsMap.put(name, value); | ||
} | ||
|
||
String sourceReceivedCount = metricsMap.get(MetricNames.SOURCE_RECEIVED_COUNT); | ||
String sourceReceivedBytes = metricsMap.get(MetricNames.SOURCE_RECEIVED_BYTES); | ||
|
||
Assertions.assertEquals(5, Integer.valueOf(sourceReceivedCount)); | ||
Assertions.assertEquals(2160, Integer.valueOf(sourceReceivedBytes)); | ||
|
||
// Due to limitations in Flink 13 version and code, the metrics on the writer side cannot be | ||
// aggregated into the global accumulator and can only be viewed in the operator based on | ||
// parallelism dimensions | ||
if (!(container instanceof Flink13Container)) { | ||
String sinkWriteCount = metricsMap.get(MetricNames.SINK_WRITE_COUNT); | ||
String sinkWriteBytes = metricsMap.get(MetricNames.SINK_WRITE_BYTES); | ||
Assertions.assertEquals(5, Integer.valueOf(sinkWriteCount)); | ||
Assertions.assertEquals(2160, Integer.valueOf(sinkWriteBytes)); | ||
} | ||
|
||
httpClient.close(); | ||
} | ||
} |
Oops, something went wrong.