public void checkRepoAndAddWarningIfRequired() { try { if (configRepository.getLooseObjectCount() >= systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_GC_LOOSE_OBJECT_WARNING_THRESHOLD)) { 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>"; serverHealthService.update(ServerHealthState.warningWithHtml(message, description, HealthStateType.general(HealthStateScope.forConfigRepo(SCOPE)))); LOGGER.warn("{}:{}", message, description); } else { serverHealthService.removeByScope(HealthStateScope.forConfigRepo(SCOPE)); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } }
private void addJobHungWarning(JobIdentifier jobIdentifier, long difference) { String namespacedJob = String.format("%s/%s/%s", jobIdentifier.getPipelineName(), jobIdentifier.getStageName(), jobIdentifier.getBuildName()); serverHealthService.update(ServerHealthState.warningWithHtml( String.format("Job '%s' is not responding", namespacedJob), String.format("Job <a href='/go/tab/build/detail/%s'>%s</a> is currently running but has not shown any console activity in the last %s minute(s). This job may be hung.", jobIdentifier.buildLocator(), namespacedJob, inMinutes(difference)), HealthStateType.general(HealthStateScope.forJob(jobIdentifier.getPipelineName(), jobIdentifier.getStageName(), jobIdentifier.getBuildName())))); }
@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>\"")); } }