Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cdc-connector][mysql]Mysql add numRecordsOutBySnapshot and numRecordsOutByIncremental metrics #3456

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ChengJie1053
Copy link
Member

@ChengJie1053 ChengJie1053 commented Jul 6, 2024

numRecordsOutBySnapshot metrics collects snapshot statistics

numRecordsOutByIncremental metrics collects incremental statistics

numRecordsOutByIncremental has three metrics, respectively is numRecordsOutByIncrementalInsert, numRecordsOutByIncrementalUpdate, numRecordsOutByIncrementalDelete

image

2024.7.12 change metrics name,change numRecordsOutByIncrementalInsert to numRecordsOutByDataChangeEventInsert
image

Comment on lines 40 to 47
public static final String IO_NUM_RECORDS_OUT_INCREMENTAL_INSERT =
".numRecordsOutByIncrementalInsert";

public static final String IO_NUM_RECORDS_OUT_INCREMENTAL_DELETE =
".numRecordsOutByIncrementalDelete";

public static final String IO_NUM_RECORDS_OUT_INCREMENTAL_UPDATE =
".numRecordsOutByIncrementalUpdate";
Copy link
Contributor

@SML0127 SML0127 Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for contirbution @ChengJie1053

Nit: How about changing INCREMENTAL to BINLOG or CHANGE_EVENT? INCREMENTAL can be understood as a Incremental Snapshot step.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your suggestion is great, and I will CHANGE it to CHANGE EVENT

Comment on lines 131 to 149
if (RecordUtils.isDataChangeRecord(element)) {
Struct value = (Struct) element.value();
if (value != null) {
Envelope.Operation operation =
Envelope.Operation.forCode(
value.getString(Envelope.FieldName.OPERATION));
switch (operation) {
case CREATE:
sourceReaderMetrics.numRecordsOutInsertIncrease(tableId);
break;
case UPDATE:
sourceReaderMetrics.numRecordsOutUpdateIncrease(tableId);
break;
case DELETE:
sourceReaderMetrics.numRecordsOutDeleteIncrease(tableId);
break;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We checked whether element is data change record or not in line 101.
How about removing this condition?

Suggested change
if (RecordUtils.isDataChangeRecord(element)) {
Struct value = (Struct) element.value();
if (value != null) {
Envelope.Operation operation =
Envelope.Operation.forCode(
value.getString(Envelope.FieldName.OPERATION));
switch (operation) {
case CREATE:
sourceReaderMetrics.numRecordsOutInsertIncrease(tableId);
break;
case UPDATE:
sourceReaderMetrics.numRecordsOutUpdateIncrease(tableId);
break;
case DELETE:
sourceReaderMetrics.numRecordsOutDeleteIncrease(tableId);
break;
}
}
}
Struct value = (Struct) element.value();
if (value != null) {
Envelope.Operation operation =
Envelope.Operation.forCode(
value.getString(Envelope.FieldName.OPERATION));
switch (operation) {
case CREATE:
sourceReaderMetrics.numRecordsOutInsertIncrease(tableId);
break;
case UPDATE:
sourceReaderMetrics.numRecordsOutUpdateIncrease(tableId);
break;
case DELETE:
sourceReaderMetrics.numRecordsOutDeleteIncrease(tableId);
break;
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for helping me review the code.
I will delete the isDataChangeRecord judgment

Copy link
Contributor

@SML0127 SML0127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@SML0127 SML0127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

Comment on lines +72 to +114
public void numRecordsOutSnapshotIncrease(TableId tableId) {
Counter counter =
snapshotNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier() + IO_NUM_RECORDS_OUT_SNAPSHOT));
counter.inc();
}

public void numRecordsOutInsertIncrease(TableId tableId) {
Counter counter =
insertNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier()
+ IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_INSERT));
counter.inc();
}

public void numRecordsOutUpdateIncrease(TableId tableId) {
Counter counter =
updateNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier()
+ IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_UPDATE));
counter.inc();
}

public void numRecordsOutDeleteIncrease(TableId tableId) {
Counter counter =
deleteNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier()
+ IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_DELETE));
counter.inc();
}

Copy link
Contributor

@SML0127 SML0127 Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied this metrics to my code, and left some comments.

  • Metric names should be general.
  • In your case, It generate uniqe metrics for each tables. But in monitorig tool such as grafana, it distingush tables by property such as job name in metric, not by metric name
    So I suggest to remove tableId.identifier() in metric name.
Suggested change
public void numRecordsOutSnapshotIncrease(TableId tableId) {
Counter counter =
snapshotNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier() + IO_NUM_RECORDS_OUT_SNAPSHOT));
counter.inc();
}
public void numRecordsOutInsertIncrease(TableId tableId) {
Counter counter =
insertNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier()
+ IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_INSERT));
counter.inc();
}
public void numRecordsOutUpdateIncrease(TableId tableId) {
Counter counter =
updateNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier()
+ IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_UPDATE));
counter.inc();
}
public void numRecordsOutDeleteIncrease(TableId tableId) {
Counter counter =
deleteNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(
tableId.identifier()
+ IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_DELETE));
counter.inc();
}
public void numRecordsOutSnapshotIncrease(TableId tableId) {
Counter counter =
snapshotNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(IO_NUM_RECORDS_OUT_SNAPSHOT));
counter.inc();
}
public void numRecordsOutInsertIncrease(TableId tableId) {
Counter counter =
insertNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_INSERT));
counter.inc();
}
public void numRecordsOutUpdateIncrease(TableId tableId) {
Counter counter =
updateNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_UPDATE));
counter.inc();
}
public void numRecordsOutDeleteIncrease(TableId tableId) {
Counter counter =
deleteNumRecordsOutMap.computeIfAbsent(
tableId,
k ->
metricGroup.counter(IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_DELETE));
counter.inc();
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for reviewing the code for me, but the original purpose of this metric is to see each table at a granular level, if you need to see the total, I will add other metrics

Comment on lines +38 to +47
public static final String IO_NUM_RECORDS_OUT_SNAPSHOT = ".numRecordsOutBySnapshot";

public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_INSERT =
".numRecordsOutByDataChangeEventInsert";

public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_DELETE =
".numRecordsOutByDataChangeEventDelete";

public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_UPDATE =
".numRecordsOutByDataChangeEventUpdate";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to remove dot(.) from metric name.

Suggested change
public static final String IO_NUM_RECORDS_OUT_SNAPSHOT = ".numRecordsOutBySnapshot";
public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_INSERT =
".numRecordsOutByDataChangeEventInsert";
public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_DELETE =
".numRecordsOutByDataChangeEventDelete";
public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_UPDATE =
".numRecordsOutByDataChangeEventUpdate";
public static final String IO_NUM_RECORDS_OUT_SNAPSHOT = "numRecordsOutBySnapshot";
public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_INSERT =
"numRecordsOutByDataChangeEventInsert";
public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_DELETE =
"numRecordsOutByDataChangeEventDelete";
public static final String IO_NUM_RECORDS_OUT_DATA_CHANGE_EVENT_UPDATE =
"numRecordsOutByDataChangeEventUpdate";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for helping me review the code, I will remove (.)

@yuxiqian
Copy link
Contributor

yuxiqian commented Jul 16, 2024

Seems we can't come up with a "best" metric design for everyone: Some may want a task-level unified record counter, while some may want fine-grained counters for each table. Or one may want to disable it entirely to avoid any extra cost.

I wonder if we should add an option to control metric behavior? cc @ruanhang1993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants