-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
api: Expose mesh status #644
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import ( | |
"github.com/prometheus/alertmanager/silence" | ||
"github.com/prometheus/alertmanager/silence/silencepb" | ||
"github.com/prometheus/alertmanager/types" | ||
"github.com/weaveworks/mesh" | ||
) | ||
|
||
var ( | ||
|
@@ -77,6 +78,7 @@ type API struct { | |
configJSON config.Config | ||
resolveTimeout time.Duration | ||
uptime time.Time | ||
mrouter *mesh.Router | ||
|
||
groups func() dispatch.AlertOverview | ||
|
||
|
@@ -86,13 +88,14 @@ type API struct { | |
} | ||
|
||
// New returns a new API. | ||
func New(alerts provider.Alerts, silences *silence.Silences, gf func() dispatch.AlertOverview) *API { | ||
func New(alerts provider.Alerts, silences *silence.Silences, gf func() dispatch.AlertOverview, router *mesh.Router) *API { | ||
return &API{ | ||
context: route.Context, | ||
alerts: alerts, | ||
silences: silences, | ||
groups: gf, | ||
uptime: time.Now(), | ||
mrouter: router, | ||
} | ||
} | ||
|
||
|
@@ -165,10 +168,11 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) { | |
api.mtx.RLock() | ||
|
||
var status = struct { | ||
Config string `json:"config"` | ||
ConfigJSON config.Config `json:"configJSON"` | ||
VersionInfo map[string]string `json:"versionInfo"` | ||
Uptime time.Time `json:"uptime"` | ||
Config string `json:"config"` | ||
ConfigJSON config.Config `json:"configJSON"` | ||
VersionInfo map[string]string `json:"versionInfo"` | ||
Uptime time.Time `json:"uptime"` | ||
MeshStatus strippedDownMeshStatus `json:"meshStatus"` | ||
}{ | ||
Config: api.config, | ||
ConfigJSON: api.configJSON, | ||
|
@@ -180,14 +184,40 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) { | |
"buildDate": version.BuildDate, | ||
"goVersion": version.GoVersion, | ||
}, | ||
Uptime: api.uptime, | ||
Uptime: api.uptime, | ||
MeshStatus: getStrippedDownMeshStatus(api), | ||
} | ||
|
||
api.mtx.RUnlock() | ||
|
||
respond(w, status) | ||
} | ||
|
||
type strippedDownMeshStatus struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here: |
||
Connections []strippedDownLocalConnectionStatus `json:"connections"` | ||
} | ||
|
||
type strippedDownLocalConnectionStatus struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here: |
||
Address string `json:"address"` | ||
State string `json:"state"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe describe in a comment what |
||
} | ||
|
||
func getStrippedDownMeshStatus(api *API) strippedDownMeshStatus { | ||
status := mesh.NewStatus(api.mrouter) | ||
strippedStatus := strippedDownMeshStatus{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically same here s := mesh.NewStatus(api.mrouter)
status := meshStatus{
...
} |
||
Connections: make([]strippedDownLocalConnectionStatus, len(status.Connections)), | ||
} | ||
|
||
for i := 0; i < len(status.Connections); i++ { | ||
strippedStatus.Connections[i] = strippedDownLocalConnectionStatus{ | ||
Address: status.Connections[i].Address, | ||
State: status.Connections[i].State, | ||
} | ||
} | ||
|
||
return strippedStatus | ||
} | ||
|
||
func (api *API) alertGroups(w http.ResponseWriter, req *http.Request) { | ||
respond(w, api.groups()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove the
getStrippedDown
...meshStatus
is perfect :)