mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 02:22:43 +08:00
Plugins: Angular patterns: Use ETag for GCOM requests (#74453)
* Plugins: Dynamic angular patterns: Send If-None-Match to GCOM, store ETag * Fix SetETag settings the wrong key in underlying kvstore * Fix wrong type in GCOMResponse.Patterns and wrong content being saved * Fix ctx passing to GetETag in background job * Added more ETag tests * More ETag tests * Set last updated and log when not modified is returned * Fix missing in-memory detectors update when etag matches, add comments * Fix mutex usage
This commit is contained in:
@ -10,13 +10,19 @@ import (
|
||||
|
||||
type Service interface {
|
||||
GetLastUpdated(ctx context.Context) (time.Time, error)
|
||||
|
||||
Get(ctx context.Context) (string, bool, error)
|
||||
Set(ctx context.Context, value any) error
|
||||
SetLastUpdated(ctx context.Context) error
|
||||
|
||||
GetETag(ctx context.Context) (string, bool, error)
|
||||
SetETag(ctx context.Context, etag string) error
|
||||
}
|
||||
|
||||
const (
|
||||
kvNamespace = "plugin.angularpatterns"
|
||||
keyPatterns = "angular_patterns"
|
||||
keyEtag = "etag"
|
||||
)
|
||||
|
||||
// KVStoreService allows to cache GCOM angular patterns into the database, as a cache.
|
||||
@ -37,7 +43,17 @@ func (s *KVStoreService) Get(ctx context.Context) (string, bool, error) {
|
||||
return s.CacheKvStore.Get(ctx, keyPatterns)
|
||||
}
|
||||
|
||||
// Set stores the given angular patterns in the underlying cachekvstore.s
|
||||
// GetETag returns the stored etag from the underlying cachekvstore.
|
||||
func (s *KVStoreService) GetETag(ctx context.Context) (string, bool, error) {
|
||||
return s.CacheKvStore.Get(ctx, keyEtag)
|
||||
}
|
||||
|
||||
// Set stores the given angular patterns in the underlying cachekvstore.
|
||||
func (s *KVStoreService) Set(ctx context.Context, value any) error {
|
||||
return s.CacheKvStore.Set(ctx, keyPatterns, value)
|
||||
}
|
||||
|
||||
// SetETag stores the given etag in the underlying cachekvstore.
|
||||
func (s *KVStoreService) SetETag(ctx context.Context, etag string) error {
|
||||
return s.CacheKvStore.Set(ctx, keyEtag, etag)
|
||||
}
|
||||
|
Reference in New Issue
Block a user