feat(storage)!: Remove persistence for memory storage
This commit is contained in:
@ -2,13 +2,11 @@ package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrSQLStorageRequiresPath = errors.New("sql storage requires a non-empty path to be defined")
|
||||
ErrMemoryStorageDoesNotSupportPath = errors.New("memory storage does not support persistence, use sqlite if you want persistence on file")
|
||||
ErrCannotSetBothFileAndPath = errors.New("file has been deprecated in favor of path: you cannot set both of them")
|
||||
)
|
||||
|
||||
// Config is the configuration for storage
|
||||
@ -18,12 +16,6 @@ type Config struct {
|
||||
// Note that not all Type support persistence
|
||||
Path string `yaml:"path"`
|
||||
|
||||
// File is the path of the file to use for persistence
|
||||
// If blank, persistence is disabled
|
||||
//
|
||||
// Deprecated
|
||||
File string `yaml:"file"`
|
||||
|
||||
// Type of store
|
||||
// If blank, uses the default in-memory store
|
||||
Type Type `yaml:"type"`
|
||||
@ -31,14 +23,6 @@ type Config struct {
|
||||
|
||||
// ValidateAndSetDefaults validates the configuration and sets the default values (if applicable)
|
||||
func (c *Config) ValidateAndSetDefaults() error {
|
||||
if len(c.File) > 0 && len(c.Path) > 0 { // XXX: Remove for v4.0.0
|
||||
return ErrCannotSetBothFileAndPath
|
||||
} else if len(c.File) > 0 { // XXX: Remove for v4.0.0
|
||||
log.Println("WARNING: Your configuration is using 'storage.file', which is deprecated in favor of 'storage.path'")
|
||||
log.Println("WARNING: storage.file will be completely removed in v4.0.0, so please update your configuration")
|
||||
log.Println("WARNING: See https://github.com/TwiN/gatus/issues/197")
|
||||
c.Path = c.File
|
||||
}
|
||||
if c.Type == "" {
|
||||
c.Type = TypeMemory
|
||||
}
|
||||
@ -46,12 +30,7 @@ func (c *Config) ValidateAndSetDefaults() error {
|
||||
return ErrSQLStorageRequiresPath
|
||||
}
|
||||
if c.Type == TypeMemory && len(c.Path) > 0 {
|
||||
log.Println("WARNING: Your configuration is using a storage of type memory with persistence, which has been deprecated")
|
||||
log.Println("WARNING: As of v4.0.0, the default storage type (memory) will not support persistence.")
|
||||
log.Println("WARNING: If you want persistence, use 'storage.type: sqlite' instead of 'storage.type: memory'")
|
||||
log.Println("WARNING: See https://github.com/TwiN/gatus/issues/198")
|
||||
// XXX: Uncomment the following line for v4.0.0
|
||||
//return ErrMemoryStorageDoesNotSupportPath
|
||||
return ErrMemoryStorageDoesNotSupportPath
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -2,11 +2,7 @@ package memory
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -14,7 +10,7 @@ import (
|
||||
"github.com/TwiN/gatus/v3/storage/store/common"
|
||||
"github.com/TwiN/gatus/v3/storage/store/common/paging"
|
||||
"github.com/TwiN/gatus/v3/util"
|
||||
"github.com/TwiN/gocache"
|
||||
"github.com/TwiN/gocache/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -28,11 +24,7 @@ func init() {
|
||||
// Store that leverages gocache
|
||||
type Store struct {
|
||||
sync.RWMutex
|
||||
// Deprecated
|
||||
//
|
||||
// File persistence will no longer be supported as of v4.0.0
|
||||
// XXX: Remove me in v4.0.0
|
||||
file string
|
||||
|
||||
cache *gocache.Cache
|
||||
}
|
||||
|
||||
@ -42,30 +34,8 @@ type Store struct {
|
||||
// supports eventual persistence.
|
||||
func NewStore(file string) (*Store, error) {
|
||||
store := &Store{
|
||||
file: file,
|
||||
cache: gocache.NewCache().WithMaxSize(gocache.NoMaxSize),
|
||||
}
|
||||
// XXX: Remove the block below in v4.0.0 because persistence with the memory store will no longer be supported
|
||||
// XXX: Make sure to also update gocache to v2.0.0
|
||||
if len(file) > 0 {
|
||||
_, err := store.cache.ReadFromFile(file)
|
||||
if err != nil {
|
||||
// XXX: Remove the block below in v4.0.0
|
||||
if data, err2 := os.ReadFile(file); err2 == nil {
|
||||
isFromOldVersion := strings.Contains(string(data), "*core.ServiceStatus")
|
||||
if isFromOldVersion {
|
||||
log.Println("WARNING: Couldn't read file due to recent change in v3.3.0, see https://github.com/TwiN/gatus/issues/191")
|
||||
log.Println("WARNING: Will automatically rename old file to " + file + ".old and overwrite the current file")
|
||||
if err = os.WriteFile(file+".old", data, fs.ModePerm); err != nil {
|
||||
log.Println("WARNING: Tried my best to keep the old file, but it wasn't enough. Sorry, your file will be overwritten :(")
|
||||
}
|
||||
// Return the store regardless of whether there was an error or not
|
||||
return store, nil
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return store, nil
|
||||
}
|
||||
|
||||
@ -221,9 +191,6 @@ func (s *Store) Clear() {
|
||||
|
||||
// Save persists the cache to the store file
|
||||
func (s *Store) Save() error {
|
||||
if len(s.file) > 0 {
|
||||
return s.cache.SaveToFile(s.file)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user