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

Ability to Use Prepared Query in Place of Service #1137

Open
selble opened this issue Sep 6, 2018 · 0 comments
Open

Ability to Use Prepared Query in Place of Service #1137

selble opened this issue Sep 6, 2018 · 0 comments

Comments

@selble
Copy link

selble commented Sep 6, 2018

Please note that the Consul Template issue tracker is reserved
for bug reports and enhancements. For general usage questions,
please use the Consul mailing list:

https://groups.google.com/forum/#!forum/consul-tool

Consul Template version

consul-template v0.18.5 (9902dd5)

Configuration

N/A
upstream exampleservice {
    least_conn;
    keepalive 16;

    #Attempt to fetch the exampleservice servers
    {{if service "exampleservice"}}
        {{range service "exampleservice"}}server {{.Address}}:8443;
    {{end}}
    {{else}} # upstream stanza must have a server directive
        server 127.0.0.1 down;
    {{end}}
}

Command

consul-template --template=/etc/templates/etc/nginx/virtual-servers/pws.conf:/etc/nginx/virtual-servers/pws.conf:systemctl reload nginx --template=/etc/templates/etc/nginx/locations/pws.conf:/etc/nginx/locations/pws.conf:systemctl reload nginx --template=/etc/templates/etc/nginx/upstreams/pws.conf:/etc/nginx/upstreams/pws.conf:systemctl reload nginx --wait=5s:10s

Debug output

N/A

Expected behavior

This is a feature request, so what I'd like to be able to do is something like this:

upstream exampleservice {
    least_conn;
    keepalive 16;

    #Attempt to fetch the exampleservice servers
    {{if query "exampleservice"}}
        {{range query "exampleservice"}}server {{.Address}}:8443;
    {{end}}
    {{else}} # upstream stanza must have a server directive
        server 127.0.0.1 down;
    {{end}}
}

Actual behavior

In the absence of using prepared queries, we are constrained to only having services within a given datacenter with the configuration as it exists. We could define a second section, with a hard coded backup:

upstream exampleservice {
    least_conn;
    keepalive 16;

    #Attempt to fetch the exampleservice servers
    {{if service "exampleservice"}}
        {{range service "exampleservice"}}server {{.Address}}:8443;
    {{end}}
    {{else}} # upstream stanza must have a server directive
        server 127.0.0.1 down;
    {{end}}

    #Attempt to fetch the backup exampleservice servers
    {{if service "exampleservice@guse4-poc"}}
        {{range service "exampleservice@guse4-poc"}}server {{.Address}}:8443 backup;
    {{end}}
    {{else}} # upstream stanza must have a server directive
        server 127.0.0.1 down;
    {{end}}
}

But that gets tricky to maintain, and query seems like the perfect solution for this, if it were an option to iterate over, as service is.

Steps to reproduce

N/A

References

Are there any other GitHub issues (open or closed) that should
be linked here? For example:
N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant