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

Add warning for duplicate instance name #484

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -828,6 +830,7 @@ public void init(final boolean forceNewConnection) {
this.brokenInstanceMap.clear();

final List<Instance> newInstances = new ArrayList<>();
final Set<String> instanceNamesSeen = new HashSet<>();

log.info("Dealing with YAML config instances...");
final Iterator<Entry<String, YamlParser>> it = this.configs.entrySet().iterator();
Expand Down Expand Up @@ -867,7 +870,16 @@ public void init(final boolean forceNewConnection) {
isDirectInstance(configInstance));
continue;
}

final String instanceName = (String) configInstance.get("name");
if (instanceName != null) {
if (instanceNamesSeen.contains(instanceName)) {
log.warn("Found multiple instances with name: '{}'. "
+ "Instance names should be unique, "
+ "update the 'name' field on your instances to be unique.",
instanceName);
}
instanceNamesSeen.add(instanceName);
}
// Create a new Instance object
log.info("Instantiating instance for: {}", name);
final Instance instance =
Expand All @@ -893,6 +905,16 @@ public void init(final boolean forceNewConnection) {
final String checkName = (String) checkConfig.get("check_name");
for (Map<String, Object> configInstance : configInstances) {
log.info("Instantiating instance for: " + checkName);
final String instanceName = (String) configInstance.get("name");
scottopell marked this conversation as resolved.
Show resolved Hide resolved
if (instanceName != null) {
if (instanceNamesSeen.contains(instanceName)) {
log.warn("Found multiple instances with name: '{}'. "
+ "Instance names should be unique, "
+ "update the 'name' field on your instances to be unique.",
instanceName);
}
instanceNamesSeen.add(instanceName);
}
final Instance instance =
instantiate(configInstance, initConfig, checkName, this.appConfig);
newInstances.add(instance);
Expand Down
Loading