-
Notifications
You must be signed in to change notification settings - Fork 74
DSMON-1102: Add configuration-level dynamic tags for JMX attribute values #581
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b91a371
Add dynamic tags support to JMX Fetch
piochelepiotr 9961226
Use tags from JMX sections, not instance tags
piochelepiotr 2c6b688
Use resources files for tests
piochelepiotr 2ed6089
address PR comments
piochelepiotr 19f1c56
Move dynamic tags to same level as include
piochelepiotr 67cc21f
remove unused functions
piochelepiotr 4ee9eb4
update when tags are resolved
piochelepiotr 55eb6a7
separate adding dynamic tags & additional tags
piochelepiotr d6e7660
address PR comments
piochelepiotr 0971987
add negative cache and improve code readability
piochelepiotr 91ffa17
test invalid dynamic tags & multiple dynamic tags
piochelepiotr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package org.datadog.jmxfetch; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import javax.management.MalformedObjectNameException; | ||
| import javax.management.ObjectName; | ||
|
|
||
| @Slf4j | ||
| public class DynamicTag { | ||
| private final String tagName; | ||
| private final String beanName; | ||
| private final String attributeName; | ||
|
|
||
| /** Parse dynamic tag from configuration map (list entry format). */ | ||
| public static DynamicTag parse(Object tagConfig) { | ||
| if (tagConfig == null) { | ||
| return null; | ||
| } | ||
|
|
||
| if (!(tagConfig instanceof Map)) { | ||
| log.warn("Invalid dynamic tag config: expected map with 'tag_name', 'bean_name' and " | ||
| + "'attribute' keys"); | ||
| return null; | ||
| } | ||
|
|
||
| Map<String, Object> config = (Map<String, Object>) tagConfig; | ||
| Object tagNameObj = config.get("tag_name"); | ||
| Object beanObj = config.get("bean_name"); | ||
| Object attrObj = config.get("attribute"); | ||
|
|
||
| if (tagNameObj == null || beanObj == null || attrObj == null) { | ||
| String missing = "Invalid dynamic tag config: missing" | ||
| + (tagNameObj == null ? " tag_name" : "") | ||
| + (beanObj == null ? " bean_name" : "") | ||
| + (attrObj == null ? " attribute" : ""); | ||
| log.warn(missing); | ||
| return null; | ||
| } | ||
|
|
||
| String tagName = tagNameObj.toString(); | ||
| String beanName = beanObj.toString(); | ||
| String attributeName = attrObj.toString(); | ||
|
|
||
| return new DynamicTag(tagName, beanName, attributeName); | ||
| } | ||
|
|
||
| private DynamicTag(String tagName, String beanName, String attributeName) { | ||
| this.tagName = tagName; | ||
| this.beanName = beanName; | ||
| this.attributeName = attributeName; | ||
| } | ||
|
|
||
| public String getTagName() { | ||
| return tagName; | ||
| } | ||
|
|
||
| public String getBeanName() { | ||
| return beanName; | ||
| } | ||
|
|
||
| public String getAttributeName() { | ||
| return attributeName; | ||
| } | ||
|
|
||
| /** Gets a unique key for the bean and attribute combination. */ | ||
| public String getBeanAttributeKey() { | ||
| return beanName + "#" + attributeName; | ||
| } | ||
|
|
||
| /** Resolve the dynamic tag by fetching the attribute value from JMX. */ | ||
| public Map.Entry<String, String> resolve(Connection connection) { | ||
| try { | ||
| ObjectName objectName = new ObjectName(beanName); | ||
| Object value = connection.getAttribute(objectName, attributeName); | ||
|
|
||
| if (value == null) { | ||
| log.warn("Dynamic tag '{}' resolved to null for bean '{}' attribute '{}'", | ||
| tagName, beanName, attributeName); | ||
| return null; | ||
| } | ||
|
|
||
| String stringValue = value.toString(); | ||
| log.info("Resolved dynamic tag '{}' to value '{}' from bean '{}' attribute '{}'", | ||
| tagName, stringValue, beanName, attributeName); | ||
|
|
||
| return new HashMap.SimpleEntry<>(tagName, stringValue); | ||
|
|
||
| } catch (MalformedObjectNameException e) { | ||
| log.error("Invalid bean name '{}' for dynamic tag '{}': {}", | ||
| beanName, tagName, e.getMessage()); | ||
| return null; | ||
| } catch (Exception e) { | ||
| log.warn("Failed to resolve dynamic tag '{}' from bean '{}' attribute '{}': {}", | ||
| tagName, beanName, attributeName, e.getMessage()); | ||
| log.debug("Dynamic tag resolution error details", e); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("DynamicTag{name='%s', bean='%s', attribute='%s'}", | ||
| tagName, beanName, attributeName); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package org.datadog.jmxfetch; | ||
|
|
||
| public class DynamicTagTestApp implements DynamicTagTestAppMBean { | ||
| private final String clusterId; | ||
| private final String version; | ||
| private final int port; | ||
| private double metric; | ||
|
|
||
| public DynamicTagTestApp() { | ||
| this("local-kafka-cluster", "2.8.0", 9092); | ||
| } | ||
|
|
||
| public DynamicTagTestApp(String clusterId, String version, int port) { | ||
| this.clusterId = clusterId; | ||
| this.version = version; | ||
| this.port = port; | ||
| this.metric = 100.0; | ||
| } | ||
|
|
||
| @Override | ||
| public String getClusterId() { | ||
| return clusterId; | ||
| } | ||
|
|
||
| @Override | ||
| public String getVersion() { | ||
| return version; | ||
| } | ||
|
|
||
| @Override | ||
| public int getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| @Override | ||
| public Double getMetric() { | ||
| return metric; | ||
| } | ||
|
|
||
| public void setMetric(double metric) { | ||
| this.metric = metric; | ||
| } | ||
| } | ||
|
|
||
|
|
10 changes: 10 additions & 0 deletions
10
src/test/java/org/datadog/jmxfetch/DynamicTagTestAppMBean.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.datadog.jmxfetch; | ||
|
|
||
| public interface DynamicTagTestAppMBean { | ||
| String getClusterId(); | ||
| String getVersion(); | ||
| int getPort(); | ||
| Double getMetric(); | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.