Skip to content

Commit

Permalink
Cleaned up Javadoc warnings. Change comments for empty constructors (#…
Browse files Browse the repository at this point in the history
…1056)

Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard authored Nov 26, 2024
1 parent a7472d2 commit 7fc16de
Show file tree
Hide file tree
Showing 29 changed files with 248 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
*/
public class BuildInfoMetrics {

/** Constructor */
public BuildInfoMetrics() {
// INTENTIONALLY BLANK
}

/**
* Method to register BuildInfoMetrics
*
Expand Down
42 changes: 42 additions & 0 deletions collector/src/main/java/io/prometheus/jmx/JmxCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@
import javax.management.ObjectName;
import org.yaml.snakeyaml.Yaml;

/** Class to implement JmxCollector */
@SuppressWarnings("unchecked")
public class JmxCollector implements MultiCollector {

private static final Logger LOGGER = LoggerFactory.getLogger(JmxCollector.class);

/** Enum to implement Mode */
public enum Mode {
/** Agent mode */
AGENT,
/** Standalone mode */
STANDALONE
}

Expand Down Expand Up @@ -103,10 +107,25 @@ private static class Config {

private final JmxMBeanPropertyCache jmxMBeanPropertyCache = new JmxMBeanPropertyCache();

/**
* Constructor
*
* @param in in
* @throws IOException IOException
* @throws MalformedObjectNameException MalformedObjectNameException
*/
public JmxCollector(File in) throws IOException, MalformedObjectNameException {
this(in, null);
}

/**
* Constructor
*
* @param in in
* @param mode mode
* @throws IOException IOException
* @throws MalformedObjectNameException MalformedObjectNameException
*/
public JmxCollector(File in, Mode mode) throws IOException, MalformedObjectNameException {
configFile = in;
this.mode = mode;
Expand All @@ -115,20 +134,43 @@ public JmxCollector(File in, Mode mode) throws IOException, MalformedObjectNameE
exitOnConfigError();
}

/**
* Constructor
*
* @param yamlConfig yamlConfig
* @throws MalformedObjectNameException MalformedObjectNameException
*/
public JmxCollector(String yamlConfig) throws MalformedObjectNameException {
config = loadConfig(new Yaml().load(yamlConfig));
mode = null;
}

/**
* Constructor
*
* @param inputStream inputStream
* @throws MalformedObjectNameException MalformedObjectNameException
*/
public JmxCollector(InputStream inputStream) throws MalformedObjectNameException {
config = loadConfig(new Yaml().load(inputStream));
mode = null;
}

/**
* Method to register the JmxCollector
*
* @return the JmxCollector
*/
public JmxCollector register() {
return register(PrometheusRegistry.defaultRegistry);
}

/**
* Method to register the JmxCollector
*
* @param prometheusRegistry prometheusRegistry
* @return the JmxCollector
*/
public JmxCollector register(PrometheusRegistry prometheusRegistry) {
this.prometheusRegistry = prometheusRegistry;

Expand Down
27 changes: 27 additions & 0 deletions collector/src/main/java/io/prometheus/jmx/JmxScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,25 @@
import javax.naming.Context;
import javax.rmi.ssl.SslRMIClientSocketFactory;

/** Class to implement JmxScraper */
class JmxScraper {

private static final Logger LOGGER = LoggerFactory.getLogger(JmxScraper.class);

/** Interface to implement MBeanReceiver */
public interface MBeanReceiver {

/**
* Method to create a bean
*
* @param domain domain
* @param beanProperties beanProperties
* @param attrKeys attrKeys
* @param attrName attrName
* @param attrType attrType
* @param attrDescription attrDescription
* @param value value
*/
void recordBean(
String domain,
LinkedHashMap<String, String> beanProperties,
Expand All @@ -74,6 +88,19 @@ void recordBean(
private final ObjectNameAttributeFilter objectNameAttributeFilter;
private final JmxMBeanPropertyCache jmxMBeanPropertyCache;

/**
* Constructor
*
* @param jmxUrl jmxUrl
* @param username username
* @param password password
* @param ssl ssl
* @param includeObjectNames includeObjectNames
* @param excludeObjectNames excludeObjectNames
* @param objectNameAttributeFilter objectNameAttributeFilter
* @param receiver receiver
* @param jmxMBeanPropertyCache jmxMBeanPropertyCache
*/
public JmxScraper(
String jmxUrl,
String username,
Expand Down
28 changes: 28 additions & 0 deletions collector/src/main/java/io/prometheus/jmx/MatchedRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ private MatchedRule() {
this.valueFactor = 1.0;
}

/**
* Constructor
*
* @param name name
* @param matchName matchName
* @param type type
* @param help help
* @param labelNames labelNames
* @param labelValues labelValues
* @param value value
* @param valueFactor valueFactor
*/
public MatchedRule(
final String name,
final String matchName,
Expand All @@ -68,6 +80,12 @@ public MatchedRule(
this.valueFactor = valueFactor;
}

/**
* Method to create a MatchedRule with a value
*
* @param value value
* @return a MatchedRule with a value
*/
public MatchedRule withValue(double value) {
return new MatchedRule(
PrometheusNaming.sanitizeMetricName(this.name),
Expand All @@ -91,10 +109,20 @@ public static MatchedRule unmatched() {
return _unmatched;
}

/**
* Method to return if the rule is unmatched
*
* @return true if unmatched, else false
*/
public boolean isUnmatched() {
return this == _unmatched;
}

/**
* Method to return if the rule is matched
*
* @return true if matched, else false
*/
public boolean isMatched() {
return !isUnmatched();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@
import java.util.Set;
import java.util.logging.Level;

/** Class to implement MatchedRuleToMetricSnapshotsConverter */
public class MatchedRuleToMetricSnapshotsConverter {

private static final Logger LOGGER =
LoggerFactory.getLogger(MatchedRuleToMetricSnapshotsConverter.class);

private static final String OBJECTNAME = "_objectname";

/** Constructor */
public MatchedRuleToMetricSnapshotsConverter() {
// INTENTIONALLY BLANK
}

/**
* Method to convert a List of MatchedRules to MetricSnapshots
*
* @param matchedRules matchedRules
* @return a MetricSnapshots
*/
public static MetricSnapshots convert(List<MatchedRule> matchedRules) {
Map<String, List<MatchedRule>> rulesByPrometheusMetricName = new HashMap<>();

Expand Down
52 changes: 51 additions & 1 deletion collector/src/main/java/io/prometheus/jmx/MatchedRulesCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,51 @@
* pattern) to avoid matching against the same pattern in later bean collections.
*/
public class MatchedRulesCache {

private final Map<JmxCollector.Rule, Map<String, MatchedRule>> cachedRules;

/**
* Constructor
*
* @param rules rules
*/
public MatchedRulesCache(Collection<JmxCollector.Rule> rules) {
this.cachedRules = new HashMap<>(rules.size());
for (JmxCollector.Rule rule : rules) {
this.cachedRules.put(rule, new ConcurrentHashMap<>());
}
}

/**
* Method to put a matched rule in the cache
*
* @param rule rule
* @param cacheKey cacheKey
* @param matchedRule matchedRule
*/
public void put(
final JmxCollector.Rule rule, final String cacheKey, final MatchedRule matchedRule) {
Map<String, MatchedRule> cachedRulesForRule = cachedRules.get(rule);
cachedRulesForRule.put(cacheKey, matchedRule);
}

/**
* Method to get a MatchedRule from the cache
*
* @param rule rule
* @param cacheKey cacheKey
* @return the MatchedRule
*/
public MatchedRule get(final JmxCollector.Rule rule, final String cacheKey) {
return cachedRules.get(rule).get(cacheKey);
}

// Remove stale rules (in the cache but not collected in the last run of the collector)
/**
* Method to remove stale rules (in the cache but not collected in the last run of the
* collector)
*
* @param stalenessTracker stalenessTracker
*/
public void evictStaleEntries(final StalenessTracker stalenessTracker) {
for (Map.Entry<JmxCollector.Rule, Map<String, MatchedRule>> entry :
cachedRules.entrySet()) {
Expand All @@ -63,21 +88,46 @@ public void evictStaleEntries(final StalenessTracker stalenessTracker) {
}
}

/** Class to implement StalenessTracker */
public static class StalenessTracker {

private final Map<JmxCollector.Rule, Set<String>> lastCachedEntries = new HashMap<>();

/** Constructor */
public StalenessTracker() {
// INTENTIONALLY BLANK
}

/**
* Method to add a Rule
*
* @param rule rule
* @param cacheKey cacheKey
*/
public void add(final JmxCollector.Rule rule, final String cacheKey) {
Set<String> lastCachedEntriesForRule =
lastCachedEntries.computeIfAbsent(rule, k -> new HashSet<>());
lastCachedEntriesForRule.add(cacheKey);
}

/**
* Method to return if a Rule is stale
*
* @param rule rule
* @param cacheKey cacheKey
* @return true if the stale, else false
*/
public boolean contains(final JmxCollector.Rule rule, final String cacheKey) {
Set<String> lastCachedEntriesForRule = lastCachedEntries.get(rule);
return (lastCachedEntriesForRule != null)
&& lastCachedEntriesForRule.contains(cacheKey);
}

/**
* Method to get the count of stale rules
*
* @return the count of stale rules
*/
public long cachedCount() {
long count = 0;
for (Set<String> cacheKeys : lastCachedEntries.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public class ObjectNameAttributeFilter {

private static final Logger LOGGER = LoggerFactory.getLogger(ObjectNameAttributeFilter.class);

/** Configuration constant to define a mapping of ObjectNames to attribute names */
/** Configuration constant to define a mapping of ObjectNames to attribute names to exclude */
public static final String EXCLUDE_OBJECT_NAME_ATTRIBUTES = "excludeObjectNameAttributes";

/** Configuration constant to define a mapping of ObjectNames to attribute names to include */
public static final String INCLUDE_OBJECT_NAME_ATTRIBUTES = "includeObjectNameAttributes";

/** Configuration constant to enable auto ObjectName attributes filtering */
Expand Down Expand Up @@ -172,6 +173,13 @@ private boolean exclude(
return result;
}

/**
* Method to return whether an attribute should be included
*
* @param objectName objectName
* @param attributeName attributeName
* @return true if the attribute should be included, else false
*/
public boolean include(ObjectName objectName, String attributeName) {
boolean result = false;

Expand All @@ -183,6 +191,11 @@ public boolean include(ObjectName objectName, String attributeName) {
return result;
}

/**
* Method to return whether any attributes are included
*
* @return true if empty, else false
*/
public boolean includeObjectNameAttributesIsEmpty() {
return includeObjectNameAttributesMap.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LoggerFactory {

/** Constructor */
private LoggerFactory() {
// DO NOTHING
// INTENTIONALLY BLANK
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface TotalValueMBean {
class TotalValue implements TotalValueMBean {

public TotalValue() {
// DO NOTHING
// INTENTIONALLY BLANK
}

@Override
Expand Down
Loading

0 comments on commit 7fc16de

Please sign in to comment.