diff --git a/internal/consensus/metrics.gen.go b/internal/consensus/metrics.gen.go index ad2adc7eb..2179b7aeb 100644 --- a/internal/consensus/metrics.gen.go +++ b/internal/consensus/metrics.gen.go @@ -162,7 +162,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Namespace: namespace, Subsystem: MetricsSubsystem, Name: "quorum_prevote_delay", - Help: "QuroumPrevoteMessageDelay is the interval in seconds between the proposal timestamp and the timestamp of the earliest prevote that achieved a quorum during the prevote step. To compute it, sum the voting power over each prevote received, in increasing order of timestamp. The timestamp of the first prevote to increase the sum to be above 2/3 of the total voting power of the network defines the endpoint the endpoint of the interval. Subtract the proposal timestamp from this endpoint to obtain the quorum delay.", + Help: "QuroumPrevoteMessageDelay is the interval in seconds between the proposal timestamp and the timestamp of the earliest prevote that achieved a quorum during the prevote step. To compute it, sum the voting power over each prevote received, in increasing order of timestamp. The timestamp of the first prevote to increase the sum to be above 2/3 of the total voting power of the network defines the endpoint the endpoint of the interval. Subtract the proposal timestamp from this endpoint to obtain the quorum delay.", }, append(labels, "proposer_address")).With(labelsAndValues...), FullPrevoteDelay: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ Namespace: namespace, diff --git a/scripts/metricsgen/metricsgen.go b/scripts/metricsgen/metricsgen.go index b7068220f..dc78bd238 100644 --- a/scripts/metricsgen/metricsgen.go +++ b/scripts/metricsgen/metricsgen.go @@ -249,19 +249,8 @@ func findMetricsStruct(files map[string]*ast.File, structName string) (*ast.Stru } func parseMetricField(f *ast.Field) ParsedMetricField { - var comment string - if f.Doc != nil { - for i, c := range f.Doc.List { - if str := strings.TrimPrefix(c.Text, "//"); len(str) > 0 { - comment += strings.TrimPrefix(str, " ") - } - if i < len(f.Doc.List)-1 { - comment += " " - } - } - } pmf := ParsedMetricField{ - Description: comment, + Description: extractHelpMessage(f.Doc), MetricName: extractFieldName(f.Names[0].String(), f.Tag), FieldName: f.Names[0].String(), TypeName: extractTypeName(f.Type), @@ -277,6 +266,28 @@ func extractTypeName(e ast.Expr) string { return strings.TrimPrefix(path.Ext(types.ExprString(e)), ".") } +func extractHelpMessage(cg *ast.CommentGroup) string { + if cg == nil { + return "" + } + var help string + for i, c := range cg.List { + str := strings.TrimPrefix(c.Text, "//") + if len(str) == 0 { + continue + } + mt := strings.TrimPrefix(str, "metrics:") + if len(mt) < len(str) { + return mt + } + help += strings.TrimPrefix(str, " ") + if i < len(cg.List)-1 { + help += " " + } + } + return help +} + func isMetric(e ast.Expr, mPkgName string) bool { return strings.Contains(types.ExprString(e), fmt.Sprintf("%s.", mPkgName)) }