Skip to content

feat: add common protocol entity check#4097

Merged
tomsun28 merged 3 commits intomasterfrom
0328-yuluo/add
Apr 1, 2026
Merged

feat: add common protocol entity check#4097
tomsun28 merged 3 commits intomasterfrom
0328-yuluo/add

Conversation

@yuluo-yx
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements concrete isInvalid() validation logic for multiple protocol entities in hertzbeat-common-core, and adds JUnit tests to verify the new validation behavior.

Changes:

  • Implemented isInvalid() checks for several protocol configs (SNMP/SMTP/IMAP/FTP/NTP/NGQL/Script/Eureka SD/Zookeeper SD).
  • Added unit tests covering valid/invalid protocol parameter combinations for each updated protocol type.
  • Standardized parts of validation using shared utilities (e.g., IpDomainUtil, StringUtils).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ZookeeperSdProtocol.java Implements Zookeeper SD protocol validation (blank/whitespace/path prefix format).
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SnmpProtocol.java Adds SNMP validation for host/port/version, v1/v2c/v3 requirements, operation + OIDs checks.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SmtpProtocol.java Adds SMTP validation for host/port/email and optional numeric timeout.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ScriptProtocol.java Adds script validation for charset/parseType/tool and presence of command/path.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NtpProtocol.java Adds NTP validation for host, optional port, optional numeric timeout.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NgqlProtocol.java Adds NGQL validation for connection fields, parseType allowlist, commands list.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ImapProtocol.java Adds IMAP validation for host/port/timeout/email/authorize/folder + ssl value.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/FtpProtocol.java Adds FTP/SFTP validation for host/port/direction/timeout + ssl value + creds when ssl=true.
hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/EurekaSdProtocol.java Adds Eureka SD URL validation using URI parsing + scheme restriction.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/ZookeeperSdProtocolTest.java Adds tests for Zookeeper SD validity rules.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/SnmpProtocolTest.java Adds tests for SNMP version/credential/operation/OID validation.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/SmtpProtocolTest.java Adds tests for SMTP host/port/email/timeout validation.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/ScriptProtocolTest.java Adds tests for script charset/parseType/tool and command/path requirements.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/NtpProtocolTest.java Adds tests for NTP host/port/timeout validation.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/NgqlProtocolTest.java Adds tests for NGQL parseType/commands/timeout validation.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/ImapProtocolTest.java Adds tests for IMAP ssl/folder/timeout/host validation.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/FtpProtocolTest.java Adds tests for FTP/SFTP ssl, direction, timeout, and credential requirements.
hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/EurekaSdProtocolTest.java Adds tests for Eureka SD URL validation (scheme/blank/malformed).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (!validateIpDomain(host) || !validPort(port) || StringUtils.isBlank(direction) || StringUtils.isBlank(timeout)) {
return true;
}
if (!CommonUtil.isNumeric(timeout)) {
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

CommonUtil.isNumeric(timeout) accepts decimal/signed values (e.g., "3000.5"), but the FTP collector later uses Integer.parseInt(timeout) (e.g., in FtpCollectImpl) which would throw at runtime. Consider validating timeout as an integer (e.g., parse with Integer.parseInt in a try/catch, or use a stricter integer-only check) to keep isInvalid() consistent with downstream parsing.

Suggested change
if (!CommonUtil.isNumeric(timeout)) {
try {
Integer.parseInt(timeout);
} catch (NumberFormatException ex) {

Copilot uses AI. Check for mistakes.
if (StringUtils.isAnyBlank(timeout, email, authorize, folderName)) {
return true;
}
if (!CommonUtil.isNumeric(timeout)) {
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

CommonUtil.isNumeric(timeout) treats decimals as numeric, but ImapCollectImpl later does Integer.parseInt(imapProtocol.getTimeout()), which will fail for values like "6000.5". Tighten the timeout validation here to ensure it matches the collector’s integer parsing expectations (integer-only parse/check).

Suggested change
if (!CommonUtil.isNumeric(timeout)) {
if (!StringUtils.isNumeric(timeout)) {

Copilot uses AI. Check for mistakes.
@tomsun28 tomsun28 merged commit c8021dc into master Apr 1, 2026
3 checks passed
@yuluo-yx yuluo-yx deleted the 0328-yuluo/add branch April 1, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants