From 7e2ed1be7ae5c6243b3e959ce06507b649c99232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Vl=C4=8Dek?= Date: Tue, 13 Aug 2019 11:30:03 +0200 Subject: [PATCH] Adapt to new upstream code changes There are two main changes impacting the code when upgrading top 7.3.0. The first is introduction of pluggable Node roles: - https://github.com/elastic/elasticsearch/pull/43175 The second is renaming the Action class to ActionType: - https://github.com/elastic/elasticsearch/pull/43778 --- .../prometheus/PrometheusMetricsCollector.java | 9 ++++++--- .../action/NodePrometheusMetricsAction.java | 14 ++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java b/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java index 8600a243..915e79ed 100644 --- a/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java +++ b/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java @@ -24,7 +24,7 @@ import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.cluster.health.ClusterIndexHealth; -import org.elasticsearch.cluster.node.DiscoveryNode.Role; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.http.HttpStats; import org.elasticsearch.indices.NodeIndicesStats; import org.elasticsearch.indices.breaker.AllCircuitBreakerStats; @@ -129,14 +129,17 @@ private void registerNodeMetrics() { private void updateNodeMetrics(NodeStats ns) { if (ns != null) { + + // Plugins can introduce custom node roles from 7.3.0: https://github.com/elastic/elasticsearch/pull/43175 + // TODO(lukas-vlcek): List of node roles can not be static but needs to be created dynamically. Map roles = new HashMap<>(); roles.put("master", 0); roles.put("data", 0); roles.put("ingest", 0); - for (Role r : ns.getNode().getRoles()) { - roles.put(r.getRoleName(), 1); + for (DiscoveryNodeRole r : ns.getNode().getRoles()) { + roles.put(r.roleName(), 1); } for (String k : roles.keySet()) { diff --git a/src/main/java/org/elasticsearch/action/NodePrometheusMetricsAction.java b/src/main/java/org/elasticsearch/action/NodePrometheusMetricsAction.java index ab644c86..03bb1eb4 100644 --- a/src/main/java/org/elasticsearch/action/NodePrometheusMetricsAction.java +++ b/src/main/java/org/elasticsearch/action/NodePrometheusMetricsAction.java @@ -21,18 +21,16 @@ /** * Action class for Prometheus Exporter plugin. */ -public class NodePrometheusMetricsAction extends Action { +public class NodePrometheusMetricsAction extends ActionType { + // TODO(lukas-vlcek): There are ongoing changes for ActionType class. This code needs additional review. + // - https://github.com/elastic/elasticsearch/pull/43778 + // - https://github.com/elastic/elasticsearch/commit/b33ffc1ae06035e934277f17c4b5d9851f607056#diff-80df90ca727aadbbe854902f81bda313 + // - https://github.com/elastic/elasticsearch/commit/5a9f81791a1be7fe6dd97728384ebafb189ab211#diff-80df90ca727aadbbe854902f81bda313 public static final NodePrometheusMetricsAction INSTANCE = new NodePrometheusMetricsAction(); public static final String NAME = "cluster:monitor/prometheus/metrics"; private NodePrometheusMetricsAction() { - super(NAME); - } - - @Override - @SuppressWarnings("deprecation") - public NodePrometheusMetricsResponse newResponse() { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); + super(NAME, null); } @Override