Skip to content

Commit

Permalink
Add gauge metrics for redis cstore items (#272)
Browse files Browse the repository at this point in the history
* Add gauge metrics for redis cstore items

* Use docker compose instead of docker-compose
  • Loading branch information
ferranbt authored Aug 6, 2024
1 parent 4d75568 commit 789081d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
uses: actions/checkout@v2

- name: Run dev environment
run: docker-compose -f ./suave/e2e/docker-compose.yml up -d --build
run: docker compose -f ./suave/e2e/docker-compose.yml up -d --build

- name: Check out suapp-examples
uses: actions/checkout@v2
with:
repository: flashbots/suapp-examples
path: suapp-examples

- name: Build suapp-examples
run: |
cd suapp-examples
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ suavedevtools:
go run ./suave/gen/main.go -write

devnet-up:
docker-compose -f ./suave/devenv/docker-compose.yml up -d --build
docker compose -f ./suave/devenv/docker-compose.yml up -d --build

devnet-down:
docker-compose -f ./suave/devenv/docker-compose.yml down
docker compose -f ./suave/devenv/docker-compose.yml down

fmt-contracts:
cd suave && forge fmt
Expand Down
22 changes: 22 additions & 0 deletions suave/cstore/redis_store_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
suave "github.com/ethereum/go-ethereum/suave/core"
"github.com/go-redis/redis/v8"
)
Expand Down Expand Up @@ -86,9 +87,30 @@ func (r *RedisStoreBackend) start() error {
return fmt.Errorf("mempool: could not initialize: %w", err)
}

go r.trackMetrics()

return nil
}

func (r *RedisStoreBackend) count() int64 {
return r.client.DBSize(context.Background()).Val()
}

var (
redisStoreItemsGauge = metrics.NewRegisteredGauge("suave/confstore/items", nil)
)

func (r *RedisStoreBackend) trackMetrics() {
for {
select {
case <-r.ctx.Done():
return
case <-time.After(10 * time.Second):
redisStoreItemsGauge.Update(r.count())
}
}
}

func (r *RedisStoreBackend) Stop() error {
if r.cancel == nil || r.client == nil {
return errors.New("redis store: Stop() called before Start()")
Expand Down
16 changes: 16 additions & 0 deletions suave/cstore/redis_store_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,19 @@ func TestRedis_TTL_MultipleEntries_SameIndex(t *testing.T) {
require.Len(t, vals, 1)
require.Equal(t, record2, vals[0])
}

func TestRedis_Count(t *testing.T) {
store, err := NewRedisStoreBackend("", 2*time.Second)
require.NoError(t, err)

for i := 0; i < 10; i++ {
record := suave.DataRecord{
Id: suave.RandomDataRecordId(),
Version: "a",
DecryptionCondition: 1,
}
require.NoError(t, store.InitRecord(record))
}

require.NotZero(t, store.count())
}

0 comments on commit 789081d

Please sign in to comment.