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

[Improve][Sort] Refactor MetricOption code structure. #10152

Closed
2 tasks done
XiaoYou201 opened this issue May 8, 2024 · 0 comments · Fixed by #10156
Closed
2 tasks done

[Improve][Sort] Refactor MetricOption code structure. #10152

XiaoYou201 opened this issue May 8, 2024 · 0 comments · Fixed by #10156
Assignees
Milestone

Comments

@XiaoYou201
Copy link
Contributor

Description

The MetricOption constructor is not concise. checkArgument method in build() will be better.

private MetricOption(
String inlongLabels,
@Nullable String inlongAudit,
RegisteredMetric registeredMetric,
long initRecords,
long initBytes,
Long initDirtyRecords,
Long initDirtyBytes,
Long readPhase,
String inlongAuditKeys) {
Preconditions.checkArgument(!StringUtils.isNullOrWhitespaceOnly(inlongLabels),
"Inlong labels must be set for register metric.");
this.initRecords = initRecords;
this.initBytes = initBytes;
this.initDirtyRecords = initDirtyRecords;
this.initDirtyBytes = initDirtyBytes;
this.readPhase = readPhase;
this.labels = new LinkedHashMap<>();
String[] inLongLabelArray = inlongLabels.split(DELIMITER);
Preconditions.checkArgument(Stream.of(inLongLabelArray).allMatch(label -> label.contains("=")),
"InLong metric label format must be xxx=xxx");
Stream.of(inLongLabelArray).forEach(label -> {
String key = label.substring(0, label.indexOf('='));
String value = label.substring(label.indexOf('=') + 1);
labels.put(key, value);
});
this.ipPorts = inlongAudit;
if (ipPorts != null) {
Preconditions.checkArgument(labels.containsKey(GROUP_ID) && labels.containsKey(STREAM_ID),
"groupId and streamId must be set when enable inlong audit collect.");
if (inlongAuditKeys == null) {
LOG.warn("should set inlongAuditKeys when enable inlong audit collect, "
+ "fallback to use id {} as audit key", AUDIT_SORT_INPUT);
inlongAuditKeys = AUDIT_SORT_INPUT;
}
this.inlongAuditKeys = AuditUtils.extractAuditKeys(inlongAuditKeys);
this.ipPortList = AuditUtils.extractAuditIpPorts(ipPorts);
}
if (registeredMetric != null) {
this.registeredMetric = registeredMetric;
}
}

public MetricOption build() {
if (inlongLabels == null && inlongAudit == null) {
return null;
}
return new MetricOption(inlongLabels, inlongAudit, registeredMetric, initRecords, initBytes,
initDirtyRecords, initDirtyBytes, initReadPhase, inlongAuditKeys);
}

InLong Component

InLong Sort

Are you willing to submit PR?

  • Yes, I am willing to submit a PR!

Code of Conduct

@XiaoYou201 XiaoYou201 changed the title [Improve][Sort] Refactor MetricOption code structure. [Improve][Sort] Refact MetricOption code structure. May 8, 2024
@XiaoYou201 XiaoYou201 changed the title [Improve][Sort] Refact MetricOption code structure. [Improve][Sort] Refactor MetricOption code structure. May 8, 2024
@dockerzhang dockerzhang added this to the 1.13.0 milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants