{"record":{"id":"059c674a54dff442","repo":"SonarSource/sonarqube","slug":"failed-to-retrieve-es-attributes-there-will-be-on","errorCode":null,"errorMessage":"Failed to retrieve ES attributes. There will be only a single \"state\" attribute.","messagePattern":"Failed to retrieve ES attributes\\. There will be only a single \"state\" attribute\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java","lineNumber":58,"sourceCode":"  public EsStateSection(EsClient esClient) {\n    this.esClient = esClient;\n  }\n\n  private HealthStatus getStateAsEnum() {\n    return esClient.clusterHealthV2(req -> req).status();\n  }\n\n  @Override\n  public ProtobufSystemInfo.Section toProtobuf() {\n    ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();\n    protobuf.setName(\"Search State\");\n    try {\n      // ES8 HealthStatus enum is mixed-case (Green/Yellow/Red); webapp expects upper-case\n      // for the System Info \"State\" field (see StatusIndicator.tsx ICON_MAP).\n      setAttribute(protobuf, \"State\", getStateAsEnum().name().toUpperCase(Locale.ENGLISH));\n      completeNodeAttributes(protobuf);\n    } catch (Exception es) {\n      LoggerFactory.getLogger(EsStateSection.class).warn(\"Failed to retrieve ES attributes. There will be only a single \\\"state\\\" attribute.\", es);\n      Throwable cause = es.getCause();\n      setAttribute(protobuf, \"State\",\n        cause instanceof ElasticsearchException ? cause.getMessage() : es.getMessage());\n    }\n    return protobuf.build();\n  }\n\n  private void completeNodeAttributes(ProtobufSystemInfo.Section.Builder protobuf) {\n    NodeStatsResponse nodesStatsResponse = esClient.nodesStats();\n\n    if (!nodesStatsResponse.getNodeStats().isEmpty()) {\n      toProtobuf(nodesStatsResponse.getNodeStats().get(0), protobuf);\n    }\n  }\n\n  public static void toProtobuf(NodeStats stats, ProtobufSystemInfo.Section.Builder protobuf) {\n    setAttribute(protobuf, \"CPU Usage (%)\", stats.getCpuUsage());\n    setAttribute(protobuf, \"Disk Available\", humanReadableByteCountSI(stats.getDiskAvailableBytes()));","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java#L40-L76","documentation":"This is a warning logged by the ES (Elasticsearch) state section of the System Info page when collecting Elasticsearch node attributes fails. The section normally publishes attributes like 'State' (Green/Yellow/Red) plus node details into the System Info protobuf; on failure it degrades gracefully and only emits a single 'State' attribute derived from the exception message.","triggerScenarios":"Calling toProtobuf (via the Search State web service section) when the ES client throws while fetching health/node info — e.g. node down, connection failure, or an ElasticsearchException returned by the cluster.","commonSituations":"Elasticsearch stopped or restarting during web server startup; wrong ES host/port settings (sonar.search.host/port); ES8 mixed-case HealthStatus handling paths; cluster health timeouts.","solutions":["Check Elasticsearch is running and reachable at the configured sonar.search host/port (curl the ES node's HTTP endpoint).","Inspect the logged exception and its cause; if it is an ElasticsearchException the State attribute will carry its message — fix the reported cluster issue (e.g. red health, missing indices).","Verify sonar.search.* configuration matches the embedded/external ES instance.","Restart the node after disk/network issues so ES health returns to Green/Yellow."],"exampleFix":"// before (typical failure: ES not reachable)\nsonar.search.host=127.0.0.1\nsonar.search.port=9001\n// after: confirm ES is up and port matches\n# curl http://127.0.0.1:9001/_cluster/health\nsonar.search.host=127.0.0.1\nsonar.search.port=9001","handlingStrategy":"try-catch","validationCode":"// check ES reachability before hitting the System Info state section\nconst res = await fetch('http://es-host:9001/_cluster/health');\nif (!res.ok) throw new Error('ES unreachable: ' + res.status);","typeGuard":"function isEsHealth(v) {\n  return v != null && typeof v === 'object' && typeof v.status === 'string';\n}","tryCatchPattern":"try {\n  const health = await esClient.cluster.health();\n} catch (e) {\n  logger.warn('Failed to retrieve ES attributes', e); // degrade to limited state\n}","preventionTips":["Monitor ES process and port availability with health checks","Keep sonar.search host/port settings in sync with the actual ES instance","Alert on cluster health turning Red","Ensure ES has enough heap and disk to answer health API quickly"],"tags":["elasticsearch","monitoring","graceful-degradation","system-info"],"backgroundTag":"connection-refused","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}