@Override public void onConfigChange(CruiseConfig newCruiseConfig) { for (ServerHealthState state : serverHealthService.logs()) { HealthStateScope currentScope = state.getType().getScope(); if (currentScope.isForJob()) { serverHealthService.removeByScope(currentScope); } } }
private ServerHealthState kickMe(ServerHealthState whatWentWrong, boolean isEverythingOk) { canContinue = isEverythingOk; serverHealthService.update(whatWentWrong); state = whatWentWrong; return whatWentWrong; }
public synchronized void onTimer() { CruiseConfig currentConfig = applicationContext.getBean(CruiseConfigProvider.class).getCurrentConfig(); purgeStaleHealthMessages(currentConfig); LOG.debug("Recomputing material to pipeline mappings."); HashMap<ServerHealthState, Set<String>> erroredPipelines = new HashMap<>(); for (Map.Entry<HealthStateType, ServerHealthState> entry : serverHealth.entrySet()) { erroredPipelines.put(entry.getValue(), entry.getValue().getPipelineNames(currentConfig)); } pipelinesWithErrors = erroredPipelines; LOG.debug("Done recomputing material to pipeline mappings."); }
private void removeMessagesForElementsNoLongerInConfig(CruiseConfig cruiseConfig) { for (HealthStateType type : entryKeys()) { if (type.isRemovedFromConfig(cruiseConfig)) { this.removeByScope(type); } } }
private void replaceServerHealthMessages(String errorMessageTitle, HealthStateScope scope, List<PluginHealthMessage> pluginHealthMessages) { serverHealthService.removeByScope(scope); for (int index = 0; index < pluginHealthMessages.size(); index++) { PluginHealthMessage pluginHealthMessage = pluginHealthMessages.get(index); ServerHealthState state; if (pluginHealthMessage.isWarning()) { state = ServerHealthState.warning(errorMessageTitle, pluginHealthMessage.message(), HealthStateType.withSubkey(scope, "message_" + index)); } else { state = ServerHealthState.error(errorMessageTitle, pluginHealthMessage.message(), HealthStateType.withSubkey(scope, "message_" + index)); } serverHealthService.update(state); } } }
@Test public void shouldRemoveErrorLogWhenCorrespondingGroupIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("message", "description", groupId)); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); assertThat(serverHealthService.logs().size(), is(0)); }
@Test public void shouldUpdateLogInServerHealth() throws Exception { ServerHealthState serverHealthState = ServerHealthState.error("message", "description", globalId); serverHealthService.update(serverHealthState); ServerHealthState newServerHealthState = ServerHealthState.error("updated message", "updated description", globalId); serverHealthService.update(newServerHealthState); assertThat(serverHealthService.logs().size(), is(1)); assertThat(serverHealthService, ServerHealthMatcher.containsState(globalId, HealthStateLevel.ERROR, "updated message")); }
@Test public void shouldRemoveLogByCategoryFromServerHealth() throws Exception { HealthStateScope scope = forPipeline(PIPELINE_NAME); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(scope))); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.invalidLicense(scope))); serverHealthService.update(ServerHealthState.error("message", "description", globalId)); assertThat(serverHealthService.logs().size(), is(3)); serverHealthService.removeByScope(scope); assertThat(serverHealthService.logs().size(), is(1)); assertThat(serverHealthService, ServerHealthMatcher.containsState(globalId)); }
public void onConfigChange(CruiseConfig newCruiseConfig) { if (registering) { registering = false; return; } serverHealthService.removeByScope(HealthStateScope.forInvalidConfig()); }
@Test public void stateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService = new ServerHealthService(); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forPipeline(PIPELINE_NAME)))); assertThat((serverHealthService.logs().get(0)).getPipelineNames(config), equalTo(Collections.singleton(PIPELINE_NAME))); serverHealthService = new ServerHealthService(); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forStage(PIPELINE_NAME, "stage1")))); assertThat((serverHealthService.logs().get(0)).getPipelineNames(config), equalTo(Collections.singleton(PIPELINE_NAME))); serverHealthService = new ServerHealthService(); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forJob(PIPELINE_NAME, "stage1", "job1")))); assertThat((serverHealthService.logs().get(0)).getPipelineNames(config), equalTo(Collections.singleton(PIPELINE_NAME))); }
@Override public Map<String, Object> asJson() { LinkedHashMap<String, Object> json = new LinkedHashMap<>(); ServerHealthStates allLogs = service.logs(); json.put("Messages Count", allLogs.size()); ArrayList<Map<String, String>> messages = new ArrayList<>(); for (ServerHealthState log : allLogs) { messages.add(log.asJson()); } json.put("Messages", messages); return json; }
@Test public void shouldRemoteExistingWarningAboutGCIfLooseObjectCountGoesBelowTheSetThreshold() throws Exception { serverHealthService.update(ServerHealthState.warning("message", "description", HealthStateType.general(HealthStateScope.forConfigRepo("GC")))); assertThat(serverHealthService.filterByScope(HealthStateScope.forConfigRepo("GC")).isEmpty(), is(false)); when(systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_GC_LOOSE_OBJECT_WARNING_THRESHOLD)).thenReturn(10L); when(configRepository.getLooseObjectCount()).thenReturn(1L); service.checkRepoAndAddWarningIfRequired(); assertThat(serverHealthService.filterByScope(HealthStateScope.forConfigRepo("GC")).isEmpty(), is(true)); }
@Test public void shouldNotAddWarningWhenConfigRepoLooseObjectCountIsBelowTheConfiguredThreshold() throws Exception { when(systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_GC_LOOSE_OBJECT_WARNING_THRESHOLD)).thenReturn(10L); when(configRepository.getLooseObjectCount()).thenReturn(1L); service.checkRepoAndAddWarningIfRequired(); List<ServerHealthState> healthStates = serverHealthService.filterByScope(HealthStateScope.forConfigRepo("GC")); assertThat(healthStates.isEmpty(), is(true)); }
@Before public void setUp() throws Exception { configRepository = mock(ConfigRepository.class); serverHealthService = new ServerHealthService(); systemEnvironment = mock(SystemEnvironment.class); service = new ConfigRepositoryGCWarningService(configRepository, serverHealthService, systemEnvironment); }
@Override public void check(OperationResult result) { if (!serverHealthService.containsError(ARTIFACTS_DISK_FULL_ID, HealthStateLevel.ERROR)) { super.check(result); } } }
@Test public void shouldRemoveErrorLogWhenCorrespondingPipelineIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("message", "description", pipelineId)); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forPipeline("other")))); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); assertThat(serverHealthService.logs().size(), is(0)); }
@Test public void shouldAddMultipleLogToServerHealth() throws Exception { assertThat(serverHealthService.update(ServerHealthState.error("message", "description", globalId)), is(globalId)); assertThat(serverHealthService.update(ServerHealthState.error("message", "description", pipelineId)), is(pipelineId)); assertThat(serverHealthService.logs().size(), is(2)); assertThat(serverHealthService, ServerHealthMatcher.containsState(globalId)); assertThat(serverHealthService, ServerHealthMatcher.containsState(pipelineId)); }
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); } } }
public void removeKnown(String fingerprint) { if (fingerprintToLatestKnownConfigMap.containsKey(fingerprint)) { fingerprintToLatestKnownConfigMap.remove(fingerprint); serverHealthService.removeByScope(HealthStateScope.forPartialConfigRepo(fingerprint)); } }
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(); }