mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Live: Add logging to memory cache (#75245)
This commit is contained in:
parent
70cb87380d
commit
71fe6f8390
@ -6,18 +6,22 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
)
|
||||
|
||||
// MemoryFrameCache ...
|
||||
type MemoryFrameCache struct {
|
||||
mu sync.RWMutex
|
||||
frames map[int64]map[string]data.FrameJSONCache
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
// NewMemoryFrameCache ...
|
||||
func NewMemoryFrameCache() *MemoryFrameCache {
|
||||
return &MemoryFrameCache{
|
||||
frames: map[int64]map[string]data.FrameJSONCache{},
|
||||
log: log.New("live.memoryframecache"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +43,13 @@ func (c *MemoryFrameCache) GetFrame(ctx context.Context, orgID int64, channel st
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
cachedFrame, ok := c.frames[orgID][channel]
|
||||
return cachedFrame.Bytes(data.IncludeAll), ok, nil
|
||||
raw := cachedFrame.Bytes(data.IncludeAll)
|
||||
c.log.Debug("Cache get",
|
||||
"orgId", orgID,
|
||||
"channel", channel,
|
||||
"length", len(raw),
|
||||
)
|
||||
return raw, ok, nil
|
||||
}
|
||||
|
||||
func (c *MemoryFrameCache) Update(ctx context.Context, orgID int64, channel string, jsonFrame data.FrameJSONCache) (bool, error) {
|
||||
@ -51,5 +61,10 @@ func (c *MemoryFrameCache) Update(ctx context.Context, orgID int64, channel stri
|
||||
cachedJsonFrame, exists := c.frames[orgID][channel]
|
||||
schemaUpdated := !exists || !cachedJsonFrame.SameSchema(&jsonFrame)
|
||||
c.frames[orgID][channel] = jsonFrame
|
||||
c.log.Debug("Cache update",
|
||||
"orgId", orgID,
|
||||
"channel", channel,
|
||||
"length", len(jsonFrame.Bytes(data.IncludeAll)),
|
||||
)
|
||||
return schemaUpdated, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user