Consul: All values in "Stats" section of /agent/self output are encoded as strings

Created on 15 Apr 2018  路  5Comments  路  Source: hashicorp/consul

Description of the Issue (and unexpected/desired result)

For example, this is what you get in Stats.consul subsection:

{
  "bootstrap": "false",
  "known_datacenters": "2",
  "leader": "false",
  "leader_addr": "10.37.3.181:8300",
  "server": "true"
}

When it clearly should be this:

{
  "bootstrap": false,
  "known_datacenters": 2,
  "leader": false,
  "leader_addr": "10.37.3.181:8300",
  "server": true
}

Reproduction steps

An HTTP GET request to the /agent/self API endpoint

consul version for both Client and Server

Client: N/A
Server: Consul v1.0.6

consul info for both Client and Server

Client: N/A
Server:

agent:
        check_monitors = 0
        check_ttls = 0
        checks = 0
        services = 0
build:
        prerelease =
        revision = 9a494b5f
        version = 1.0.6
consul:
        bootstrap = false
        known_datacenters = 2
        leader = false
        leader_addr = 10.37.3.181:8300
        server = true
raft:
        applied_index = 650855
        commit_index = 650855
        fsm_pending = 0
        last_contact = 22.528594ms
        last_log_index = 650855
        last_log_term = 15
        last_snapshot_index = 647204
        last_snapshot_term = 15
        latest_configuration = [{Suffrage:Voter ID:8e9baf45-e2e2-bea6-81f7-ecb3975048cc Address:10.37.3.180:8300} {Suffrage:Voter ID:241ab375-a605-3500-6663-af323d9eccda Address:10.37.3.181:8300} {Suffrage:Voter ID:a8d44039-7733-e59f-8b2c-700b67e67489 Address:10.37.3.182:8300}]
        latest_configuration_index = 592862
        num_peers = 2
        protocol_version = 3
        protocol_version_max = 3
        protocol_version_min = 0
        snapshot_version_max = 1
        snapshot_version_min = 0
        state = Follower
        term = 15
runtime:
        arch = amd64
        cpu_count = 8
        goroutines = 174
        max_procs = 8
        os = linux
        version = go1.9.3
serf_lan:
        coordinate_resets = 0
        encrypted = false
        event_queue = 0
        event_time = 422
        failed = 0
        health_score = 0
        intent_queue = 0
        left = 0
        member_time = 1265
        members = 6
        query_queue = 0
        query_time = 1
serf_wan:
        coordinate_resets = 0
        encrypted = false
        event_queue = 0
        event_time = 1
        failed = 0
        health_score = 0
        intent_queue = 0
        left = 0
        member_time = 60
        members = 6
        query_queue = 0
        query_time = 1

Operating system and Environment details

CentOS 7.4.1708

themapi typbug

Most helpful comment

Maybe another endpoint with correct JSON output should be introduced to avoid breaking changes? (still sound hacky to me though)

All 5 comments

Is there any reason behind exporting Stats as map[string]map[string]string?

Any progress on this? It blocks me too.

Hi there. We've made patch, that fixes problem with encoding all Stats fields as strings. But actually it's quite big and depends on changing code in vendored projects: raft and serf. For me this patch looks as quite big breaking change but anyway it addresses problem that should be fixed somehow. Is it feasible to get this changes landed step by step in raft and serf repos? Would be great to have any feedback on it. Thanks.
0001-Fix-Stats-format-preserve-orignial-types-instead-str.patch.zip

Maybe another endpoint with correct JSON output should be introduced to avoid breaking changes? (still sound hacky to me though)

@boogie-byte is on the right track here that it is a trade-off to maintain compatibility and do the "right thing" here which is to return the appropriate type, which these APIs are not. I'm going to tag this as a longer term API cleanup issue -- likely not something we'll be able to do against the v1 APIs given the relative improvement this would make.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

satheeshCharles picture satheeshCharles  路  3Comments

sandstrom picture sandstrom  路  3Comments

achille-roussel picture achille-roussel  路  4Comments

wargamez picture wargamez  路  4Comments

eshujiushiwo picture eshujiushiwo  路  3Comments