Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions internal/topo/node/cache/sync_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ func (p *page) reset() {
}

const (
syncCacheAdd = "add"
syncCachePop = "pop"
syncCacheFlush = "flush"
syncCacheDrop = "drop"
syncCacheLoad = "load"
syncCacheLength = "length"
syncCacheAdd = "add"
syncCachePop = "pop"
syncCacheFlush = "flush"
syncCacheDrop = "drop"
syncCacheLoad = "load"
)

type SyncCache struct {
Expand Down Expand Up @@ -150,6 +151,10 @@ func (c *SyncCache) SetupMeta(ctx api.StreamContext) {

// AddCache not thread safe!
func (c *SyncCache) AddCache(ctx api.StreamContext, item any) error {
defer func() {
metrics.SyncCacheCounter.WithLabelValues(syncCacheAdd, c.RuleID, c.OpID).Inc()
metrics.SyncCacheGauge.WithLabelValues(syncCacheLength, c.RuleID, c.OpID).Set(float64(c.CacheLength))
}()
isBufferNotFull := c.writeBufferPage.append(item)
if !isBufferNotFull { // cool page full, save to disk
err := c.appendWriteCache(ctx)
Expand All @@ -161,7 +166,6 @@ func (c *SyncCache) AddCache(ctx api.StreamContext, item any) error {
} else {
ctx.GetLogger().Debugf("added cache to disk buffer page %v", c.writeBufferPage)
}
metrics.SyncCacheCounter.WithLabelValues(syncCacheAdd, c.RuleID, c.OpID).Inc()
c.CacheLength++
ctx.GetLogger().Debugf("added cache %d", c.CacheLength)
return nil
Expand Down Expand Up @@ -204,6 +208,11 @@ func (c *SyncCache) appendWriteCache(ctx api.StreamContext) error {
}

func (c *SyncCache) insertReadCache(ctx api.StreamContext) error {
metrics.SyncCacheCounter.WithLabelValues(syncCacheFlush, c.RuleID, c.OpID).Inc()
start := time.Now()
defer func() {
metrics.SyncCacheHist.WithLabelValues(syncCacheFlush, c.RuleID, c.OpID).Observe(float64(time.Since(start).Microseconds()))
}()
// insert before current head
head := c.diskPageHead - 1
if head < 0 {
Expand Down Expand Up @@ -255,6 +264,7 @@ func (c *SyncCache) PopCache(ctx api.StreamContext) (any, bool) {
}
ctx.GetLogger().Debugf("deleted cache. CacheLength: %d, diskSize: %d, readPage: %v", c.CacheLength, c.diskSize, c.readBufferPage)
metrics.SyncCacheCounter.WithLabelValues(syncCachePop, c.RuleID, c.OpID).Inc()
metrics.SyncCacheGauge.WithLabelValues(syncCacheLength, c.RuleID, c.OpID).Set(float64(c.CacheLength))
return result, true
}

Expand Down
8 changes: 8 additions & 0 deletions metrics/sync_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ var (
Name: "counter",
Help: "counter of sync cache",
}, []string{LblType, LblRuleIDType, LblOpIDType})

SyncCacheGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "kuiper",
Subsystem: "sync_cache",
Name: "gauge",
Help: "gauge of sync cache",
}, []string{LblType, LblRuleIDType, LblOpIDType})
)

func RegisterSyncCache() {
prometheus.MustRegister(SyncCacheCounter)
prometheus.MustRegister(SyncCacheHist)
prometheus.MustRegister(SyncCacheGauge)
}
Loading