@Test public void load_info_from_all_nodes() throws Exception { DistributedAnswer<SystemInfo> answer = new DistributedAnswer<>(); answer.setAnswer(newMember("foo"), SystemInfo.newBuilder().addSections(Section.newBuilder().build()).build()); answer.setTimedOut(newMember("bar")); answer.setFailed(newMember("baz"), new IOException("BOOM")); when(hzMember.call(any(DistributedCall.class), any(MemberSelector.class), anyLong())).thenReturn(answer); Collection<NodeInfo> nodes = underTest.load(); assertThat(nodes).hasSize(3); NodeInfo successfulNodeInfo = findNode(nodes, "foo"); assertThat(successfulNodeInfo.getName()).isEqualTo("foo"); assertThat(successfulNodeInfo.getHost()).hasValue(AN_ADDRESS.getHostAddress()); assertThat(successfulNodeInfo.getErrorMessage()).isEmpty(); assertThat(successfulNodeInfo.getSections()).hasSize(1); NodeInfo timedOutNodeInfo = findNode(nodes, "bar"); assertThat(timedOutNodeInfo.getName()).isEqualTo("bar"); assertThat(timedOutNodeInfo.getErrorMessage()).hasValue("Failed to retrieve information on time"); assertThat(timedOutNodeInfo.getSections()).isEmpty(); NodeInfo failedNodeInfo = findNode(nodes, "baz"); assertThat(failedNodeInfo.getName()).isEqualTo("baz"); assertThat(failedNodeInfo.getErrorMessage()).hasValue("Failed to retrieve information: BOOM"); assertThat(failedNodeInfo.getSections()).isEmpty(); }
@Test public void name_is_not_empty() { assertThat(underTest.toProtobuf().getName()).isEqualTo("System"); }
@Test public void return_info_from_elasticsearch_api() { Collection<NodeInfo> nodes = underTest.load(); assertThat(nodes).hasSize(1); NodeInfo node = nodes.iterator().next(); assertThat(node.getName()).isNotEmpty(); assertThat(node.getHost()).isNotEmpty(); assertThat(node.getSections()).hasSize(1); ProtobufSystemInfo.Section stateSection = node.getSections().get(0); assertThat(stateSection.getAttributesList()) .extracting(ProtobufSystemInfo.Attribute::getKey) .contains( "Disk Available", "Store Size", "JVM Heap Usage", "JVM Heap Used", "JVM Heap Max", "JVM Non Heap Used", "JVM Threads", "Field Data Memory", "Field Data Circuit Breaker Limit", "Field Data Circuit Breaker Estimation", "Request Circuit Breaker Limit", "Request Circuit Breaker Estimation", "Query Cache Memory", "Request Cache Memory"); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder builder = ProtobufSystemInfo.Section.newBuilder(); builder.setName("Compute Engine Database Connection"); builder.addAttributesBuilder().setKey("Pool Initial Size").setLongValue(getPoolInitialSize()).build(); builder.addAttributesBuilder().setKey("Pool Active Connections").setLongValue(getPoolActiveConnections()).build(); builder.addAttributesBuilder().setKey("Pool Idle Connections").setLongValue(getPoolIdleConnections()).build(); builder.addAttributesBuilder().setKey("Pool Max Active Connections").setLongValue(getPoolMaxActiveConnections()).build(); builder.addAttributesBuilder().setKey("Pool Max Idle Connections").setLongValue(getPoolMaxIdleConnections()).build(); builder.addAttributesBuilder().setKey("Pool Min Idle Connections").setLongValue(getPoolMinIdleConnections()).build(); builder.addAttributesBuilder().setKey("Pool Max Wait (ms)").setLongValue(getPoolMaxWaitMillis()).build(); builder.addAttributesBuilder().setKey("Pool Remove Abandoned").setBooleanValue(getPoolRemoveAbandoned()).build(); builder.addAttributesBuilder().setKey("Pool Remove Abandoned Timeout (sec)").setLongValue(getPoolRemoveAbandonedTimeoutSeconds()).build(); return builder.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "Version", getVersion()); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "High Availability", false); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
@Override public Section toProtobuf() { Section.Builder protobuf = Section.newBuilder(); protobuf.setName("Database"); try (DbSession dbSession = dbClient.openSession(false)) { DatabaseMetaData metadata = dbSession.getConnection().getMetaData(); setAttribute(protobuf, "Database", metadata.getDatabaseProductName()); setAttribute(protobuf, "Database Version", metadata.getDatabaseProductVersion()); setAttribute(protobuf, "Username", metadata.getUserName()); setAttribute(protobuf, "URL", metadata.getURL()); setAttribute(protobuf, "Driver", metadata.getDriverName()); setAttribute(protobuf, "Driver Version", metadata.getDriverVersion()); } catch (SQLException e) { throw new IllegalStateException("Fail to get DB metadata", e); } return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Plugins"); for (PluginInfo plugin : repository.getPluginInfos()) { String label = "[" + plugin.getName() + "]"; Version version = plugin.getVersion(); if (version != null) { label = version.getName() + " " + label; } setAttribute(protobuf, plugin.getKey(), label); } return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Search State"); try { setAttribute(protobuf, "State", getStateAsEnum().name()); completeNodeAttributes(protobuf); } catch (Exception es) { Loggers.get(EsStateSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"state\" attribute.", es); setAttribute(protobuf, "State", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage()); } return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder builder = ProtobufSystemInfo.Section.newBuilder(); builder.setName("Compute Engine Tasks"); builder.addAttributesBuilder().setKey("Pending").setLongValue(getPendingCount()).build(); builder.addAttributesBuilder().setKey("In Progress").setLongValue(getInProgressCount()).build(); builder.addAttributesBuilder().setKey("Processed With Error").setLongValue(getErrorCount()).build(); builder.addAttributesBuilder().setKey("Processed With Success").setLongValue(getSuccessCount()).build(); builder.addAttributesBuilder().setKey("Processing Time (ms)").setLongValue(getProcessingTime()).build(); builder.addAttributesBuilder().setKey("Worker Count").setLongValue(getWorkerCount()).build(); builder.addAttributesBuilder().setKey("Max Worker Count").setLongValue(getWorkerMaxCount()).build(); return builder.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Version", server.getVersion()); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
private static NodeInfo toNodeInfo(NodeStats stat) { String nodeName = stat.getNode().getName(); NodeInfo info = new NodeInfo(nodeName); info.setHost(stat.getHostname()); ProtobufSystemInfo.Section.Builder section = ProtobufSystemInfo.Section.newBuilder(); section.setName("Search State"); EsStateSection.toProtobuf(stat, section); info.addSection(section.build()); return info; }
@Override public Section toProtobuf() { Section.Builder protobuf = Section.newBuilder(); String side = runtime.getSonarQubeSide() == SonarQubeSide.COMPUTE_ENGINE ? "Compute Engine" : "Web"; protobuf.setName(side + " Database Connection"); completePoolAttributes(protobuf); return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); if (runtime.getSonarQubeSide() == SonarQubeSide.COMPUTE_ENGINE) { protobuf.setName("Compute Engine Logging"); } else { protobuf.setName("Web Logging"); } SystemInfoUtils.setAttribute(protobuf, "Logs Level", logging.getRootLoggerLevel().name()); SystemInfoUtils.setAttribute(protobuf, "Logs Dir", logging.getLogsDir().getAbsolutePath()); return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Settings"); PropertyDefinitions definitions = settings.getDefinitions(); TreeMap<String, String> orderedProps = new TreeMap<>(settings.getProperties()); for (Map.Entry<String, String> prop : orderedProps.entrySet()) { String key = prop.getKey(); String value = obfuscateValue(definitions, key, prop.getValue()); setAttribute(protobuf, key, value); } return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Compute Engine Tasks"); try (DbSession dbSession = dbClient.openSession(false)) { setAttribute(protobuf, "Total Pending", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING)); setAttribute(protobuf, "Total In Progress", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.IN_PROGRESS)); setAttribute(protobuf, "Max Workers per Node", workerCountProvider == null ? DEFAULT_NB_OF_WORKERS : workerCountProvider.get()); setAttribute(protobuf, "Workers Paused", "true".equals(dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE).orElse(null))); } return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Search Indexes"); try { completeIndexAttributes(protobuf); } catch (Exception es) { Loggers.get(EsIndexesSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"Error\" attribute.", es); setAttribute(protobuf, "Error", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage()); } return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "High Availability", true); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); return protobuf.build(); }
private void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { json.name(section.getName()); json.beginObject(); for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { writeAttribute(attribute, json); } json.endObject(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Search State"); ClusterStatsResponse stats = esClient.prepareClusterStats().get(); setAttribute(protobuf, "State", stats.getStatus().name()); setAttribute(protobuf, "Nodes", stats.getNodesStats().getCounts().getTotal()); return protobuf.build(); }
@Test public void write_json() { logInAsSystemAdministrator(); ProtobufSystemInfo.Section.Builder attributes1 = ProtobufSystemInfo.Section.newBuilder() .setName("Section One"); setAttribute(attributes1, "foo", "bar"); when(section1.toProtobuf()).thenReturn(attributes1.build()); ProtobufSystemInfo.Section.Builder attributes2 = ProtobufSystemInfo.Section.newBuilder() .setName("Section Two"); setAttribute(attributes2, "one", 1); setAttribute(attributes2, "two", 2); when(section2.toProtobuf()).thenReturn(attributes2.build()); when(ceHttpClient.retrieveSystemInfo()).thenReturn(Optional.empty()); StringWriter writer = new StringWriter(); JsonWriter jsonWriter = JsonWriter.of(writer); jsonWriter.beginObject(); underTest.write(jsonWriter); jsonWriter.endObject(); // response does not contain empty "Section Three" assertThat(writer.toString()).isEqualTo("{\"Health\":\"GREEN\",\"Health Causes\":[],\"Section One\":{\"foo\":\"bar\"},\"Section Two\":{\"one\":1,\"two\":2}," + "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"usingBranches\":false," + "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[]}}"); }