@@ -20,6 +20,7 @@ import static io.xh.hoist.json.JSONParser.parseObject
2020import static io.xh.hoist.util.DateTimeUtils.MINUTES
2121import static io.xh.hoist.util.DateTimeUtils.intervalElapsed
2222import static io.xh.hoist.util.Utils.getAppEnvironment
23+ import static io.xh.hoist.util.Utils.getIsLocalDevelopment
2324import static io.xh.hoist.util.Utils.isProduction
2425import static io.xh.hoist.cluster.ClusterService.startupTime
2526import static io.xh.hoist.util.DateTimeUtils.HOURS
@@ -39,7 +40,7 @@ class MemoryMonitoringService extends BaseService {
3940 private Map<Long , Map > _snapshots = new ConcurrentHashMap ()
4041 private Date _lastInfoLogged
4142 private final String blobOwner = ' xhMemoryMonitoringService'
42- private final static String blobType = isProduction ? ' xhMemorySnapshots' : " xhMemorySnapshots_$appEnvironment "
43+ private final static String blobType = isProduction ? ' xhMemorySnapshots' : " xhMemorySnapshots_$appEnvironment "
4344
4445 void init () {
4546 createTimer(
@@ -111,7 +112,7 @@ class MemoryMonitoringService extends BaseService {
111112 logDebug(newSnap)
112113 }
113114
114- if (config . preservePastInstances) persistSnapshots()
115+ if (preservePastInstances) persistSnapshots()
115116
116117 return newSnap
117118 }
@@ -132,7 +133,8 @@ class MemoryMonitoringService extends BaseService {
132133 * Get list of past instances for which snapshots are available.
133134 */
134135 List<Map > availablePastInstances () {
135- if (! config. preservePastInstances) return []
136+ if (! preservePastInstances) return []
137+
136138 jsonBlobService
137139 .list(blobType, blobOwner)
138140 .findAll { ! clusterService. isMember(it. name) }
@@ -200,14 +202,6 @@ class MemoryMonitoringService extends BaseService {
200202 ]
201203 }
202204
203- private Map getConfig () {
204- return configService. getMap(' xhMemoryMonitoringConfig' )
205- }
206-
207- private double roundTo2DP (v ) {
208- return Math . round(v * 100 ) / 100
209- }
210-
211205 private void persistSnapshots () {
212206 try {
213207 jsonBlobService. createOrUpdate(
@@ -224,8 +218,7 @@ class MemoryMonitoringService extends BaseService {
224218 @Transactional
225219 private cullPersisted () {
226220 def all = jsonBlobService. list(blobType, blobOwner). sort { it. lastUpdated },
227- maxKeep = config. maxPastInstances != null ? Math . max(config. maxPastInstances, 0 ) : 5 ,
228- toDelete = all. dropRight(maxKeep)
221+ toDelete = all. dropRight(maxPastInstances)
229222
230223 if (toDelete) {
231224 withInfo([' Deleting memory snapshots' , [count : toDelete. size()]]) {
@@ -234,6 +227,22 @@ class MemoryMonitoringService extends BaseService {
234227 }
235228 }
236229
230+ private Map getConfig () {
231+ return configService. getMap(' xhMemoryMonitoringConfig' )
232+ }
233+
234+ private boolean getPreservePastInstances () {
235+ return config. preservePastInstances && ! getIsLocalDevelopment()
236+ }
237+
238+ private int getMaxPastInstances () {
239+ return config. maxPastInstances != null ? Math . max(config. maxPastInstances as int , 0 ) : 5
240+ }
241+
242+ private double roundTo2DP (v ) {
243+ return Math . round(v * 100 ) / 100
244+ }
245+
237246 void clearCaches () {
238247 _snapshots. clear()
239248 super . clearCaches()
0 commit comments