Skip to content

Commit

Permalink
Add metric for num logs in buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ogtownsend committed Jan 23, 2024
1 parent c45ff89 commit 7f2db32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ type logEventBuffer struct {
blocks []fetchedBlock
// latestBlock is the latest block number seen
latestBlock int64
// logsInBuffer is the number of logs currently in the buffer
logsInBuffer int64
}

func newLogEventBuffer(lggr logger.Logger, size, numOfLogUpkeeps, fastExecLogsHigh int) *logEventBuffer {
Expand Down Expand Up @@ -230,6 +232,7 @@ func (b *logEventBuffer) enqueue(id *big.Int, logs ...logpoller.Log) int {
}
if added > 0 {
lggr.Debugw("Added logs to buffer", "addedLogs", added, "dropped", dropped, "latestBlock", latestBlock)
atomic.AddInt64(&b.logsInBuffer, int64(added-dropped))
}

return added - dropped
Expand Down Expand Up @@ -331,6 +334,7 @@ func (b *logEventBuffer) dequeueRange(start, end int64, upkeepLimit, totalLimit

if len(results) > 0 {
b.lggr.Debugw("Dequeued logs", "results", len(results), "start", start, "end", end)
atomic.AddInt64(&b.logsInBuffer, -int64(len(results)))
}

return results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/prommetrics"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
Expand Down Expand Up @@ -102,6 +103,8 @@ type logEventProvider struct {
opts LogTriggersOptions

currentPartitionIdx uint64

servedLogs int64
}

func NewLogProvider(lggr logger.Logger, poller logpoller.LogPoller, packer LogDataPacker, filterStore UpkeepFilterStore, opts LogTriggersOptions) *logEventProvider {
Expand Down Expand Up @@ -142,6 +145,21 @@ func (p *logEventProvider) Start(context.Context) error {
})
})

p.threadCtrl.Go(func(ctx context.Context) {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
p.lggr.Debugw("logs stats", "servedLogs", atomic.LoadInt64(&p.servedLogs), "logsInBuffer", atomic.LoadInt64(&p.buffer.logsInBuffer), "latestBlockSeen", p.buffer.latestBlockSeen())
prommetrics.AutomationLogsInLogBuffer.Set(float64(atomic.LoadInt64(&p.buffer.logsInBuffer)))
case <-ctx.Done():
return

}
}
})

return nil
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package prommetrics

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

// AutomationNamespace is the namespace for all Automation related metrics
const AutomationNamespace = "automation"

// Automation metrics
var (
AutomationLogsInLogBuffer = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: AutomationNamespace,
Name: "num_logs_in_log_buffer",
Help: "The total number of logs currently being stored in the log buffer",
})
)

0 comments on commit 7f2db32

Please sign in to comment.