-
Notifications
You must be signed in to change notification settings - Fork 520
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
[INLONG-1796]DataProxy support monitor indicator with JMX. #1796 #1797
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1797 +/- ##
============================================
- Coverage 12.18% 11.94% -0.25%
Complexity 1049 1049
============================================
Files 396 399 +3
Lines 32833 33466 +633
Branches 5149 5276 +127
============================================
- Hits 4002 3997 -5
- Misses 28065 28701 +636
- Partials 766 768 +2
Continue to review full report at Codecov.
|
@luchunliang please add some UTs to verify this feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
this.reload(); | ||
this.setReloadTimer(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not print stacktrace direct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, print exception with log4j.
*/ | ||
private void setReloadTimer() { | ||
reloadTimer = new Timer(true); | ||
TimerTask task = new TimerTask() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimerTask is not recommend to use . use ScheduledExecutorService instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScheduledExecutorService is used to ThreadPool case, it is better for a lot of same task.
The reload task of CacheClusterConfigHolder is a single schedule task, single thread of Timer is better.
this.reload(); | ||
this.setReloadTimer(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.printstacktrace is not suitable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, remove this line.
*/ | ||
protected Map<String, String> loadProperties(String fileName) { | ||
Map<String, String> result = new ConcurrentHashMap<>(); | ||
InputStream inStream = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend to use try-resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, use try-with-resource mode.
*/ | ||
@Override | ||
public List<CacheClusterConfig> load() { | ||
String clusterNames = context.getString("cacheClusterConfig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract to constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, extract to constant.
@Override | ||
public List<IdTopicConfig> load() { | ||
Map<String, String> idTopicMap = context.getSubProperties("idTopicConfig."); | ||
List<IdTopicConfig> configList = new ArrayList<>(idTopicMap.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPE check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.getSubProperties() should not return null.
public ImmutableMap<String, String> getSubProperties(String prefix) {
Preconditions.checkArgument(prefix.endsWith("."),
"The given prefix does not end with a period (" + prefix + ")");
Map<String, String> result = Maps.newHashMap();
synchronized (parameters) {
for (Entry<String, String> entry : parameters.entrySet()) {
String key = entry.getKey();
if (key.startsWith(prefix)) {
String name = key.substring(prefix.length());
result.put(name, entry.getValue());
}
}
}
return ImmutableMap.copyOf(result);
}
|
||
public static final Logger LOG = LoggerFactory.getLogger(MetricObserver.class); | ||
private static final AtomicBoolean isInited = new AtomicBoolean(false); | ||
private static ScheduledExecutorService statExecutor = Executors.newScheduledThreadPool(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should init with thead name for online trouble shooting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statExecutor is a thread pool. Runtime exception will print stack trace to log file.
It is enough to online trouble shooting based on log file.
try { | ||
List<MetricItemValue> itemValues = this.getItemValues(); | ||
LOG.info("snapshot metric:{},size:{}", domain, itemValues.size()); | ||
// LOG.info("snapshot metric:{},size:{},contents:{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove un-used code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, remove un-used code.
} finally { | ||
tx.close(); | ||
} | ||
// Channel channel = getChannel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove un-used code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, remove un-used code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Fixes #1796
Motivation
[Feature]DataProxy provide monitor indicator based on JMX, user can implement the code that read the metrics and report to user-defined monitor system.
DataProxy provide monitor indicator based on JMX, user can implement the code that read the metrics and report to user-defined monitor system.
Source-module and Sink-module can add monitor metric class that is the subclass of org.apache.inlong.commons.config.metrics.MetricItemSet, and register it to MBeanServer.
User-defined plugin can get module metric with JMX, and report metric data to different monitor system.
User can describe the configuration in the file "common.properties ".
For example:
metricDomains=DataProxy metricDomains.DataProxy.domainListeners=com.tencent.pcg.atta.dataproxy.metrics.m007.M007MetricListener org.apache.inlong.dataproxy.metrics.prometheus.PrometheusMetricListener metricDomains.DataProxy.snapshotInterval=60000
The JMX domain name of DataProxy is "DataProxy".
It is defined by the parameter "metricDomains".
The listeners of JMX domain is defined by the parameter "metricDomains.$domainName.domainListeners".
The class names of the listeners is separated by the space char.
The listener class need to implement the interface "org.apache.inlong.dataproxy.metrics.MetricListener".
The snapshot interval of the listeners is defined by the parameter "metricDomains.$domainName.snapshotInterval", the parameter unit is "millisecond".
The method proto of org.apache.inlong.dataproxy.metrics.MetricListener is:
public void snapshot(String domain, List itemValues);
The field of MetricItemValue.dimensions has these key(The fields of DataProxyMetricItem defined by the Annotation "@Dimension"):
The field of MetricItemValue.metrics has these key(The fields of DataProxyMetricItem defined by the Annotation "@CountMetric"):
Modifications
Describe the modifications you've done.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Documentation