hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.26k stars 4.41k forks source link

`-meta` CLI argument does not seem to work while registering a service #19572

Open thomaslepoix opened 10 months ago

thomaslepoix commented 10 months ago

Overview of the Issue

Declaring a service metadata field through a service file (HCL or JSON) works fine, but I didn't manage to declare the same metadata field through the -meta CLI flag.


Reproduction Steps

cat svc.hcl
service = {
  name = "svc"
  id = "svc1"
  port = 5555
  meta = { foo = "bar" }
}

consul services register svc.hcl

curl http://127.0.0.1:8500/v1/catalog/node/node1 2>/dev/null | jq '.Services.svc1.Meta'
{
  "foo": "bar"
}

vs.

cat svc.hcl
service = {
  name = "svc"
  id = "svc1"
  port = 5555
}

consul services register -meta=foo=bar svc.hcl

curl http://127.0.0.1:8500/v1/catalog/node/node1 2>/dev/null | jq '.Services.svc1.Meta'
null

Consul info for both Client and Server

Client info ``` Output from client 'consul info' command here agent: check_monitors = 0 check_ttls = 0 checks = 5 services = 5 build: prerelease = revision = version = 1.16.1 version_metadata = consul: acl = enabled known_servers = 1 server = false runtime: arch = amd64 cpu_count = 3 goroutines = 130 max_procs = 3 os = linux version = go1.20.7 serf_lan: coordinate_resets = 0 encrypted = true event_queue = 0 event_time = 3 failed = 0 health_score = 0 intent_queue = 0 left = 0 member_time = 4 members = 2 query_queue = 0 query_time = 1 ``` ```json Client agent JSON config { "acl": { "default_policy": "allow", "enable_token_persistence": true, "enabled": true }, "advertise_addr": "192.168.240.12", "auto_encrypt": { "tls": true }, "bind_addr": "192.168.240.12", "client_addr": "0.0.0.0", "data_dir": "/var/lib/consul", "datacenter": "dc1", "ports": { "grpc": 8502, "grpc_tls": 8503, "https": 8501 }, "retry_join": [ "192.168.240.11" ], "tls": { "defaults": { "ca_file": "/var/run/secrets/certs/consul-agent-ca.pem", "verify_incoming": true, "verify_outgoing": true }, "grpc": { "verify_incoming": false }, "https": { "verify_incoming": false } }, "ui_config": { "enabled": true }, "encrypt": "#########################" } ```
Server info ``` Output from server 'consul info' command here agent: check_monitors = 0 check_ttls = 0 checks = 6 services = 7 build: prerelease = revision = version = 1.16.1 version_metadata = consul: acl = enabled bootstrap = true known_datacenters = 1 leader = true leader_addr = 192.168.240.11:8300 server = true raft: applied_index = 6173 commit_index = 6173 fsm_pending = 0 last_contact = 0 last_log_index = 6173 last_log_term = 3 last_snapshot_index = 0 last_snapshot_term = 0 latest_configuration = [{Suffrage:Voter ID:##################### Address:192.168.240.11:8300}] latest_configuration_index = 0 num_peers = 0 protocol_version = 3 protocol_version_max = 3 protocol_version_min = 0 snapshot_version_max = 1 snapshot_version_min = 0 state = Leader term = 3 runtime: arch = amd64 cpu_count = 3 goroutines = 262 max_procs = 3 os = linux version = go1.20.7 serf_lan: coordinate_resets = 0 encrypted = true event_queue = 0 event_time = 3 failed = 0 health_score = 0 intent_queue = 0 left = 0 member_time = 4 members = 2 query_queue = 0 query_time = 1 serf_wan: coordinate_resets = 0 encrypted = true event_queue = 0 event_time = 1 failed = 0 health_score = 0 intent_queue = 0 left = 0 member_time = 1 members = 1 query_queue = 0 query_time = 1 ``` ```json Server agent JSON config { "acl": { "default_policy": "allow", "enable_token_persistence": true, "enabled": true "tokens": { "initial_management": "#######################" } }, "advertise_addr": "192.168.240.11", "auto_encrypt": { "allow_tls": true }, "bind_addr": "192.168.240.11", "bootstrap_expect": 1, "client_addr": "0.0.0.0", "connect": { "enabled": true }, "data_dir": "/var/lib/consul", "datacenter": "dc1", "domain": "##########", "ports": { "grpc": 8502, "grpc_tls": 8503, "https": 8501 }, "server": true, "tls": { "defaults": { "ca_file": "/run/secrets/certs/consul-agent-ca.pem", "cert_file": "/run/secrets/certs/dc1-server-consul-0.pem", "key_file": "/run/secrets/certs/dc1-server-consul-0-key.pem", "verify_incoming": true, "verify_outgoing": true }, "grpc": { "verify_incoming": false }, "https": { "verify_incoming": false } }, "ui_config": { "enabled": true }, "encrypt": "#########################" } ```

Operating system and Environment details

NixOS 23.05, x86_64 Libvirt/KVM virtual machine

Log Fragments

vijayraghav-io commented 10 months ago

Should be fixed by https://github.com/hashicorp/consul/issues/19572

FYI @thomaslepoix @huikang

thomaslepoix commented 10 months ago

I tried your patch and can confirm it solves it in my use case. Thank you !

I'll let the merge of the PR close this issue.

vijayraghav-io commented 10 months ago

Thank you! @thomaslepoix for confirming.