public String getMessageWithTimestamp() { return getMessage() + " [" + TIMESTAMP_FORMAT.format(timestamp) + "]"; }
private Exception represent(ServerHealthState serverHealthState) { String message = new StringBuilder() .append(serverHealthState.getMessage().toUpperCase()) .append("\n") .append(serverHealthState.getDescription()) .toString(); return new Exception(message); }
public String getLogsAsText() { StringBuilder text = new StringBuilder(); for (ServerHealthState state : logs()) { text.append(state.getDescription()); text.append("\n\t"); text.append(state.getMessage()); text.append("\n"); } return text.toString(); }
public Map<String, String> asJson() { Map<String, String> json = new LinkedHashMap<>(); json.put("message", getMessage()); json.put("detail", getDescription()); json.put("level", healthStateLevel.toString()); return json; }
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 void canProduce(PipelineConfig pipelineConfig, SchedulingCheckerService schedulingChecker, ServerHealthService serverHealthService, OperationResult operationResult) { schedulingChecker.canTriggerPipelineWithTimer(pipelineConfig, operationResult); if (!operationResult.canContinue()) { ServerHealthState serverHealthState = operationResult.getServerHealthState(); LOGGER.info("'{}' because '{}'", serverHealthState.getMessage(), serverHealthState.getDescription()); } else { TimerConfig timer = pipelineConfig.getTimer(); String timerSpec = timer == null ? "Missing timer spec" : timer.getTimerSpec(); LOGGER.info("Timer scheduling pipeline '{}' using spec '{}'", pipelineConfig.name(), timerSpec); } }
public void canProduce(PipelineConfig pipelineConfig, SchedulingCheckerService schedulingChecker, ServerHealthService serverHealthService, OperationResult operationResult) { schedulingChecker.canTriggerManualPipeline(pipelineConfig, CaseInsensitiveString.str(username.getUsername()), operationResult); if (!operationResult.canContinue()) { ServerHealthState serverHealthState = operationResult.getServerHealthState(); LOGGER.info("'{}' because '{}'", serverHealthState.getMessage(), serverHealthState.getDescription()); serverHealthService.update(serverHealthState); } }
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)); }
@Test public void shouldEscapeWarningMessageAndDescriptionByDefault() { ServerHealthState warningStateWithoutTimeout = ServerHealthState.warning("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo"))); ServerHealthState warningStateWithTimeout = ServerHealthState.warning("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo")), Timeout.TEN_SECONDS); ServerHealthState warningState = ServerHealthState.warning("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo")), 15L); assertThat(warningStateWithoutTimeout.getMessage(), is(""<message1 & message2>"")); assertThat(warningStateWithoutTimeout.getDescription(), is(""<message1 & message2>"")); assertThat(warningStateWithTimeout.getMessage(), is("\"<message1 & message2>\"")); assertThat(warningStateWithTimeout.getDescription(), is("\"<message1 & message2>\"")); assertThat(warningState.getMessage(), is(""<message1 & message2>"")); assertThat(warningState.getDescription(), is(""<message1 & message2>"")); }
@Test public void shouldPreserverHtmlInWarningMessageAndDescription() { ServerHealthState warningState = ServerHealthState.warningWithHtml("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo"))); ServerHealthState warningStateWithTime = ServerHealthState.warningWithHtml("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo")), 15L); assertThat(warningState.getMessage(), is("\"<message1 & message2>\"")); assertThat(warningState.getDescription(), is("\"<message1 & message2>\"")); assertThat(warningStateWithTime.getMessage(), is("\"<message1 & message2>\"")); assertThat(warningStateWithTime.getDescription(), is("\"<message1 & message2>\"")); } }
@Test public void shouldEscapeErrorMessageAndDescriptionByDefault() { ServerHealthState errorState = ServerHealthState.error("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo"))); assertThat(errorState.getMessage(), is(""<message1 & message2>"")); assertThat(errorState.getDescription(), is(""<message1 & message2>"")); }
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; } }