Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gauge metrics for redis cstore items #272

Merged
merged 2 commits into from
Aug 6, 2024
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
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())
}
Loading