Skip to content

fix(manager): set instance to 'unknow' for dynamic monitors on modification#4101

Open
pentium100 wants to merge 11 commits intoapache:masterfrom
pentium100:fix-modify-monitor-instance-bug
Open

fix(manager): set instance to 'unknow' for dynamic monitors on modification#4101
pentium100 wants to merge 11 commits intoapache:masterfrom
pentium100:fix-modify-monitor-instance-bug

Conversation

@pentium100
Copy link
Copy Markdown
Contributor

What's changed?

fix(manager): set instance to 'unknow' for dynamic monitors on modification

In the modifyMonitor method, the instance field for dynamically discovered monitors (where isStatic is false) was not being explicitly set to "unknow". This could lead to incorrect instance values or unexpected behavior when updating service discovery monitors.

This commit aligns the behavior of modifyMonitor with addMonitor by explicitly setting monitor.setInstance("unknow") for non-static scrape types before processing the instance and port fields.

refer to #4100

Checklist

  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Add or update API

  • I have added the necessary e2e tests and all cases have passed.

…cation

In the `modifyMonitor` method, the `instance` field for dynamically discovered monitors (where `isStatic` is false) was not being explicitly set to "unknow". This could lead to incorrect instance values or unexpected behavior when updating service discovery monitors.

This commit aligns the behavior of `modifyMonitor` with `addMonitor` by explicitly setting `monitor.setInstance("unknow")` for non-static scrape types before processing the instance and port fields.
…cation

In the `modifyMonitor` method, the `instance` field for dynamically discovered monitors (where `isStatic` is false) was not being explicitly set to "unknow". This could lead to incorrect instance values or unexpected behavior when updating service discovery monitors.

This commit aligns the behavior of `modifyMonitor` with `addMonitor` by explicitly setting `monitor.setInstance("unknow")` for non-static scrape types before processing the instance and port fields.
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

Fixes an exception when modifying service-discovery (non-static scrape) monitors by ensuring monitor.instance is set to a non-null placeholder before building job metadata (aligning modifyMonitor behavior with addMonitor). This addresses issue #4100 where Map.of(...) would throw due to a null instance.

Changes:

  • In modifyMonitor, compute isStatic earlier and set monitor.instance to a placeholder value for non-static scrapes.
  • Prevent null instance from reaching Map.of(...) during job metadata construction for service discovery monitors.

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

boolean isStatic = CommonConstants.SCRAPE_STATIC.equals(monitor.getScrape())
|| !StringUtils.hasText(monitor.getScrape());
if (!isStatic) {
monitor.setInstance("unknow");
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The placeholder instance string is spelled "unknow". If this value is user-facing or persisted, consider switching to the correctly spelled "unknown" (ideally via a shared constant) and handling any backward-compatibility/migration needed, since this method now introduces an additional persisted usage of the typo.

Suggested change
monitor.setInstance("unknow");
monitor.setInstance("unknown");

Copilot uses AI. Check for mistakes.
Comment on lines 391 to 403
@@ -396,8 +402,6 @@ public void modifyMonitor(Monitor monitor, List<Param> params, String collector,
}
monitor.setInstance(instance);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

modifyMonitor appends portWithMark whenever instance is non-null, even if instance already includes a ":port" suffix. This can produce duplicated ports (e.g., host:9200:9200) for API clients/imports that send monitor.instance with port included. Align this logic with addMonitor by checking IpDomainUtil.isHasPortWithMark(instance) before concatenating the port.

Copilot uses AI. Check for mistakes.
@yuluo-yx
Copy link
Copy Markdown
Member

hi @pentium100 pls see the copilot review comment.

When the monitor type is service discovery and the instance is not empty,
the instance value should not be overwritten. This commit fixes this issue.
Additionally, it corrects the spelling of 'unknow' to 'unknown' and prevents
appending the port if the instance already contains it.
zqr10159
zqr10159 previously approved these changes Mar 30, 2026
@zqr10159 zqr10159 requested a review from Duansg March 31, 2026 08:06
Copy link
Copy Markdown
Member

@Duansg Duansg left a comment

Choose a reason for hiding this comment

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

In addition, please update the regression test cases for this change.

if (Objects.nonNull(instance)) {
? ""
: SignConstants.DOUBLE_MARK + portParam.getParamValue();
if (Objects.nonNull(instance) && !IpDomainUtil.isHasPortWithMark(instance)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a question here: if this includes port-skipping concatenation, will changes made by the user to the port not take effect?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants