[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@235402fa92
This commit is contained in:
parent
91401fcb83
commit
485a42dc6a
|
@ -12,7 +12,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.hash.MessageDigests;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.license.License;
|
||||
|
@ -21,7 +20,6 @@ import org.elasticsearch.xpack.core.monitoring.MonitoredSystem;
|
|||
import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -133,7 +131,6 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc {
|
|||
.map();
|
||||
params = new ToXContent.DelegatingMapParams(extraParams, params);
|
||||
license.toInnerXContent(builder, params);
|
||||
builder.field("hkey", hash(license, getCluster()));
|
||||
if (clusterNeedsTLSEnabled) {
|
||||
builder.field("cluster_needs_tls", true);
|
||||
}
|
||||
|
@ -197,12 +194,4 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc {
|
|||
return temp.toString().hashCode();
|
||||
}
|
||||
|
||||
public static String hash(License license, String clusterName) {
|
||||
return hash(license.status().label(), license.uid(), license.type(), String.valueOf(license.expiryDate()), clusterName);
|
||||
}
|
||||
|
||||
public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) {
|
||||
String toHash = licenseStatus + licenseUid + licenseType + licenseExpiryDate + clusterUUID;
|
||||
return MessageDigests.toHexString(MessageDigests.sha256().digest(toHash.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.hash.MessageDigests;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.BoundTransportAddress;
|
||||
|
@ -51,7 +50,6 @@ import org.elasticsearch.xpack.monitoring.exporter.BaseMonitoringDocTestCase;
|
|||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -188,38 +186,6 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
|
|||
assertThat(ClusterStatsMonitoringDoc.nodesHash(nodes), equalTo(ephemeralIds.toString().hashCode()));
|
||||
}
|
||||
|
||||
public void testHash() {
|
||||
assertEquals("cc6628dbcfd052fba57870dc4eed4bc9f5cd5d43b4df46e97867aeb2dd7bd2e8",
|
||||
ClusterStatsMonitoringDoc.hash("licenseStatus", "licenseUid", "licenseType", "licenseExpiryDate", "clusterUUID"));
|
||||
}
|
||||
|
||||
public void testHashWithLicense() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
final License license = mock(License.class);
|
||||
final License.Status status = randomFrom(License.Status.values());
|
||||
when(license.status()).thenReturn(status);
|
||||
builder.append(status.label());
|
||||
|
||||
final String uuid = randomAlphaOfLength(10);
|
||||
when(license.uid()).thenReturn(uuid);
|
||||
builder.append(uuid);
|
||||
|
||||
final String type = randomAlphaOfLength(10);
|
||||
when(license.type()).thenReturn(type);
|
||||
builder.append(type);
|
||||
|
||||
final long expiryDate = randomNonNegativeLong();
|
||||
when(license.expiryDate()).thenReturn(expiryDate);
|
||||
builder.append(String.valueOf(expiryDate));
|
||||
|
||||
final String cluster = randomAlphaOfLength(5);
|
||||
builder.append(cluster);
|
||||
|
||||
assertEquals(MessageDigests.toHexString(MessageDigests.sha256().digest(builder.toString().getBytes(StandardCharsets.UTF_8))),
|
||||
ClusterStatsMonitoringDoc.hash(license, cluster));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testToXContent() throws IOException {
|
||||
final ClusterName clusterName = new ClusterName("_cluster_name");
|
||||
|
@ -380,8 +346,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
|
|||
+ "\"max_nodes\":2,"
|
||||
+ "\"issued_to\":\"customer\","
|
||||
+ "\"issuer\":\"elasticsearch\","
|
||||
+ "\"start_date_in_millis\":-1,"
|
||||
+ "\"hkey\":\"e05627254d639cf36346bf99934dc4a4ac9f37bdc9100cee450c10fa6322a6dd\""
|
||||
+ "\"start_date_in_millis\":-1"
|
||||
+ (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "")
|
||||
+ "},"
|
||||
+ "\"cluster_stats\":{"
|
||||
|
|
|
@ -65,7 +65,6 @@ import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
|||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.threadpool.ThreadPool.Names.BULK;
|
||||
import static org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStatsMonitoringDoc.hash;
|
||||
import static org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.TEMPLATE_VERSION;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -336,10 +335,6 @@ public class MonitoringIT extends ESSingleNodeTestCase {
|
|||
Boolean clusterNeedsTLS = (Boolean) license.get("cluster_needs_tls");
|
||||
assertThat(clusterNeedsTLS, isOneOf(true, null));
|
||||
|
||||
// We basically recompute the hash here
|
||||
assertThat("Hash key should be the same",
|
||||
license.get("hkey"), equalTo(hash(status, uid, type, String.valueOf(expiryDate), (String) source.get("cluster_uuid"))));
|
||||
|
||||
final Map<String, Object> clusterStats = (Map<String, Object>) source.get("cluster_stats");
|
||||
assertThat(clusterStats, notNullValue());
|
||||
assertThat(clusterStats.size(), equalTo(4));
|
||||
|
|
Loading…
Reference in New Issue