@Test public void testGetHealthyStatus() throws IOException { String expression = FileUtils.readFile(HealthyTest.class.getResource("/healthExpression.js").getPath(), Charset .forName("utf-8")); Healthy healthy = new Healthy(expression); Map<String, Object> stat = new HashMap<String, Object>(); stat.put("readqps_1m", 10l); stat.put("latencyRead_1m_p50", 50l); stat.put("writeqps_1m", 100l); stat.put("latencyWrite_1m_p50", 50l); stat.put("mongo_replMaster", "localhost"); stat.put("mongo_databases", "[abc,def]"); Assert.assertEquals(0.6, healthy.getHealthyStatus(null), 0.01); Assert.assertEquals(0.2, healthy.getHealthyStatus(stat), 0.01); stat.put("latencyWrite_1m_p50", 2500l); Assert.assertEquals(0.2, healthy.getHealthyStatus(stat), 0.01); stat.put("readqps_1m", 1000l); stat.put("latencyRead_1m_p50", 500l); stat.put("writeqps_1m", 1000l); stat.put("latencyWrite_1m_p50", 500l); Assert.assertEquals(0.9, healthy.getHealthyStatus(stat), 0.01); stat.put("latencyWrite_1m_p50", 100l); stat.put("readqps_1m", 500l); Assert.assertEquals(0.2, healthy.getHealthyStatus(stat), 0.01); stat.put("latencyWrite_1m_p50", 2500l); Assert.assertEquals(0.9, healthy.getHealthyStatus(stat), 0.01); stat.put("latencyWrite_1m_p50", 2500l); stat.put("writeqps_1m", 2500l); Assert.assertEquals(0.95, healthy.getHealthyStatus(stat), 0.01); stat.put("latencyRead_1m_p50", 2500l); stat.put("readqps_1m", 2500l); Assert.assertEquals(0.95, healthy.getHealthyStatus(stat), 0.01); stat.put(MetricConstants.REPL_MASTER, "not found!"); Assert.assertEquals(1.5, healthy.getHealthyStatus(stat), 0.01); stat.put(MetricConstants.REPL_DATABASES, "not found!"); Assert.assertEquals(2.5, healthy.getHealthyStatus(stat), 0.01); }
double getHealthyStatus(Map<String, Object> systemStatistics) { if (systemStatistics == null) { logger.error("systemStatistics should not be null"); return 0.6; } StatisticsExpressionContext context = new StatisticsExpressionContext(systemStatistics); try { Object val = enginee.evaluate(expression, context); if (val != null) { return (Double) val; } } catch (Exception e) { logger.error("failed to eval healthy expression", e); } return 0.2; }
Healthy { double getHealthyStatus(Map<String, Object> systemStatistics) { if (systemStatistics == null) { logger.error("systemStatistics should not be null"); return 0.6; } StatisticsExpressionContext context = new StatisticsExpressionContext(systemStatistics); try { Object val = enginee.evaluate(expression, context); if (val != null) { return (Double) val; } } catch (Exception e) { logger.error("failed to eval healthy expression", e); } return 0.2; } }
Healthy { double getHealthyStatus(Map<String, Object> systemStatistics) { if (systemStatistics == null) { logger.error("systemStatistics should not be null"); return 0.6; } StatisticsExpressionContext context = new StatisticsExpressionContext(systemStatistics); try { Object val = enginee.evaluate(expression, context); if (val != null) { return (Double) val; } } catch (Exception e) { logger.error("failed to eval healthy expression", e); } return 0.2; } Healthy(String expression); }
Healthy { double getHealthyStatus(Map<String, Object> systemStatistics) { if (systemStatistics == null) { logger.error("systemStatistics should not be null"); return 0.6; } StatisticsExpressionContext context = new StatisticsExpressionContext(systemStatistics); try { Object val = enginee.evaluate(expression, context); if (val != null) { return (Double) val; } } catch (Exception e) { logger.error("failed to eval healthy expression", e); } return 0.2; } Healthy(String expression);  }
Healthy { double getHealthyStatus(Map<String, Object> systemStatistics) { if (systemStatistics == null) { logger.error("systemStatistics should not be null"); return 0.6; } StatisticsExpressionContext context = new StatisticsExpressionContext(systemStatistics); try { Object val = enginee.evaluate(expression, context); if (val != null) { return (Double) val; } } catch (Exception e) { logger.error("failed to eval healthy expression", e); } return 0.2; } Healthy(String expression);   }