Provide stable config for agent/self (#3532)

* config: provide stable config for /v1/agent/self (#3530)

This patch adds a stable subset of the previous Config struct to the
agent/self response. The actual runtime configuration is moved into
DebugConfig and will be documented to change.

Fixes #3530

* config: fix tests

* doc: update api documentation for /v1/agent/self
This commit is contained in:
Frank Schröder 2017-10-04 19:43:17 +02:00 committed by James Phillips
parent 69a02f22a1
commit ce887a0c45
4 changed files with 38 additions and 47 deletions

View File

@ -20,7 +20,8 @@ import (
) )
type Self struct { type Self struct {
Config map[string]interface{} Config interface{}
DebugConfig map[string]interface{}
Coord *coordinate.Coordinate Coord *coordinate.Coordinate
Member serf.Member Member serf.Member
Stats map[string]map[string]string Stats map[string]map[string]string
@ -51,8 +52,22 @@ func (s *HTTPServer) AgentSelf(resp http.ResponseWriter, req *http.Request) (int
return nil, acl.ErrPermissionDenied return nil, acl.ErrPermissionDenied
} }
config := struct {
Datacenter string
NodeName string
Revision string
Server bool
Version string
}{
Datacenter: s.agent.config.Datacenter,
NodeName: s.agent.config.NodeName,
Revision: s.agent.config.Revision,
Server: s.agent.config.ServerMode,
Version: s.agent.config.Version,
}
return Self{ return Self{
Config: s.agent.config.Sanitized(), Config: config,
DebugConfig: s.agent.config.Sanitized(),
Coord: cs[s.agent.config.SegmentName], Coord: cs[s.agent.config.SegmentName],
Member: s.agent.LocalMember(), Member: s.agent.LocalMember(),
Stats: s.agent.Stats(), Stats: s.agent.Stats(),

View File

@ -189,7 +189,7 @@ func TestAgent_Self(t *testing.T) {
t.Fatalf("incorrect port: %v", obj) t.Fatalf("incorrect port: %v", obj)
} }
if val.Config["SerfPortLAN"].(int) != a.Config.SerfPortLAN { if val.DebugConfig["SerfPortLAN"].(int) != a.Config.SerfPortLAN {
t.Fatalf("incorrect port: %v", obj) t.Fatalf("incorrect port: %v", obj)
} }

View File

@ -638,7 +638,7 @@ func TestAPI_AgentJoin(t *testing.T) {
} }
// Join ourself // Join ourself
addr := info["Config"]["SerfAdvertiseAddrLAN"].(string) addr := info["DebugConfig"]["SerfAdvertiseAddrLAN"].(string)
// strip off 'tcp://' // strip off 'tcp://'
addr = addr[len("tcp://"):] addr = addr[len("tcp://"):]
err = agent.Join(addr, false) err = agent.Join(addr, false)

View File

@ -85,7 +85,10 @@ $ curl \
## Read Configuration ## Read Configuration
This endpoint returns the configuration and member information of the local This endpoint returns the configuration and member information of the local
agent. agent. The `Config` element contains a subset of the configuration and its
format will not change in a backwards incompatible way between releases.
`DebugConfig` contains the full runtime configuration but its format is subject
to change without notice or deprecation.
| Method | Path | Produces | | Method | Path | Produces |
| ------ | ---------------------------- | -------------------------- | | ------ | ---------------------------- | -------------------------- |
@ -112,42 +115,15 @@ $ curl \
```json ```json
{ {
"Config": { "Config": {
"Bootstrap": true,
"Server": true,
"Datacenter": "dc1", "Datacenter": "dc1",
"DataDir": "/tmp/consul",
"DNSRecursor": "",
"DNSRecursors": [],
"Domain": "consul.",
"LogLevel": "INFO",
"NodeID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"NodeName": "foobar", "NodeName": "foobar",
"ClientAddr": "127.0.0.1", "Server": true,
"BindAddr": "0.0.0.0", "Revision": "deadbeef",
"AdvertiseAddr": "10.1.10.12", "Version": "1.0.0"
"Ports": {
"DNS": 8600,
"HTTP": 8500,
"RPC": 8400,
"SerfLan": 8301,
"SerfWan": 8302,
"Server": 8300
}, },
"LeaveOnTerm": false, "DebugConfig": {
"SkipLeaveOnInt": false, ... full runtime configuration ...
"StatsiteAddr": "", ... format subject to change ...
"Protocol": 1,
"EnableDebug": false,
"VerifyIncoming": false,
"VerifyOutgoing": false,
"CAFile": "",
"CertFile": "",
"KeyFile": "",
"StartJoin": [],
"UiDir": "",
"PidFile": "",
"EnableSyslog": false,
"RejoinAfterLeave": false
}, },
"Coord": { "Coord": {
"Adjustment": 0, "Adjustment": 0,