mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-24 00:44:09 +01:00
Support 30d Data from Raw Uptime Endpoint
Signed-off-by: James Hillyard <james.hillyard@payara.fish>
This commit is contained in:
parent
7d028f5a5f
commit
67f84da9b4
@ -14,6 +14,8 @@ func UptimeRaw(c *fiber.Ctx) error {
|
||||
duration := c.Params("duration")
|
||||
var from time.Time
|
||||
switch duration {
|
||||
case "30d":
|
||||
from = time.Now().Add(-30 * 24 * time.Hour)
|
||||
case "7d":
|
||||
from = time.Now().Add(-7 * 24 * time.Hour)
|
||||
case "24h":
|
||||
@ -21,7 +23,7 @@ func UptimeRaw(c *fiber.Ctx) error {
|
||||
case "1h":
|
||||
from = time.Now().Add(-2 * time.Hour) // Because uptime metrics are stored by hour, we have to cheat a little
|
||||
default:
|
||||
return c.Status(400).SendString("Durations supported: 7d, 24h, 1h")
|
||||
return c.Status(400).SendString("Durations supported: 30d,7d, 24h, 1h")
|
||||
}
|
||||
key := c.Params("key")
|
||||
uptime, err := store.Get().GetUptimeByKey(key, from, time.Now())
|
||||
@ -38,4 +40,4 @@ func UptimeRaw(c *fiber.Ctx) error {
|
||||
c.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
c.Set("Expires", "0")
|
||||
return c.Status(200).Send([]byte(fmt.Sprintf("%f", uptime)))
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,11 @@ func TestRawDataEndpoint(t *testing.T) {
|
||||
Path: "/api/v1/endpoints/core_frontend/uptimes/7d",
|
||||
ExpectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
Name: "raw-uptime-30d",
|
||||
Path: "/api/v1/endpoints/core_frontend/uptimes/30d",
|
||||
ExpectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
Name: "raw-uptime-with-invalid-duration",
|
||||
Path: "/api/v1/endpoints/core_backend/uptimes/3d",
|
||||
|
Loading…
Reference in New Issue
Block a user