Skip to content

Commit 485a42d

Browse files
authored
[Monitoring] Stop providing "hkey" addition to license (elastic/x-pack-elasticsearch#4131)
This stops providing the "hkey" (hash) of the license now that the Monitoring UI no longer uses it (6.3+). Original commit: elastic/x-pack-elasticsearch@235402f
1 parent 91401fc commit 485a42d

File tree

3 files changed

+1
-52
lines changed

3 files changed

+1
-52
lines changed

plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.cluster.node.DiscoveryNodes;
1313
import org.elasticsearch.common.Nullable;
1414
import org.elasticsearch.common.collect.MapBuilder;
15-
import org.elasticsearch.common.hash.MessageDigests;
1615
import org.elasticsearch.common.xcontent.ToXContent;
1716
import org.elasticsearch.common.xcontent.XContentBuilder;
1817
import org.elasticsearch.license.License;
@@ -21,7 +20,6 @@
2120
import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
2221

2322
import java.io.IOException;
24-
import java.nio.charset.StandardCharsets;
2523
import java.util.Collections;
2624
import java.util.List;
2725
import java.util.Locale;
@@ -133,7 +131,6 @@ protected void innerToXContent(XContentBuilder builder, Params params) throws IO
133131
.map();
134132
params = new ToXContent.DelegatingMapParams(extraParams, params);
135133
license.toInnerXContent(builder, params);
136-
builder.field("hkey", hash(license, getCluster()));
137134
if (clusterNeedsTLSEnabled) {
138135
builder.field("cluster_needs_tls", true);
139136
}
@@ -197,12 +194,4 @@ public static int nodesHash(final DiscoveryNodes nodes) {
197194
return temp.toString().hashCode();
198195
}
199196

200-
public static String hash(License license, String clusterName) {
201-
return hash(license.status().label(), license.uid(), license.type(), String.valueOf(license.expiryDate()), clusterName);
202-
}
203-
204-
public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) {
205-
String toHash = licenseStatus + licenseUid + licenseType + licenseExpiryDate + clusterUUID;
206-
return MessageDigests.toHexString(MessageDigests.sha256().digest(toHash.getBytes(StandardCharsets.UTF_8)));
207-
}
208197
}

plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.cluster.routing.ShardRouting;
2323
import org.elasticsearch.cluster.routing.UnassignedInfo;
2424
import org.elasticsearch.common.bytes.BytesReference;
25-
import org.elasticsearch.common.hash.MessageDigests;
2625
import org.elasticsearch.common.network.NetworkModule;
2726
import org.elasticsearch.common.settings.Settings;
2827
import org.elasticsearch.common.transport.BoundTransportAddress;
@@ -51,7 +50,6 @@
5150
import org.junit.Before;
5251

5352
import java.io.IOException;
54-
import java.nio.charset.StandardCharsets;
5553
import java.util.Collections;
5654
import java.util.List;
5755
import java.util.Map;
@@ -188,38 +186,6 @@ public void testNodesHash() {
188186
assertThat(ClusterStatsMonitoringDoc.nodesHash(nodes), equalTo(ephemeralIds.toString().hashCode()));
189187
}
190188

191-
public void testHash() {
192-
assertEquals("cc6628dbcfd052fba57870dc4eed4bc9f5cd5d43b4df46e97867aeb2dd7bd2e8",
193-
ClusterStatsMonitoringDoc.hash("licenseStatus", "licenseUid", "licenseType", "licenseExpiryDate", "clusterUUID"));
194-
}
195-
196-
public void testHashWithLicense() {
197-
final StringBuilder builder = new StringBuilder();
198-
199-
final License license = mock(License.class);
200-
final License.Status status = randomFrom(License.Status.values());
201-
when(license.status()).thenReturn(status);
202-
builder.append(status.label());
203-
204-
final String uuid = randomAlphaOfLength(10);
205-
when(license.uid()).thenReturn(uuid);
206-
builder.append(uuid);
207-
208-
final String type = randomAlphaOfLength(10);
209-
when(license.type()).thenReturn(type);
210-
builder.append(type);
211-
212-
final long expiryDate = randomNonNegativeLong();
213-
when(license.expiryDate()).thenReturn(expiryDate);
214-
builder.append(String.valueOf(expiryDate));
215-
216-
final String cluster = randomAlphaOfLength(5);
217-
builder.append(cluster);
218-
219-
assertEquals(MessageDigests.toHexString(MessageDigests.sha256().digest(builder.toString().getBytes(StandardCharsets.UTF_8))),
220-
ClusterStatsMonitoringDoc.hash(license, cluster));
221-
}
222-
223189
@Override
224190
public void testToXContent() throws IOException {
225191
final ClusterName clusterName = new ClusterName("_cluster_name");
@@ -380,8 +346,7 @@ public void testToXContent() throws IOException {
380346
+ "\"max_nodes\":2,"
381347
+ "\"issued_to\":\"customer\","
382348
+ "\"issuer\":\"elasticsearch\","
383-
+ "\"start_date_in_millis\":-1,"
384-
+ "\"hkey\":\"e05627254d639cf36346bf99934dc4a4ac9f37bdc9100cee450c10fa6322a6dd\""
349+
+ "\"start_date_in_millis\":-1"
385350
+ (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "")
386351
+ "},"
387352
+ "\"cluster_stats\":{"

plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
6666
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
6767
import static org.elasticsearch.threadpool.ThreadPool.Names.BULK;
68-
import static org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStatsMonitoringDoc.hash;
6968
import static org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.TEMPLATE_VERSION;
7069
import static org.hamcrest.Matchers.containsString;
7170
import static org.hamcrest.Matchers.equalTo;
@@ -336,10 +335,6 @@ private void assertClusterStatsMonitoringDoc(final Map<String, Object> document,
336335
Boolean clusterNeedsTLS = (Boolean) license.get("cluster_needs_tls");
337336
assertThat(clusterNeedsTLS, isOneOf(true, null));
338337

339-
// We basically recompute the hash here
340-
assertThat("Hash key should be the same",
341-
license.get("hkey"), equalTo(hash(status, uid, type, String.valueOf(expiryDate), (String) source.get("cluster_uuid"))));
342-
343338
final Map<String, Object> clusterStats = (Map<String, Object>) source.get("cluster_stats");
344339
assertThat(clusterStats, notNullValue());
345340
assertThat(clusterStats.size(), equalTo(4));

0 commit comments

Comments
 (0)