mirror of
https://github.com/TwiN/gatus.git
synced 2025-01-03 12:39:39 +01:00
Remove uptime from /api/v1/services/{key}/statuses and return the entire service status instead of a map
This commit is contained in:
parent
c61b406483
commit
becc17202b
@ -154,23 +154,7 @@ func serviceStatusHandler(writer http.ResponseWriter, r *http.Request) {
|
|||||||
_, _ = writer.Write([]byte("not found"))
|
_, _ = writer.Write([]byte("not found"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uptime7Days, _ := storage.Get().GetUptimeByKey(vars["key"], time.Now().Add(-24*7*time.Hour), time.Now())
|
output, err := json.Marshal(serviceStatus)
|
||||||
uptime24Hours, _ := storage.Get().GetUptimeByKey(vars["key"], time.Now().Add(-24*time.Hour), time.Now())
|
|
||||||
uptime1Hour, _ := storage.Get().GetUptimeByKey(vars["key"], time.Now().Add(-time.Hour), time.Now())
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"serviceStatus": serviceStatus,
|
|
||||||
// The following fields, while present on core.ServiceStatus, are annotated to remain hidden so that we can
|
|
||||||
// expose only the necessary data on /api/v1/statuses.
|
|
||||||
// Since the /api/v1/statuses/{key} endpoint does need this data, however, we explicitly expose it here
|
|
||||||
"events": serviceStatus.Events,
|
|
||||||
// TODO: remove this in v3.0.0. Not used by front-end, only used for API. Left here for v2.x.x backward compatibility
|
|
||||||
"uptime": map[string]float64{
|
|
||||||
"7d": uptime7Days,
|
|
||||||
"24h": uptime24Hours,
|
|
||||||
"1h": uptime1Hour,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
output, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[controller][serviceStatusHandler] Unable to marshal object to JSON: %s", err.Error())
|
log.Printf("[controller][serviceStatusHandler] Unable to marshal object to JSON: %s", err.Error())
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@ -15,21 +15,13 @@ type ServiceStatus struct {
|
|||||||
Results []*Result `json:"results"`
|
Results []*Result `json:"results"`
|
||||||
|
|
||||||
// Events is a list of events
|
// Events is a list of events
|
||||||
//
|
Events []*Event `json:"events"`
|
||||||
// We don't expose this through JSON, because the main dashboard doesn't need to have this data.
|
|
||||||
// However, the detailed service page does leverage this by including it to a map that will be
|
|
||||||
// marshalled alongside the ServiceStatus.
|
|
||||||
Events []*Event `json:"-"`
|
|
||||||
|
|
||||||
// Uptime information on the service's uptime
|
// Uptime information on the service's uptime
|
||||||
//
|
//
|
||||||
// We don't expose this through JSON, because the main dashboard doesn't need to have this data.
|
// Used by the memory store.
|
||||||
// However, the detailed service page does leverage this by including it to a map that will be
|
|
||||||
// marshalled alongside the ServiceStatus.
|
|
||||||
//
|
//
|
||||||
// TODO: Get rid of this in favor of using the new store.GetUptimeByKey.
|
// To retrieve the uptime between two time, use store.GetUptimeByKey.
|
||||||
// TODO: For memory, store the uptime in a different map? (is that possible, given that we need to persist it through gocache?)
|
|
||||||
// Deprecated
|
|
||||||
Uptime *Uptime `json:"-"`
|
Uptime *Uptime `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ export default {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (JSON.stringify(this.serviceStatus) !== JSON.stringify(data)) {
|
if (JSON.stringify(this.serviceStatus) !== JSON.stringify(data)) {
|
||||||
this.serviceStatus = data.serviceStatus;
|
this.serviceStatus = data;
|
||||||
this.uptime = data.uptime;
|
this.uptime = data.uptime;
|
||||||
let events = [];
|
let events = [];
|
||||||
for (let i = data.events.length - 1; i >= 0; i--) {
|
for (let i = data.events.length - 1; i >= 0; i--) {
|
||||||
|
Loading…
Reference in New Issue
Block a user