Skip to content

Commit

Permalink
SOLR-15019: Remove support for (unsecure) env variables until it's ne…
Browse files Browse the repository at this point in the history
…eded.
  • Loading branch information
sigram committed Apr 26, 2021
1 parent c7abf3f commit d79b19a
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ public interface AttributeFetcher {
*/
AttributeFetcher requestNodeSystemProperty(String name);

/**
* Request an environment variable on each node. To get the value use {@link AttributeValues#getEnvironmentVariable(Node, String)}
* @param name environment property name
*/
AttributeFetcher requestNodeEnvironmentVariable(String name);

/**
* Request a node metric from each node. To get the value use {@link AttributeValues#getNodeMetric(Node, NodeMetric)}
* @param metric metric to retrieve (see {@link NodeMetric})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public interface AttributeValues {
*/
Optional<String> getSystemProperty(Node node, String name);

/**
* For the given node: environment variable value
*/
Optional<String> getEnvironmentVariable(Node node, String name);

/**
* For the given node: metric identified by an instance of {@link NodeMetric}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ public AttributeFetcher requestNodeSystemProperty(String name) {
return this;
}

@Override
public AttributeFetcher requestNodeEnvironmentVariable(String name) {
requestedNodeSystemSnitchTags.add(getSystemEnvSnitchTag(name));
return this;
}

@Override
public AttributeFetcher requestNodeMetric(NodeMetric<?> metric) {
requestedNodeMetricSnitchTags.add(metric);
Expand Down Expand Up @@ -214,8 +208,4 @@ public static String getMetricSnitchTag(NodeMetric<?> metric) {
public static String getSystemPropertySnitchTag(String name) {
return ImplicitSnitch.SYSPROP + name;
}

public static String getSystemEnvSnitchTag(String name) {
return ImplicitSnitch.SYSENV + name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ public Optional<String> getSystemProperty(Node node, String name) {
return Optional.ofNullable(nodeToValue.get(node));
}

@Override
public Optional<String> getEnvironmentVariable(Node node, String name) {
Map<Node, String> nodeToValue = systemSnitchToNodeToValue.get(AttributeFetcherImpl.getSystemEnvSnitchTag(name));
if (nodeToValue == null) {
return Optional.empty();
}
return Optional.ofNullable(nodeToValue.get(node));
}

@Override
@SuppressWarnings("unchecked")
public <T> Optional<T> getNodeMetric(Node node, NodeMetric<T> metric) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public AttributeFetcher requestNodeSystemProperty(String name) {
return this;
}

@Override
public AttributeFetcher requestNodeEnvironmentVariable(String name) {
throw new UnsupportedOperationException("Not yet implemented...");
}

@Override
public AttributeFetcher requestNodeMetric(NodeMetric<?> metric) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,6 @@ public void testAttributeFetcherImpl() throws Exception {
AttributeFetcher attributeFetcher = new AttributeFetcherImpl(cloudManager);
NodeMetric<String> someMetricKey = new NodeMetricImpl<>("solr.jvm:system.properties:user.name");
String sysprop = "user.name";
Set<String> potentialEnvVars = Set.of("PWD", "TMPDIR", "TMP", "TEMP", "USER", "USERNAME", "HOME");

String envVar = null;
for (String env : potentialEnvVars) {
if (System.getenv(env) != null) {
envVar = env;
break;
}
}
if (envVar == null) {
fail("None of the potential env vars exist? " + potentialEnvVars);
}
attributeFetcher
.fetchFrom(cluster.getLiveNodes())
.requestNodeMetric(NodeMetricImpl.HEAP_USAGE)
Expand All @@ -382,11 +370,9 @@ public void testAttributeFetcherImpl() throws Exception {
.requestNodeMetric(NodeMetricImpl.AVAILABLE_PROCESSORS)
.requestNodeMetric(someMetricKey)
.requestNodeSystemProperty(sysprop)
.requestNodeEnvironmentVariable(envVar)
.requestCollectionMetrics(collection, Set.of(ReplicaMetricImpl.INDEX_SIZE_GB, ReplicaMetricImpl.QUERY_RATE_1MIN, ReplicaMetricImpl.UPDATE_RATE_1MIN));
AttributeValues attributeValues = attributeFetcher.fetchAttributes();
String userName = System.getProperty("user.name");
String envVarValue = System.getenv(envVar);
// node metrics
for (Node node : cluster.getLiveNodes()) {
Optional<Double> doubleOpt = attributeValues.getNodeMetric(node, NodeMetricImpl.HEAP_USAGE);
Expand All @@ -409,9 +395,6 @@ public void testAttributeFetcherImpl() throws Exception {
Optional<String> syspropOpt = attributeValues.getSystemProperty(node, sysprop);
assertTrue("sysprop", syspropOpt.isPresent());
assertEquals("user.name sysprop", userName, syspropOpt.get());
Optional<String> envVarOpt = attributeValues.getEnvironmentVariable(node, envVar);
assertTrue("envVar", envVarOpt.isPresent());
assertEquals("envVar " + envVar, envVarValue, envVarOpt.get());
}
assertTrue(attributeValues.getCollectionMetrics(COLLECTION).isPresent());
CollectionMetrics collectionMetrics = attributeValues.getCollectionMetrics(COLLECTION).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ protected void getRemoteInfo(String solrNode, Set<String> requestedTags, SnitchC
if (tag.startsWith(SYSPROP)) {
metricsKeyVsTag.computeIfAbsent("solr.jvm:system.properties:" + tag.substring(SYSPROP.length()), k -> new HashSet<>())
.add(tag);
} else if (tag.startsWith(SYSENV)) {
metricsKeyVsTag.computeIfAbsent("solr.jvm:system.env:" + tag.substring(SYSENV.length()), k -> new HashSet<>())
.add(tag);
} else if (tag.startsWith(METRICS_PREFIX)) {
metricsKeyVsTag.computeIfAbsent(tag.substring(METRICS_PREFIX.length()), k -> new HashSet<>())
.add(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class ImplicitSnitch extends Snitch {
public static final String ROLE = "role";
public static final String NODEROLE = "nodeRole";
public static final String SYSPROP = "sysprop.";
public static final String SYSENV = "sysenv.";
public static final String SYSLOADAVG = "sysLoadAvg";
public static final String HEAPUSAGE = "heapUsage";
public static final List<String> IP_SNITCHES = Collections.unmodifiableList(Arrays.asList("ip_1", "ip_2", "ip_3", "ip_4"));
Expand Down

0 comments on commit d79b19a

Please sign in to comment.