public HealthStateType update(ServerHealthState serverHealthState) { HealthStateType type = serverHealthState.getType(); if (serverHealthState.getLogLevel() == HealthStateLevel.OK) { if (serverHealth.containsKey(type)) { serverHealth.remove(type); } return null; } else { serverHealth.put(type, serverHealthState); return type; } }
public void describeTo(Description description) { description.appendText("HealthStateType " + healthStateType + " contains: " + entry + "\n" + "With level: " + entry.getLogLevel()); } };
public boolean containsError(HealthStateType type, HealthStateLevel level) { ServerHealthStates allLogs = logs(); for (ServerHealthState log : allLogs) { if (log.getType().equals(type) && log.getLogLevel() == level) { return true; } } return false; }
public void describeTo(Description description) { if (entry == null) { description.appendText("Can not find result with " + healthStateType + " in all logs: " + allLogs); } else { if (!levelMatches) { description.appendText("Level was " + entry.getLogLevel() + " instead of " + healthStateLevel); } if (!messageMatches) { description.appendText("Message was: \n" + entry.getMessage() + "\n instead of:\n" + message); } } } };
public static void toJSON(OutputListWriter outputListWriter, Collection<ServerHealthState> healthStates) { healthStates.forEach(healthState -> outputListWriter.addChild(writer -> writer.add("message", healthState.getMessage()) .add("detail", healthState.getDescription()) .add("level", healthState.getLogLevel().toString()) .add("time", healthState.getTimestamp())) ); } }
@Test public void shouldAddWarningWhenConfigRepoLooseObjectCountGoesBeyondTheConfiguredThreshold() throws Exception { when(systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_GC_LOOSE_OBJECT_WARNING_THRESHOLD)).thenReturn(10L); when(configRepository.getLooseObjectCount()).thenReturn(20L); service.checkRepoAndAddWarningIfRequired(); List<ServerHealthState> healthStates = serverHealthService.filterByScope(HealthStateScope.forConfigRepo("GC")); String message = "Action required: Run 'git gc' on config.git repo"; String description = "Number of loose objects in your Configuration repository(config.git) has grown beyond " + "the configured threshold. As the size of config repo increases, the config save operations tend to slow down " + "drastically. It is recommended that you run 'git gc' from " + "'<go server installation directory>/db/config.git/' to address this problem. Go can do this " + "automatically on a periodic basis if you enable automatic GC. <a target='_blank' href='" + docsUrl("/advanced_usage/config_repo.html") + "'>read more...</a>"; assertThat(healthStates.get(0).getDescription(), is(description)); assertThat(healthStates.get(0).getLogLevel(), is(HealthStateLevel.WARNING)); assertThat(healthStates.get(0).getMessage(), is(message)); }
public boolean matchesSafely(ServerHealthService item) { allLogs = item.logs(); for (ServerHealthState serverHealthState : allLogs) { if (serverHealthState.getType().equals(healthStateType)) { entry = serverHealthState; } } if (!(entry != null)) { return false; } else { levelMatches = healthStateLevel == null || healthStateLevel.equals(entry.getLogLevel()); messageMatches = message == null || message.equals(entry.getMessage()); return levelMatches && messageMatches; } }