From 4104e84d0cb6d735ab71ade3b53e62fbe6f66e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Mon, 29 Jul 2024 16:00:34 -0400 Subject: [PATCH] Tools->prometheus: added the possibility to override the start-block on an endpoint --- docs/release-notes/change-log.md | 4 ++++ tools/prometheus-exporter.go | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/change-log.md b/docs/release-notes/change-log.md index a0b8f962..78c5e34b 100644 --- a/docs/release-notes/change-log.md +++ b/docs/release-notes/change-log.md @@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +* Tools->prometheus: added the possibility to override the start-block on an endpoint + ## v1.9.3 * Fixed error handling issue in 'backprocessing' causing high CPU usage in tier1 servers diff --git a/tools/prometheus-exporter.go b/tools/prometheus-exporter.go index 6d72da29..aa3f3856 100644 --- a/tools/prometheus-exporter.go +++ b/tools/prometheus-exporter.go @@ -31,12 +31,13 @@ var status = prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "substreams_healt var requestDurationMs = prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "substreams_healthcheck_duration_ms", Help: "Request full processing time in millisecond"}, []string{"endpoint"}) var prometheusCmd = &cobra.Command{ - Use: "prometheus-exporter [] ", + Use: "prometheus-exporter ]],[,...]]> [] ", Short: "run substreams client periodically on a single block, exporting the values in prometheus format", Long: cli.Dedent(` Run substreams client periodically on a single block, exporting the values in prometheus format. The manifest is optional as it will try to find a file named 'substreams.yaml' in current working directory if nothing entered. You may enter a directory that contains a 'substreams.yaml' file in place of ', or a link to a remote .spkg file, using urls gs://, http(s)://, ipfs://, etc.'. + You can specify a start-block on some endpoints by appending '@' to the endpoint URL. `), RunE: runPrometheus, Args: cobra.RangeArgs(3, 4), @@ -90,6 +91,19 @@ func runPrometheus(cmd *cobra.Command, args []string) error { interval := sflags.MustGetDuration(cmd, "lookup_interval") timeout := sflags.MustGetDuration(cmd, "lookup_timeout") for _, endpoint := range endpoints { + + startBlock := blockNum + + if parts := strings.Split(endpoint, "@"); len(parts) == 2 { + start, err := strconv.ParseUint(parts[1], 10, 64) + if err != nil { + return fmt.Errorf("invalid endpoint @startBlock format for %q: %w", endpoint, err) + } + + endpoint = parts[0] + startBlock = int64(start) + } + substreamsClientConfig := client.NewSubstreamsClientConfig( endpoint, authToken, @@ -97,7 +111,7 @@ func runPrometheus(cmd *cobra.Command, args []string) error { insecure, plaintext, ) - go launchSubstreamsPoller(endpoint, substreamsClientConfig, pkg.Modules, outputStreamName, blockNum, interval, timeout) + go launchSubstreamsPoller(endpoint, substreamsClientConfig, pkg.Modules, outputStreamName, startBlock, interval, timeout) } promReg := prometheus.NewRegistry() @@ -136,6 +150,7 @@ func maybeMarkFailure(endpoint string, begin time.Time, counter *failCounter) { } func launchSubstreamsPoller(endpoint string, substreamsClientConfig *client.SubstreamsClientConfig, modules *pbsubstreams.Modules, outputStreamName string, blockNum int64, pollingInterval, pollingTimeout time.Duration) { + sleep := time.Duration(0) counter := newFailCounter() for {