From a6c3d1e42b922f3db4f1262181a2e5a6da8eea30 Mon Sep 17 00:00:00 2001 From: Joshua Gutow Date: Mon, 10 Apr 2023 16:43:05 -0700 Subject: [PATCH] op-node/doc: Document op-batcher & op-proposer metrics --- op-node/cmd/doc/cmd.go | 68 +++++++++++++++++++------- op-proposer/metrics/metrics.go | 4 ++ op-service/txmgr/metrics/tx_metrics.go | 4 +- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/op-node/cmd/doc/cmd.go b/op-node/cmd/doc/cmd.go index 2a55b6b064ead..8106644c1194b 100644 --- a/op-node/cmd/doc/cmd.go +++ b/op-node/cmd/doc/cmd.go @@ -6,11 +6,30 @@ import ( "os" "strings" + batcher_metrics "github.com/ethereum-optimism/optimism/op-batcher/metrics" "github.com/ethereum-optimism/optimism/op-node/metrics" + proposer_metrics "github.com/ethereum-optimism/optimism/op-proposer/metrics" + opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" "github.com/olekukonko/tablewriter" "github.com/urfave/cli" ) +type docs struct { + Node []opmetrics.DocumentedMetric `json:"op_node"` + Batcher []opmetrics.DocumentedMetric `json:"op_batcher"` + Proposer []opmetrics.DocumentedMetric `json:"op_proposer"` +} + +func (d docs) printMarkdown() error { + fmt.Println("# op-node metrics") + printMetricsAsMarkdown(d.Node) + fmt.Println("\n# op-batcher metrics") + printMetricsAsMarkdown(d.Batcher) + fmt.Println("\n# op-proposer metrics") + printMetricsAsMarkdown(d.Proposer) + return nil +} + var Subcommands = cli.Commands{ { Name: "metrics", @@ -24,31 +43,42 @@ var Subcommands = cli.Commands{ }, Action: func(ctx *cli.Context) error { m := metrics.NewMetrics("default") - supportedMetrics := m.Document() - format := ctx.String("format") + batcherM := batcher_metrics.NewMetrics("default") + proposerM := proposer_metrics.NewMetrics("default") - if format != "markdown" && format != "json" { - return fmt.Errorf("invalid format: %s", format) + d := docs{ + Node: m.Document(), + Batcher: batcherM.Document(), + Proposer: proposerM.Document(), } - if format == "json" { + format := ctx.String("format") + + switch format { + case "markdown": + return d.printMarkdown() + case "json": enc := json.NewEncoder(os.Stdout) - return enc.Encode(supportedMetrics) + return enc.Encode(d) + default: + return fmt.Errorf("invalid format: %s", format) } - table := tablewriter.NewWriter(os.Stdout) - table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) - table.SetCenterSeparator("|") - table.SetAutoWrapText(false) - table.SetHeader([]string{"Metric", "Description", "Labels", "Type"}) - var data [][]string - for _, metric := range supportedMetrics { - labels := strings.Join(metric.Labels, ",") - data = append(data, []string{metric.Name, metric.Help, labels, metric.Type}) - } - table.AppendBulk(data) - table.Render() - return nil }, }, } + +func printMetricsAsMarkdown(supportedMetrics []opmetrics.DocumentedMetric) { + table := tablewriter.NewWriter(os.Stdout) + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) + table.SetCenterSeparator("|") + table.SetAutoWrapText(false) + table.SetHeader([]string{"Metric", "Description", "Labels", "Type"}) + var data [][]string + for _, metric := range supportedMetrics { + labels := strings.Join(metric.Labels, ",") + data = append(data, []string{metric.Name, metric.Help, labels, metric.Type}) + } + table.AppendBulk(data) + table.Render() +} diff --git a/op-proposer/metrics/metrics.go b/op-proposer/metrics/metrics.go index 41767e8bc6caf..1f550eeedd732 100644 --- a/op-proposer/metrics/metrics.go +++ b/op-proposer/metrics/metrics.go @@ -104,3 +104,7 @@ const ( func (m *Metrics) RecordL2BlocksProposed(l2ref eth.L2BlockRef) { m.RecordL2Ref(BlockProposed, l2ref) } + +func (m *Metrics) Document() []opmetrics.DocumentedMetric { + return m.factory.Document() +} diff --git a/op-service/txmgr/metrics/tx_metrics.go b/op-service/txmgr/metrics/tx_metrics.go index 2ae036b33f814..ff632f594c95a 100644 --- a/op-service/txmgr/metrics/tx_metrics.go +++ b/op-service/txmgr/metrics/tx_metrics.go @@ -70,7 +70,7 @@ func MakeTxMetrics(ns string, factory metrics.Factory) TxMetrics { txPublishError: factory.NewCounterVec(prometheus.CounterOpts{ Namespace: ns, Name: "tx_publish_error_count", - Help: "Count of publish errors. Labells are sanitized error strings", + Help: "Count of publish errors. Labels are sanitized error strings", Subsystem: "txmgr", }, []string{"error"}), confirmEvent: metrics.NewEventVec(factory, ns, "confirm", "tx confirm", []string{"status"}), @@ -78,7 +78,7 @@ func MakeTxMetrics(ns string, factory metrics.Factory) TxMetrics { rpcError: factory.NewCounter(prometheus.CounterOpts{ Namespace: ns, Name: "rpc_error_count", - Help: "Temporrary: Count of RPC errors (like timeouts) that have occurrred", + Help: "Temporary: Count of RPC errors (like timeouts) that have occurred", Subsystem: "txmgr", }), }