Hi,
I’m quite new to consul, but trying to get into it. While playing around with services and changes on time with consul-template, we try to use added meta data to the service. The key/value pairs are correctly viewable within the service catalog details, but even with the easiest way to access the meta data an error is thrown:
2023/02/20 17:35:36.135590 [ERR] (cli) /tmp/test.tpl: execute: template: :4:42: executing "" at <.ServiceMeta>: can't evaluate field ServiceMeta in type *dependency.HealthService
The ctmpl is as easy as it can be:
{{- range services }}
# {{- .Name }}
{{- range service .Name }}
{{ .Node }} - {{ .Port }} - {{ index .ServiceMeta "serviceUrl" }}
{{- end }}
{{- end }}
It makes perfect sense that this template would error, as it is written to depend on every service registered in Consul having serviceUrl in the metadata - and they won’t all have that, as consul itself does not.
Thank you very much for your kind reply, it makes absolut sense, yes … but:
Even if I limit the result set to those services containing the ServiceMeta stuff, I get the error.
I added
{{- $allowedTags := parseJSON `["myservice","expose"]` -}}
{{ range services }}
{{- if (containsAny $allowedTags .Tags) }}
{{ range service .Name }}
to get only the service(s) containing ServiceMeta entries but still get the same error message.
Hi maxb, thanks again for your kind reply. It seems, even from the error message, that the whole map “ServiceMeta” is not “accessable”, although I can see the entries within the json when calling the consul service catalog details.
0
ID
959ea52f-7a5f-2146-935f-eb514c6fc904
Node
at-vie-1-node01
Address
10.0.55.40
Datacenter
at-vie-1-dev01
…
ServiceMeta
—
—
external-source
nomad
servicePath
/
serviceUrl
proxy-test
ServicePort
80
…
When trying the same stuff with .NodeMeta, everything is working fine (but not feasable for our requirements here)
I have to apologize for all the time you’ve spent … we just found that for some reason on the dev node a VERY old version (0.19.5) of consul-table was installed So, .ServiceMeta was not yet implemented. So sorry for that!