Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template errors should not be fatal #1419

Closed
phemmer opened this issue Oct 28, 2020 · 3 comments · Fixed by #1420
Closed

Template errors should not be fatal #1419

phemmer opened this issue Oct 28, 2020 · 3 comments · Fixed by #1420
Milestone

Comments

@phemmer
Copy link
Contributor

phemmer commented Oct 28, 2020

Consul Template version

consul-template v0.25.1 (b11fa80)

Configuration

consul {
	address = "192.168.122.1:8500"
}
template {
	source = "/tmp/test.ctmpl"
	destination = "/tmp/test.out"
}
{{ key "mykey" | parseInt }}
123

Command

consul-template -config test.hcl

Debug output

2020/10/28 23:02:53.719058 [INFO] consul-template v0.25.1 (b11fa800)
2020/10/28 23:02:53.719072 [INFO] (runner) creating new runner (dry: false, once: false)
2020/10/28 23:02:53.719304 [DEBUG] (runner) final config: {"Consul":{"Address":"192.168.122.1:8500","Namespace":"","Auth":{"Enabled":false,"Username":"","Password":""},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":"","Transport":{"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":4,"TLSHandshakeTimeout":10000000000}},"Dedup":{"Enabled":false,"MaxStale":2000000000,"Prefix":"consul-template/dedup/","TTL":15000000000,"BlockQueryWaitTime":60000000000},"DefaultDelims":{"Left":null,"Right":null},"Exec":{"Command":"","Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":0},"KillSignal":2,"LogLevel":"trace","MaxStale":2000000000,"PidFile":"","ReloadSignal":1,"Syslog":{"Enabled":false,"Facility":"LOCAL0","Name":"consul-template"},"Templates":[{"Backup":false,"Command":"","CommandTimeout":30000000000,"Contents":"","CreateDestDirs":true,"Destination":"/tmp/test.out","ErrMissingKey":false,"Exec":{"Command":"","Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":30000000000},"Perms":0,"Source":"/tmp/test.ctmpl","Wait":{"Enabled":false,"Min":0,"Max":0},"LeftDelim":"","RightDelim":"","FunctionDenylist":[],"SandboxPath":""}],"Vault":{"Address":"http://192.168.122.1:8200","Enabled":true,"Namespace":"","RenewToken":false,"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":true,"Key":"","ServerName":"","Verify":true},"Transport":{"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":4,"TLSHandshakeTimeout":10000000000},"UnwrapToken":false},"Wait":{"Enabled":false,"Min":0,"Max":0},"Once":false,"BlockQueryWaitTime":60000000000}
2020/10/28 23:02:53.719352 [INFO] (runner) creating watcher
2020/10/28 23:02:53.719535 [INFO] (runner) starting
2020/10/28 23:02:53.719637 [DEBUG] (runner) running initial templates
2020/10/28 23:02:53.719665 [DEBUG] (runner) initiating run
2020/10/28 23:02:53.719693 [DEBUG] (runner) checking template dfe4ece652c1cad0a4fd3f9dd363a909
2020/10/28 23:02:53.720069 [DEBUG] (runner) missing data for 1 dependencies
2020/10/28 23:02:53.720102 [DEBUG] (runner) missing dependency: kv.block(mykey)
2020/10/28 23:02:53.720120 [DEBUG] (runner) add used dependency kv.block(mykey) to missing since isLeader but do not have a watcher
2020/10/28 23:02:53.720174 [DEBUG] (runner) was not watching 1 dependencies
2020/10/28 23:02:53.720196 [DEBUG] (watcher) adding kv.block(mykey)
2020/10/28 23:02:53.720245 [TRACE] (watcher) kv.block(mykey) starting
2020/10/28 23:02:53.720255 [DEBUG] (runner) diffing and updating dependencies
2020/10/28 23:02:53.720264 [DEBUG] (runner) watching 1 dependencies
2020/10/28 23:02:53.720311 [TRACE] (view) kv.block(mykey) starting fetch
2020/10/28 23:02:53.720334 [TRACE] kv.block(mykey): GET /v1/kv/mykey?stale=true&wait=1m0s
2020/10/28 23:02:53.721692 [TRACE] kv.block(mykey): returned "123"
2020/10/28 23:02:53.721716 [TRACE] (view) kv.block(mykey) marking successful data response
2020/10/28 23:02:53.721730 [TRACE] (view) kv.block(mykey) successful contact, resetting retries
2020/10/28 23:02:53.835671 [TRACE] (view) kv.block(mykey) received data
2020/10/28 23:02:53.835721 [TRACE] (view) kv.block(mykey) starting fetch
2020/10/28 23:02:53.835733 [DEBUG] (runner) receiving dependency kv.block(mykey)
2020/10/28 23:02:53.835741 [DEBUG] (runner) initiating run
2020/10/28 23:02:53.835749 [DEBUG] (runner) checking template dfe4ece652c1cad0a4fd3f9dd363a909
2020/10/28 23:02:53.835878 [TRACE] kv.block(mykey): GET /v1/kv/mykey?index=214686&stale=true&wait=1m0s
2020/10/28 23:02:53.835996 [DEBUG] (runner) rendering "/tmp/test.ctmpl" => "/tmp/test.out"
2020/10/28 23:02:53.836214 [DEBUG] (runner) diffing and updating dependencies
2020/10/28 23:02:53.836234 [DEBUG] (runner) kv.block(mykey) is still needed
2020/10/28 23:02:53.836244 [DEBUG] (runner) watching 1 dependencies
2020/10/28 23:02:53.836250 [DEBUG] (runner) all templates rendered
2020/10/28 23:02:59.619763 [TRACE] kv.block(mykey): returned "123abc"
2020/10/28 23:02:59.619800 [TRACE] (view) kv.block(mykey) marking successful data response
2020/10/28 23:02:59.619831 [TRACE] (view) kv.block(mykey) successful contact, resetting retries
2020/10/28 23:02:59.619839 [TRACE] (view) kv.block(mykey) received data
2020/10/28 23:02:59.619862 [TRACE] (view) kv.block(mykey) starting fetch
2020/10/28 23:02:59.619880 [TRACE] kv.block(mykey): GET /v1/kv/mykey?index=214688&stale=true&wait=1m0s
2020/10/28 23:02:59.620012 [DEBUG] (runner) receiving dependency kv.block(mykey)
2020/10/28 23:02:59.620027 [DEBUG] (runner) initiating run
2020/10/28 23:02:59.620032 [DEBUG] (runner) checking template dfe4ece652c1cad0a4fd3f9dd363a909
2020/10/28 23:02:59.620523 [ERR] (cli) /tmp/test.ctmpl: execute: template: :1:17: executing "" at <parseInt>: error calling parseInt: parseInt: strconv.ParseInt: parsing "123abc": invalid syntax

Expected behavior

Should log and error and continue.

Actual behavior

Exits with error message

Steps to reproduce

  1. Run with above config
  2. Change consul key from 123 to 123abc

References

Additional info

The documentation clearly states:

By default Consul Template is highly fault-tolerant. If Consul is unreachable or a template changes, Consul Template will happily continue running. The only exception to this rule is if the optional command exits non-zero. In this case, Consul Template will also exit non-zero.

In this case the optional command is not used, so consul-template should not exit. It should log an error and continue running.

This is especially problematic if consul-template is handling multiple templates. An error in a single template should not cause all other templates to stop rendering.

@eikenb
Copy link
Contributor

eikenb commented Oct 28, 2020

Related to #1289

@eikenb
Copy link
Contributor

eikenb commented Oct 28, 2020

Hey @phemmer, thanks for taking the time to file this ticket.

Related issue talks about adding an option to have it ignore template rendering errors and continue on running. I think that change would handle this as well. As adding a config option for this is a feature, I'm categorizing this as an enhancement request.

@phemmer
Copy link
Contributor Author

phemmer commented Oct 29, 2020

Thanks, I didn't see that other issue. I don't mind if you want to close this one as a dup. Though I think this one is more succinct and so might be easier for others to find.

@phemmer phemmer changed the title Template errors are fatal Template errors should not be fatal Oct 29, 2020
@eikenb eikenb added this to the v0.28.0 milestone Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants