Skip to content

Commit

Permalink
complete e2e test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Dec 16, 2024
1 parent dc84716 commit baa2beb
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 16 deletions.
17 changes: 9 additions & 8 deletions cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, account confi
}

return runner.Clients{
Zetacore: zetaCoreClients,
BtcRPC: btcRPCClient,
Solana: solanaClient,
TON: tonClient,
Evm: evmClient,
EvmAuth: evmAuth,
Zevm: zevmClient,
ZevmAuth: zevmAuth,
Zetacore: zetaCoreClients,
BtcRPC: btcRPCClient,
Solana: solanaClient,
TON: tonClient,
Evm: evmClient,
EvmAuth: evmAuth,
Zevm: zevmClient,
ZevmAuth: zevmAuth,
ZetaclientMetrics: &runner.MetricsClient{URL: conf.RPCs.ZetaclientMetrics},
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ rpcs:
zetacore_rpc: "http://localhost:26657"
solana: "http://localhost:8899"
ton_sidecar_url: "http://localhost:8111"
zetaclient_metrics: "http://localhost:8886"
contracts:
zevm:
system_contract: "0x91d18e54DAf4F677cB28167158d6dd21F6aB3921"
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ rpcs:
ton_sidecar_url: "http://ton:8000"
zetacore_grpc: "zetacore0:9090"
zetacore_rpc: "http://zetacore0:26657"
zetaclient_metrics: "http://zetaclient0:8886"
contracts:
# configure localnet solana gateway program id
solana:
Expand Down
1 change: 1 addition & 0 deletions contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ services:
restart: always
ports:
- "6061:6061" # pprof
- "8886:8886" # metrics
volumes:
- ssh:/root/.ssh
- preparams:/root/preparams
Expand Down
15 changes: 8 additions & 7 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ type ObserverRelayerAccounts struct {

// RPCs contains the configuration for the RPC endpoints
type RPCs struct {
Zevm string `yaml:"zevm"`
EVM string `yaml:"evm"`
Bitcoin BitcoinRPC `yaml:"bitcoin"`
Solana string `yaml:"solana"`
TONSidecarURL string `yaml:"ton_sidecar_url"`
ZetaCoreGRPC string `yaml:"zetacore_grpc"`
ZetaCoreRPC string `yaml:"zetacore_rpc"`
Zevm string `yaml:"zevm"`
EVM string `yaml:"evm"`
Bitcoin BitcoinRPC `yaml:"bitcoin"`
Solana string `yaml:"solana"`
TONSidecarURL string `yaml:"ton_sidecar_url"`
ZetaCoreGRPC string `yaml:"zetacore_grpc"`
ZetaCoreRPC string `yaml:"zetacore_rpc"`
ZetaclientMetrics string `yaml:"zetaclient_metrics"`
}

// BitcoinRPC contains the configuration for the Bitcoin RPC endpoint
Expand Down
21 changes: 20 additions & 1 deletion e2e/e2etests/test_operational_flags.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package e2etests

import (
"time"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
observertypes "github.com/zeta-chain/node/x/observer/types"
)

const (
startTimestampMetricName = "zetaclient_last_start_timestamp_seconds"
)

// TestOperationalFlags tests the functionality of operations flags.
func TestOperationalFlags(r *runner.E2ERunner, _ []string) {
_, err := r.Clients.Zetacore.Observer.OperationalFlags(
Expand Down Expand Up @@ -38,5 +44,18 @@ func TestOperationalFlags(r *runner.E2ERunner, _ []string) {
require.NoError(r, err)
require.Equal(r, restartHeight, operationalFlagsRes.OperationalFlags.RestartHeight)

// TODO: wait for restart height + 2 then test that start timestamp metric has increased
originalStartTime, err := r.Clients.ZetaclientMetrics.FetchGuage(startTimestampMetricName)
require.NoError(r, err, "fetching zetaclient metric name")

// wait for height above restart height
require.Eventually(r, func() bool {
height, err := r.Clients.Zetacore.GetBlockHeight(r.Ctx)
require.NoError(r, err)
return height > restartHeight+1
}, time.Minute, time.Second)

currentStartTime, err := r.Clients.ZetaclientMetrics.FetchGuage(startTimestampMetricName)
require.NoError(r, err)

require.Greater(r, currentStartTime, originalStartTime+1)
}
46 changes: 46 additions & 0 deletions e2e/runner/clients.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package runner

import (
"fmt"
"net/http"

"github.com/btcsuite/btcd/rpcclient"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/gagliardetto/solana-go/rpc"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"

tonrunner "github.com/zeta-chain/node/e2e/runner/ton"
zetacore_rpc "github.com/zeta-chain/node/pkg/rpc"
Expand All @@ -24,4 +29,45 @@ type Clients struct {
// the RPC clients for ZetaChain
Zevm *ethclient.Client
ZevmAuth *bind.TransactOpts

ZetaclientMetrics *MetricsClient
}

type MetricsClient struct {
URL string
}

// Fetch retrieves and parses the prometheus metrics from the provided URL
func (m *MetricsClient) Fetch() (map[string]*dto.MetricFamily, error) {
// Fetch metrics
resp, err := http.Get(m.URL)
if err != nil {
return nil, fmt.Errorf("failed to fetch metrics: %w", err)
}
defer resp.Body.Close()

// Parse metrics
parser := expfmt.TextParser{}
metricFamilies, err := parser.TextToMetricFamilies(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to parse metrics: %w", err)
}

return metricFamilies, nil
}

func (m *MetricsClient) FetchGuage(name string) (float64, error) {
metrics, err := m.Fetch()
if err != nil {
return 0, err
}
metric, ok := metrics[name]
if !ok {
return 0, fmt.Errorf("%s metric is not found", name)
}
guage := metric.Metric[0].Gauge

Check failure on line 68 in e2e/runner/clients.go

View workflow job for this annotation

GitHub Actions / lint

`guage` is a misspelling of `gauge` (misspell)
if guage == nil {

Check failure on line 69 in e2e/runner/clients.go

View workflow job for this annotation

GitHub Actions / lint

`guage` is a misspelling of `gauge` (misspell)
return 0, fmt.Errorf("%s metric is not a gauge", name)
}
return *guage.Value, nil

Check failure on line 72 in e2e/runner/clients.go

View workflow job for this annotation

GitHub Actions / lint

`guage` is a misspelling of `gauge` (misspell)
}

0 comments on commit baa2beb

Please sign in to comment.