Skip to content

Commit 41da77b

Browse files
committed
add flink metrics for token tableInsertCount,tableUpdateCount,tableDeleteCount
1 parent d76b122 commit 41da77b

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

tis-incr/tis-flink-cdc-kingbase-plugin/src/main/java/com/qlangtech/plugins/incr/flink/cdc/kingbase/FlinkCDCKingBaseSourceFunction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* @create: 2025-01-14 19:11
5353
**/
5454
public class FlinkCDCKingBaseSourceFunction extends FlinkCDCPGLikeSourceFunction {
55+
5556
public FlinkCDCKingBaseSourceFunction(FlinkCDCKingBaseSourceFactory sourceFactory) {
5657
super(sourceFactory);
5758
}
@@ -110,6 +111,7 @@ public boolean visit(DBConfig config, String jdbcUrl, String ip, String dbName)
110111
// .deserializer(new PostgreSQLDeserializationSchema(tabs, flinkColCreator, contextParamValsGetterMapper, sourceFactory.getRepIdentity()))
111112
// .build();
112113

114+
113115
PostgreSQLDeserializationSchema deserializer = new PostgreSQLDeserializationSchema(tabs, flinkColCreator, contextParamValsGetterMapper, sourceFactory.getRepIdentity());
114116

115117
PostgresOffsetFactory offsetFactory = new PostgresOffsetFactory();

tis-incr/tis-flink-cdc-kingbase-plugin/src/main/java/com/qlangtech/plugins/incr/flink/cdc/pglike/PostgreSQLDeserializationSchema.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.qlangtech.tis.realtime.transfer.DTO;
2828
import org.apache.kafka.connect.data.Schema;
2929
import org.apache.kafka.connect.data.Struct;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032

3133
import java.util.List;
3234
import java.util.Map;
@@ -38,6 +40,7 @@
3840
**/
3941
public class PostgreSQLDeserializationSchema extends TISDeserializationSchema {
4042
private final ReplicaIdentity replicaIdentity;
43+
private static final Logger logger = LoggerFactory.getLogger(PostgreSQLDeserializationSchema.class);
4144

4245
/**
4346
* @param tabs
@@ -51,6 +54,7 @@ public PostgreSQLDeserializationSchema(List<ISelectedTab> tabs, IFlinkColCreator
5154
) {
5255
super(new PGDTOColValProcess(tabs, flinkColCreator), new DefaultTableNameConvert(), contextParamValsGetterMapper);
5356
this.replicaIdentity = replicaIdentity;
57+
logger.info("create deserializationSchema with replicaIdentity:{}", replicaIdentity);
5458
}
5559

5660
@Override

tis-incr/tis-flink-extends/src/main/java/com/qlangtech/plugins/incr/flink/metrics/TISPBReporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup gr
110110
super.notifyOfAddedMetric(metric, metricName, group);
111111
String name = group.getMetricIdentifier(metricName, this);
112112
if (scope.length > 1 && TaskExecutor.TASK_MANAGER_NAME.equals(scope[1])) {
113-
if (IIncreaseCounter.TABLE_CONSUME_COUNT.equals(metricName)) {
113+
if (IIncreaseCounter.COLLECTABLE_TABLE_COUNT_METRIC.contains(metricName)) {
114114
// System.out.println(metricName);
115115
metricIdentifierMapper.put(name, Pair.of(metricName, group));
116116
}
@@ -168,7 +168,7 @@ public void report() {
168168
// System.out.println(metricID + ": " + counter.getCount());
169169
metricGroup = metricIdentifierMapper.get(metricID);
170170
if (metricGroup != null) {
171-
// System.out.println(metricGroup);
171+
// System.out.println(metricGroup);
172172

173173
metrics.add(new UseableMetricForTIS(counter, /**metricName*/metricGroup.getKey(), metricGroup.getRight()));
174174
}

tis-incr/tis-flink-extends/src/main/java/com/qlangtech/tis/realtime/DTOSourceTagProcessFunction.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ protected void increaseNumRecordsMetric(DTO in) {
7676
// 当记录为更新时候会有before,after两条,所以需要将before那条记录过滤掉
7777
return;
7878
}
79+
switch (in.getEventType()) {
80+
case ADD: {
81+
this.tisInsertNumRecordsIn.inc();
82+
break;
83+
}
84+
case UPDATE_AFTER: {
85+
this.tisUpdateNumRecordsIn.inc();
86+
break;
87+
}
88+
case DELETE: {
89+
this.tisDeleteNumRecordsIn.inc();
90+
break;
91+
}
92+
}
7993
super.increaseNumRecordsMetric(in);
8094
}
8195

tis-incr/tis-flink-extends/src/main/java/com/qlangtech/tis/realtime/SourceProcessFunction.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public abstract class SourceProcessFunction<RECORD_TYPE> extends BroadcastProces
5656
* 包括所有的数据流量(增删改)
5757
*/
5858
private transient Counter tisNumRecordsIn;
59+
protected transient Counter tisInsertNumRecordsIn;
60+
protected transient Counter tisUpdateNumRecordsIn;
61+
protected transient Counter tisDeleteNumRecordsIn;
5962
private final AtomicBoolean drain = new AtomicBoolean(false);
6063
// private String taskId;
6164

@@ -84,6 +87,18 @@ public void open(Configuration parameters) throws Exception {
8487
.getMetricGroup()
8588
.counter(IIncreaseCounter.TABLE_CONSUME_COUNT);
8689

90+
this.tisInsertNumRecordsIn = getRuntimeContext()
91+
.getMetricGroup()
92+
.counter(IIncreaseCounter.TABLE_INSERT_COUNT);
93+
94+
this.tisUpdateNumRecordsIn = getRuntimeContext()
95+
.getMetricGroup()
96+
.counter(IIncreaseCounter.TABLE_UPDATE_COUNT);
97+
98+
this.tisDeleteNumRecordsIn = getRuntimeContext()
99+
.getMetricGroup()
100+
.counter(IIncreaseCounter.TABLE_DELETE_COUNT);
101+
87102
// 获取广播状态
88103
// ValueStateDescriptor<Double> descriptor = new ValueStateDescriptor<>("rate", Double.class);
89104
// broadcastState = getRuntimeContext().getBroadcastState(descriptor);

0 commit comments

Comments
 (0)