kumaab commented on code in PR #447:
URL: https://github.com/apache/ranger/pull/447#discussion_r1881001760
##########
tagsync/src/main/java/org/apache/ranger/tagsync/process/TagSyncMetricsProducer.java:
##########
@@ -18,80 +18,74 @@
* specific language governing permissions and limitations
* under the License.
*/
-import java.io.File;
import org.apache.ranger.plugin.util.RangerMetricsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TagSyncMetricsProducer implements Runnable {
-
- private static final Logger LOG =
LoggerFactory.getLogger(TagSyncMetricsProducer.class);
- private boolean shutdownFlag = false;
-
- public static void main(String[] args) {
- TagSyncMetricsProducer tagSyncMetrics = new
TagSyncMetricsProducer();
- tagSyncMetrics.run();
- // try { tagSyncMetrics.writeJVMMetrics(); } catch (Throwable
e) { }
- }
+import java.io.File;
- @Override
- public void run() {
- try {
- TagSyncConfig config = TagSyncConfig.getInstance();
- long sleepTimeBetweenCycleInMillis =
config.getTagSyncMetricsFrequency();
- String logFileNameWithPath =
config.getTagSyncMetricsFileName();
- LOG.info("Tagsync metrics frequency : " +
sleepTimeBetweenCycleInMillis +" and metrics file : "+logFileNameWithPath );
- if (null != logFileNameWithPath) {
- while (!shutdownFlag) {
- try {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Sleeping
Tagsync metrics for [" + sleepTimeBetweenCycleInMillis
- + "]
milliSeconds");
- }
-
Thread.sleep(sleepTimeBetweenCycleInMillis);
- } catch (InterruptedException e) {
- LOG.error("Failed to wait for
[" + sleepTimeBetweenCycleInMillis
- + "]
milliseconds before attempting to tagsync metrics information", e);
- }
- try {
-
writeJVMMetrics(logFileNameWithPath, config);
- } catch (Throwable t) {
- LOG.error("Failed to write
tagsync metrics into file. Error details: ", t);
- }
- }
- } else {
- LOG.info("No file directory found for tagsync
metrics log ");
- }
- } catch (Throwable t) {
- LOG.error("Failed to start Tagsync metrics. Error
details: ", t);
- } finally {
- LOG.info("Shutting down the TagSync metrics thread");
- }
+public class TagSyncMetricsProducer implements Runnable {
+ private static final Logger LOG =
LoggerFactory.getLogger(TagSyncMetricsProducer.class);
- }
+ private boolean shutdownFlag;
- private void writeJVMMetrics(String logFileNameWithPath, TagSyncConfig
config) throws Throwable {
- try {
- File userMetricFile = null;
- userMetricFile = new File(logFileNameWithPath);
- if (!userMetricFile.exists()) {
- userMetricFile.createNewFile();
- }
- RangerMetricsUtil rangerMetricsUtil = new
RangerMetricsUtil();
- if
(config.getBoolean(TagSyncConfig.TAGSYNC_SERVER_HA_ENABLED_PARAM, false)) {
- if(config.isTagSyncServiceActive()){
- rangerMetricsUtil.setIsRoleActive(1);
- }else{
- rangerMetricsUtil.setIsRoleActive(0);
- }
- }
- rangerMetricsUtil.writeMetricsToFile(userMetricFile);
+ public static void main(String[] args) {
+ TagSyncMetricsProducer tagSyncMetrics = new TagSyncMetricsProducer();
+ tagSyncMetrics.run();
+ // try { tagSyncMetrics.writeJVMMetrics(); } catch (Throwable e) { }
+ }
- } catch (Throwable t) {
- LOG.error("TagSyncMetricsProducer.writeJVMMetrics()
failed to write metrics into file. Error details: ", t);
- throw t;
- }
- }
+ @Override
+ public void run() {
+ try {
+ TagSyncConfig config =
TagSyncConfig.getInstance();
+ long sleepTimeBetweenCycleInMillis =
config.getTagSyncMetricsFrequency();
+ String logFileNameWithPath =
config.getTagSyncMetricsFileName();
+ LOG.info("Tagsync metrics frequency : {} and metrics file : {}",
sleepTimeBetweenCycleInMillis, logFileNameWithPath);
Review Comment:
please keep a line space between initializations and log messages.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]