Skip to content

Commit

Permalink
fix(da): fix metrics init
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Oct 7, 2024
1 parent 30c6dd6 commit b54ce8b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/rollkit/centralized-sequencer/sequencing"
sequencingGRPC "github.com/rollkit/go-sequencing/proxy/grpc"
)
Expand Down Expand Up @@ -68,15 +69,15 @@ func main() {
go func() {
log.Printf("Starting metrics server on %v...\n", metricsAddress)
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(metricsAddress, nil)
err := http.ListenAndServe(metricsAddress, nil) // #nosec G114
if err != nil {
log.Fatalf("Failed to serve metrics: %v", err)
}
}()
}

metrics := sequencing.DefaultMetricsProvider(metricsEnabled, da_namespace)
centralizedSeq, err := sequencing.NewSequencer(da_address, da_auth_token, namespace, batchTime, metrics(""))
metrics := sequencing.DefaultMetricsProvider(metricsEnabled)("") // TODO use rollupId as chain_id
centralizedSeq, err := sequencing.NewSequencer(da_address, da_auth_token, namespace, batchTime, metrics)
if err != nil {
log.Fatalf("Failed to create centralized sequencer: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions sequencing/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type MetricsProvider func(chainID string) *Metrics

// DefaultMetricsProvider returns Metrics build using Prometheus client library
// if Prometheus is enabled. Otherwise, it returns no-op Metrics.
func DefaultMetricsProvider(enabled bool, namespace string) MetricsProvider {
func DefaultMetricsProvider(enabled bool) MetricsProvider {
return func(chainID string) *Metrics {
if enabled {
return PrometheusMetrics(namespace, "chain_id", chainID)
return PrometheusMetrics("chain_id", chainID)
}
return NopMetrics()
}
Expand Down Expand Up @@ -49,7 +49,7 @@ type Metrics struct {
// PrometheusMetrics returns Metrics build using Prometheus client library.
// Optionally, labels can be provided along with their values ("foo",
// "fooValue").
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
func PrometheusMetrics(labelsAndValues ...string) *Metrics {
labels := []string{}
for i := 0; i < len(labelsAndValues); i += 2 {
labels = append(labels, labelsAndValues[i])
Expand Down
3 changes: 1 addition & 2 deletions sequencing/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ type Sequencer struct {
seenBatches map[string]struct{}
bq *BatchQueue

metricsProvider MetricsProvider
metrics *Metrics
metrics *Metrics
}

// NewSequencer ...
Expand Down
4 changes: 2 additions & 2 deletions sequencing/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestNewSequencer(t *testing.T) {
// mockDAClient := new(da.DAClient)

// Create a new sequencer with mock DA client
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), 10*time.Second)
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), 10*time.Second, NopMetrics())
require.NoError(t, err)

// Check if the sequencer was created with the correct values
Expand All @@ -63,7 +63,7 @@ func TestNewSequencer(t *testing.T) {

func TestSequencer_SubmitRollupTransaction(t *testing.T) {
// Initialize a new sequencer
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), 10*time.Second)
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), 10*time.Second, NopMetrics())
require.NoError(t, err)

// Test with initial rollup ID
Expand Down

0 comments on commit b54ce8b

Please sign in to comment.