Skip to content

Commit 9620350

Browse files
committed
Merge branch 'main' into fix/reserve-port
2 parents 2ae7aca + 49e3782 commit 9620350

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

internal/components.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func (o *OpGeth) Run(service *service, ctx *ExContext) {
137137
WithImage("us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth").
138138
WithTag("v1.101503.2-rc.5").
139139
WithEntrypoint("/bin/sh").
140+
WithLabel("metrics_path", "/debug/metrics/prometheus").
140141
WithArgs(
141142
"-c",
142143
"geth init --datadir {{.Dir}}/data_opgeth --state.scheme hash {{.Dir}}/l2-genesis.json && "+
@@ -262,6 +263,7 @@ func (r *RethEL) Run(svc *service, ctx *ExContext) {
262263
"--authrpc.port", `{{Port "authrpc" 8551}}`,
263264
"--authrpc.addr", "0.0.0.0",
264265
"--authrpc.jwtsecret", "{{.Dir}}/jwtsecret",
266+
"--metrics", `0.0.0.0:{{Port "metrics" 9090}}`,
265267
// For reth version 1.2.0 the "legacy" engine was removed, so we now require these arguments:
266268
"--engine.persistence-threshold", "0", "--engine.memory-block-buffer-target", "0",
267269
logLevelToRethVerbosity(ctx.LogLevel),
@@ -396,6 +398,7 @@ func (m *MevBoostRelay) Run(service *service, ctx *ExContext) {
396398
service.
397399
WithImage("docker.io/flashbots/playground-utils").
398400
WithTag("latest").
401+
WithEnv("ALLOW_SYNCING_BEACON_NODE", "1").
399402
WithEntrypoint("mev-boost-relay").
400403
DependsOnHealthy(m.BeaconClient).
401404
WithArgs(
@@ -512,6 +515,7 @@ func (o *OpReth) Run(service *service, ctx *ExContext) {
512515
"--datadir", "{{.Dir}}/data_op_reth",
513516
"--disable-discovery",
514517
"--color", "never",
518+
"--metrics", `0.0.0.0:{{Port "metrics" 9090}}`,
515519
"--port", `{{Port "rpc" 30303}}`)
516520
}
517521

internal/local_runner.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,68 @@ func (d *LocalRunner) trackContainerStatusAndLogs() {
780780
}
781781
}
782782

783+
func CreatePrometheusServices(manifest *Manifest, out *output) error {
784+
// Read all the components to be deployed and find all the ports with name 'metrics'
785+
// to create the prometheus scrapper config
786+
var scrapeConfigs []map[string]interface{}
787+
788+
// global scrape config
789+
scrapeConfigs = append(scrapeConfigs, map[string]interface{}{
790+
"job_name": "external",
791+
"metrics_path": "/metrics",
792+
"static_configs": []map[string]interface{}{
793+
{
794+
"targets": []string{"host.docker.internal:5555"},
795+
},
796+
},
797+
})
798+
799+
for _, c := range manifest.services {
800+
for _, port := range c.ports {
801+
if port.Name == "metrics" {
802+
metricsPath := "/metrics"
803+
if overrideMetricsPath, ok := c.labels["metrics_path"]; ok {
804+
metricsPath = overrideMetricsPath
805+
}
806+
807+
scrapeConfig := map[string]interface{}{
808+
"job_name": c.Name,
809+
"metrics_path": metricsPath,
810+
"static_configs": []map[string]interface{}{
811+
{
812+
"targets": []string{fmt.Sprintf("%s:%d", c.Name, port.Port)},
813+
},
814+
},
815+
}
816+
scrapeConfigs = append(scrapeConfigs, scrapeConfig)
817+
}
818+
}
819+
}
820+
821+
promConfig := map[string]interface{}{
822+
"global": map[string]interface{}{
823+
"scrape_interval": "1s",
824+
"evaluation_interval": "1s",
825+
},
826+
"scrape_configs": scrapeConfigs,
827+
}
828+
829+
if err := out.WriteFile("prometheus.yaml", promConfig); err != nil {
830+
return fmt.Errorf("failed to write prometheus.yml: %w", err)
831+
}
832+
833+
// add to the manifest the prometheus service
834+
// This is a bit of a hack.
835+
srv := manifest.NewService("prometheus").
836+
WithImage("prom/prometheus").
837+
WithTag("latest").
838+
WithArgs("--config.file", "{{.Dir}}/prometheus.yaml").
839+
WithPort("metrics", 9090, "tcp")
840+
manifest.services = append(manifest.services, srv)
841+
842+
return nil
843+
}
844+
783845
func (d *LocalRunner) Run() error {
784846
go d.trackContainerStatusAndLogs()
785847

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var interactive bool
2525
var timeout time.Duration
2626
var logLevelFlag string
2727
var bindExternal bool
28+
var withPrometheus bool
2829

2930
var rootCmd = &cobra.Command{
3031
Use: "playground",
@@ -169,6 +170,7 @@ func main() {
169170
recipeCmd.Flags().DurationVar(&timeout, "timeout", 0, "") // Used for CI
170171
recipeCmd.Flags().StringVar(&logLevelFlag, "log-level", "info", "log level")
171172
recipeCmd.Flags().BoolVar(&bindExternal, "bind-external", false, "bind host ports to external interface")
173+
recipeCmd.Flags().BoolVar(&withPrometheus, "with-prometheus", false, "whether to gather the Prometheus metrics")
172174

173175
cookCmd.AddCommand(recipeCmd)
174176
}
@@ -225,6 +227,12 @@ func runIt(recipe internal.Recipe) error {
225227
return err
226228
}
227229

230+
if withPrometheus {
231+
if err := internal.CreatePrometheusServices(svcManager, artifacts.Out); err != nil {
232+
return fmt.Errorf("failed to create prometheus services: %w", err)
233+
}
234+
}
235+
228236
if dryRun {
229237
return nil
230238
}

0 commit comments

Comments
 (0)