2021-02-03 05:06:34 +01:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
2021-08-20 05:07:21 +02:00
|
|
|
"time"
|
|
|
|
|
2021-02-03 05:06:34 +01:00
|
|
|
"github.com/TwinProduction/gatus/core"
|
2021-08-13 03:54:23 +02:00
|
|
|
"github.com/TwinProduction/gatus/storage/store/common/paging"
|
2021-02-03 05:06:34 +01:00
|
|
|
"github.com/TwinProduction/gatus/storage/store/memory"
|
2021-09-11 00:00:04 +02:00
|
|
|
"github.com/TwinProduction/gatus/storage/store/sql"
|
2021-02-03 05:06:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Store is the interface that each stores should implement
|
|
|
|
type Store interface {
|
2021-07-15 04:26:51 +02:00
|
|
|
// GetAllServiceStatuses returns the JSON encoding of all monitored core.ServiceStatus
|
2021-02-25 04:41:36 +01:00
|
|
|
// with a subset of core.Result defined by the page and pageSize parameters
|
2021-09-11 00:00:04 +02:00
|
|
|
GetAllServiceStatuses(params *paging.ServiceStatusParams) ([]*core.ServiceStatus, error)
|
2021-02-03 05:06:34 +01:00
|
|
|
|
|
|
|
// GetServiceStatus returns the service status for a given service name in the given group
|
2021-09-11 00:00:04 +02:00
|
|
|
GetServiceStatus(groupName, serviceName string, params *paging.ServiceStatusParams) (*core.ServiceStatus, error)
|
2021-02-03 05:06:34 +01:00
|
|
|
|
|
|
|
// GetServiceStatusByKey returns the service status for a given key
|
2021-09-11 00:00:04 +02:00
|
|
|
GetServiceStatusByKey(key string, params *paging.ServiceStatusParams) (*core.ServiceStatus, error)
|
2021-02-03 05:06:34 +01:00
|
|
|
|
2021-08-13 03:54:23 +02:00
|
|
|
// GetUptimeByKey returns the uptime percentage during a time range
|
|
|
|
GetUptimeByKey(key string, from, to time.Time) (float64, error)
|
|
|
|
|
2021-08-21 16:59:09 +02:00
|
|
|
// GetAverageResponseTimeByKey returns the average response time in milliseconds (value) during a time range
|
|
|
|
GetAverageResponseTimeByKey(key string, from, to time.Time) (int, error)
|
|
|
|
|
2021-08-20 05:07:21 +02:00
|
|
|
// GetHourlyAverageResponseTimeByKey returns a map of hourly (key) average response time in milliseconds (value) during a time range
|
|
|
|
GetHourlyAverageResponseTimeByKey(key string, from, to time.Time) (map[int64]int, error)
|
|
|
|
|
2021-02-03 05:06:34 +01:00
|
|
|
// Insert adds the observed result for the specified service into the store
|
2021-09-11 00:00:04 +02:00
|
|
|
Insert(service *core.Service, result *core.Result) error
|
2021-02-03 05:06:34 +01:00
|
|
|
|
|
|
|
// DeleteAllServiceStatusesNotInKeys removes all ServiceStatus that are not within the keys provided
|
|
|
|
//
|
|
|
|
// Used to delete services that have been persisted but are no longer part of the configured services
|
|
|
|
DeleteAllServiceStatusesNotInKeys(keys []string) int
|
|
|
|
|
|
|
|
// Clear deletes everything from the store
|
|
|
|
Clear()
|
2021-02-06 02:45:28 +01:00
|
|
|
|
|
|
|
// Save persists the data if and where it needs to be persisted
|
|
|
|
Save() error
|
2021-07-16 04:07:30 +02:00
|
|
|
|
2021-09-11 00:00:04 +02:00
|
|
|
// Close terminates every connection and closes the store, if applicable.
|
2021-07-16 04:07:30 +02:00
|
|
|
// Should only be used before stopping the application.
|
|
|
|
Close()
|
2021-02-03 05:06:34 +01:00
|
|
|
}
|
|
|
|
|
2021-07-13 04:53:14 +02:00
|
|
|
// TODO: add method to check state of store (by keeping track of silent errors)
|
|
|
|
|
2021-02-03 05:06:34 +01:00
|
|
|
var (
|
|
|
|
// Validate interface implementation on compile
|
|
|
|
_ Store = (*memory.Store)(nil)
|
2021-09-11 00:00:04 +02:00
|
|
|
_ Store = (*sql.Store)(nil)
|
2021-02-03 05:06:34 +01:00
|
|
|
)
|