Skip to content

Commit

Permalink
Tools->prometheus: added the possibility to override the start-block …
Browse files Browse the repository at this point in the history
…on an endpoint
  • Loading branch information
sduchesneau committed Jul 29, 2024
1 parent febfb69 commit 4104e84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions tools/prometheus-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <endpoint[,endpoint[,...]]> [<manifest>] <module_name> <block_height>",
Use: "prometheus-exporter <endpoint[,endpoint[,endpoint[@<block_height>]],[,...]]> [<manifest>] <module_name> <block_height>",
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 '<manifest_file>, 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 '@<block_height>' to the endpoint URL.
`),
RunE: runPrometheus,
Args: cobra.RangeArgs(3, 4),
Expand Down Expand Up @@ -90,14 +91,27 @@ 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,
authType,
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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4104e84

Please sign in to comment.