Skip to content

Commit

Permalink
Add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mslipper committed Oct 23, 2024
1 parent 70b8fc5 commit d62fdc3
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 7 deletions.
29 changes: 25 additions & 4 deletions cmd/bailiff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/ctxinterrupt"
"github.com/ethereum-optimism/optimism/op-service/httputil"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/google/go-github/v66/github"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -61,12 +62,12 @@ var (
}
)

var GlobalFlags = append([]cli.Flag{
var GlobalFlags = []cli.Flag{
ConfigPathFlag,
WebhookSecretFlag,
GithubTokenFlag,
PrivateKeyFileFlag,
}, oplog.CLIFlags(EnvVarPrefix)...)
}

func main() {
app := cli.NewApp()
Expand Down Expand Up @@ -118,22 +119,42 @@ func main() {

ctx, cancel := context.WithCancel(cliCtx.Context)
defer cancel()

metricsCfg := opmetrics.ReadCLIConfig(cliCtx)
if metricsCfg.Enabled {
metricsSrv, err := opmetrics.StartServer(bailiff.MetricsRegistry, metricsCfg.ListenAddr, metricsCfg.ListenPort)
if err != nil {
return fmt.Errorf("failed to start metrics server: %w", err)
}
defer func() {
if err := metricsSrv.Stop(context.Background()); err != nil {
l.Error("failed to stop metrics server", "err", err)
}
}()

l.Info("metrics server is running", "addr", metricsCfg.ListenAddr)
}

httpSrv, err := httputil.StartHTTPServer(cfg.ListenAddr, srv)
if err != nil {
return fmt.Errorf("failed to start HTTP server: %w", err)
}

defer func() {
if err := httpSrv.Stop(ctx); err != nil {
if err := httpSrv.Stop(context.Background()); err != nil {
l.Error("failed to stop DA server", "err", err)
}
}()

l.Info("bailiff is running", "addr", cfg.ListenAddr)

return ctxinterrupt.Wait(ctx)
}
if err := app.Run(os.Args); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Application failed: %v\n", err)
}
}

func init() {
GlobalFlags = append(GlobalFlags, oplog.CLIFlags(EnvVarPrefix)...)
GlobalFlags = append(GlobalFlags, opmetrics.CLIFlags(EnvVarPrefix)...)
}
42 changes: 42 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,73 @@ require (
github.com/google/go-github/v66 v66.0.0
github.com/gorilla/mux v1.8.0
github.com/migueleliasweb/go-github-mock v1.0.1
github.com/prometheus/client_golang v1.20.5
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.4
)

require (
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.2 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-github/v64 v64.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit d62fdc3

Please sign in to comment.