From 65c27896ffeb16edf9dbfddbc6893a92e4ee9c2e Mon Sep 17 00:00:00 2001 From: David Heryanto Date: Wed, 29 Apr 2020 21:51:14 +0800 Subject: [PATCH] Fix config validation for feast.jobs.metrics.host (#662) * Update config validation for feast.jobs.metrics.host `host` will be used as the parameter to connect to a metrics server e.g StatsD Server. It's not a URL but rather an IP address or hostname. For example StatsD UDP server expects a DNS hostname or IP address and not a URL such as http://10.23.40.1. The UDP server does not understand http application layer protocol. * Typo in error message --- .../feast/core/config/FeastProperties.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/feast/core/config/FeastProperties.java b/core/src/main/java/feast/core/config/FeastProperties.java index 941d51f68c..eb50728baf 100644 --- a/core/src/main/java/feast/core/config/FeastProperties.java +++ b/core/src/main/java/feast/core/config/FeastProperties.java @@ -18,6 +18,8 @@ import feast.core.config.FeastProperties.StreamProperties.FeatureStreamOptions; import feast.core.validators.OneOfStrings; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.*; import javax.annotation.PostConstruct; import javax.validation.*; @@ -26,7 +28,6 @@ import javax.validation.constraints.Positive; import lombok.Getter; import lombok.Setter; -import org.hibernate.validator.constraints.URL; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.info.BuildProperties; @@ -91,6 +92,7 @@ public Runner getActiveRunner() { @Getter @Setter public static class Runner { + /** Job runner name. This must be unique. */ String name; @@ -173,7 +175,7 @@ public static class MetricsProperties { private String type; /* Host of metric sink */ - @URL private String host; + private String host; /* Port of metric sink */ @Positive private int port; @@ -221,6 +223,18 @@ public void validate() { if (!jobMetricViolations.isEmpty()) { throw new ConstraintViolationException(jobMetricViolations); } + // Additional custom check for hostname value because there is no built-in Spring annotation + // to validate the value is a DNS resolvable hostname or an IP address. + try { + //noinspection ResultOfMethodCallIgnored + InetAddress.getByName(getJobs().getMetrics().getHost()); + } catch (UnknownHostException e) { + throw new IllegalArgumentException( + "Invalid config value for feast.jobs.metrics.host: " + + getJobs().getMetrics().getHost() + + ". Make sure it is a valid IP address or DNS hostname e.g. localhost or 10.128.10.40. Error detail: " + + e.getMessage()); + } } } }