Files
gatus/storage/store/store.go
T

58 lines
2.3 KiB
Go
Raw Normal View History

2021-02-02 23:06:34 -05:00
package store
import (
2021-08-19 23:07:21 -04:00
"time"
"github.com/TwiN/gatus/v3/core"
"github.com/TwiN/gatus/v3/storage/store/common/paging"
"github.com/TwiN/gatus/v3/storage/store/memory"
"github.com/TwiN/gatus/v3/storage/store/sql"
2021-02-02 23:06:34 -05:00
)
// Store is the interface that each stores should implement
type Store interface {
2021-10-23 16:47:12 -04:00
// GetAllEndpointStatuses returns the JSON encoding of all monitored core.EndpointStatus
// with a subset of core.Result defined by the page and pageSize parameters
2021-10-23 16:47:12 -04:00
GetAllEndpointStatuses(params *paging.EndpointStatusParams) ([]*core.EndpointStatus, error)
2021-02-02 23:06:34 -05:00
2021-10-23 16:47:12 -04:00
// GetEndpointStatus returns the endpoint status for a given endpoint name in the given group
GetEndpointStatus(groupName, endpointName string, params *paging.EndpointStatusParams) (*core.EndpointStatus, error)
2021-02-02 23:06:34 -05:00
2021-10-23 16:47:12 -04:00
// GetEndpointStatusByKey returns the endpoint status for a given key
GetEndpointStatusByKey(key string, params *paging.EndpointStatusParams) (*core.EndpointStatus, error)
2021-02-02 23:06:34 -05:00
2021-08-12 21:54:23 -04:00
// GetUptimeByKey returns the uptime percentage during a time range
GetUptimeByKey(key string, from, to time.Time) (float64, error)
// GetAverageResponseTimeByKey returns the average response time in milliseconds (value) during a time range
GetAverageResponseTimeByKey(key string, from, to time.Time) (int, error)
2021-08-19 23:07:21 -04: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-10-23 16:47:12 -04:00
// Insert adds the observed result for the specified endpoint into the store
Insert(endpoint *core.Endpoint, result *core.Result) error
2021-02-02 23:06:34 -05:00
2021-10-23 16:47:12 -04:00
// DeleteAllEndpointStatusesNotInKeys removes all EndpointStatus that are not within the keys provided
2021-02-02 23:06:34 -05:00
//
2021-10-23 16:47:12 -04:00
// Used to delete endpoints that have been persisted but are no longer part of the configured endpoints
DeleteAllEndpointStatusesNotInKeys(keys []string) int
2021-02-02 23:06:34 -05:00
// Clear deletes everything from the store
Clear()
2021-02-05 20:45:28 -05:00
// Save persists the data if and where it needs to be persisted
Save() error
2021-07-15 22:07:30 -04:00
// Close terminates every connection and closes the store, if applicable.
2021-07-15 22:07:30 -04:00
// Should only be used before stopping the application.
Close()
2021-02-02 23:06:34 -05:00
}
// TODO: add method to check state of store (by keeping track of silent errors)
2021-02-02 23:06:34 -05:00
var (
// Validate interface implementation on compile
_ Store = (*memory.Store)(nil)
_ Store = (*sql.Store)(nil)
2021-02-02 23:06:34 -05:00
)