Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
Default value for REDIS_SMEMBERS_COUNT (#532)
Browse files Browse the repository at this point in the history
Use a default value for the OS env variable REDIS_SMEMBERS_COUNT in case it's not defined. Prevents an NPE at runtime. Default value was derived from the commit message of ac6e26f.
  • Loading branch information
twz123 authored and mohabusama committed Jan 2, 2018
1 parent 47ae2f8 commit 59f5b9a
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -56,6 +56,7 @@ public class AlertServiceImpl implements AlertService {
private static final String DOWNTIMES_KEY = "downtimes";

private final NamedMessageFormatter messageFormatter = new NamedMessageFormatter();
private final long redisSMembersCount = parseRedisSmembersCount();

@Autowired
private NoOpEventLog eventLog;
Expand Down Expand Up @@ -265,7 +266,7 @@ protected void getActiveAlertsForDefinitionsWithoutEntities(List<AlertDefinition
p.sync();
Long count = response.get();

if (count > Long.parseLong(System.getenv("REDIS_SMEMBERS_COUNT")))
if (count > redisSMembersCount)
results.add(ResponseHolder.create(definition.getId(),
p.scard(RedisPattern.alertEntities(definition.getId()))));
else
Expand Down Expand Up @@ -627,4 +628,9 @@ private String buildMessage(final String template, final List<LastCheckResult> c
public Date getMaxLastModified() {
return alertDefinitionSProc.getAlertLastModifiedMax();
}

private static long parseRedisSmembersCount() {
final String smembersCount = System.getenv("REDIS_SMEMBERS_COUNT");
return smembersCount == null ? 1000 : Long.parseLong(smembersCount);
}
}

0 comments on commit 59f5b9a

Please sign in to comment.