diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2020-02-18 11:08:58 +0100 |
---|---|---|
committer | Ola Aunrønning <olaa@verizonmedia.com> | 2020-02-20 11:09:59 +0100 |
commit | 53e7bf587a974dd538b47fd87d0d578bcb18346b (patch) | |
tree | 27460638c0982487e733fd14e79bf9be48d5d706 /metrics-proxy | |
parent | 20e49ef934d2043b816f7a7547de017ef096ca74 (diff) |
Load template using ClasspathResourceLoader. Renamed template
Diffstat (limited to 'metrics-proxy')
-rw-r--r-- | metrics-proxy/src/main/java/ai/vespa/metricsproxy/telegraf/Telegraf.java | 16 | ||||
-rw-r--r-- | metrics-proxy/src/main/resources/templates/telegraf.conf.vm (renamed from metrics-proxy/src/main/resources/templates/cloudwatch_plugin.vm) | 0 |
2 files changed, 12 insertions, 4 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/telegraf/Telegraf.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/telegraf/Telegraf.java index 24f24fbfef0..17ac0c8e9db 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/telegraf/Telegraf.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/telegraf/Telegraf.java @@ -7,6 +7,8 @@ import com.yahoo.system.execution.ProcessExecutor; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; import java.io.FileWriter; import java.io.Writer; @@ -19,7 +21,7 @@ import static com.yahoo.yolean.Exceptions.uncheck; public class Telegraf extends AbstractComponent { private static final String TELEGRAF_CONFIG_PATH = "/etc/telegraf/telegraf.conf"; - private static final String TELEGRAF_CONFIG_TEMPLATE_PATH = "src/main/resources/templates/cloudwatch_plugin.vm"; + private static final String TELEGRAF_CONFIG_TEMPLATE_PATH = "templates/telegraf.conf.vm"; private final TelegrafRegistry telegrafRegistry; @Inject @@ -31,9 +33,7 @@ public class Telegraf extends AbstractComponent { } protected static void writeConfig(TelegrafConfig telegrafConfig, Writer writer) { - VelocityEngine velocityEngine = new VelocityEngine(); - velocityEngine.init(); - Template template = velocityEngine.getTemplate(TELEGRAF_CONFIG_TEMPLATE_PATH); + Template template = loadTemplate(); VelocityContext context = new VelocityContext(); context.put("intervalSeconds", telegrafConfig.intervalSeconds()); context.put("vespaConsumer", telegrafConfig.vespa().consumer()); @@ -61,6 +61,14 @@ public class Telegraf extends AbstractComponent { .orElseThrow(() -> new RuntimeException("Timed out running command: " + command)); } + private static Template loadTemplate() { + VelocityEngine velocityEngine = new VelocityEngine(); + velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + velocityEngine.init(); + return velocityEngine.getTemplate(TELEGRAF_CONFIG_TEMPLATE_PATH); + } + @Override public void deconstruct() { telegrafRegistry.removeInstance(this); diff --git a/metrics-proxy/src/main/resources/templates/cloudwatch_plugin.vm b/metrics-proxy/src/main/resources/templates/telegraf.conf.vm index 45c87a78ebf..45c87a78ebf 100644 --- a/metrics-proxy/src/main/resources/templates/cloudwatch_plugin.vm +++ b/metrics-proxy/src/main/resources/templates/telegraf.conf.vm |