mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Live: Add logging to memory cache (#75245)
This commit is contained in:
parent
70cb87380d
commit
71fe6f8390
@ -6,18 +6,22 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MemoryFrameCache ...
|
// MemoryFrameCache ...
|
||||||
type MemoryFrameCache struct {
|
type MemoryFrameCache struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
frames map[int64]map[string]data.FrameJSONCache
|
frames map[int64]map[string]data.FrameJSONCache
|
||||||
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMemoryFrameCache ...
|
// NewMemoryFrameCache ...
|
||||||
func NewMemoryFrameCache() *MemoryFrameCache {
|
func NewMemoryFrameCache() *MemoryFrameCache {
|
||||||
return &MemoryFrameCache{
|
return &MemoryFrameCache{
|
||||||
frames: map[int64]map[string]data.FrameJSONCache{},
|
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()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
cachedFrame, ok := c.frames[orgID][channel]
|
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) {
|
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]
|
cachedJsonFrame, exists := c.frames[orgID][channel]
|
||||||
schemaUpdated := !exists || !cachedJsonFrame.SameSchema(&jsonFrame)
|
schemaUpdated := !exists || !cachedJsonFrame.SameSchema(&jsonFrame)
|
||||||
c.frames[orgID][channel] = jsonFrame
|
c.frames[orgID][channel] = jsonFrame
|
||||||
|
c.log.Debug("Cache update",
|
||||||
|
"orgId", orgID,
|
||||||
|
"channel", channel,
|
||||||
|
"length", len(jsonFrame.Bytes(data.IncludeAll)),
|
||||||
|
)
|
||||||
return schemaUpdated, nil
|
return schemaUpdated, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user