Skip to content

Commit

Permalink
Merge pull request #693 from oasisprotocol/andrew7234/node-stats-fix
Browse files Browse the repository at this point in the history
node stats analyzer: handle nonexistent runtimes gracefully
  • Loading branch information
Andrew7234 authored May 21, 2024
2 parents c26c754 + 115b3e0 commit 24a551c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions .changelog/693.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
analyzer: make node stats analyzer more robust to unsupported runtimes
14 changes: 4 additions & 10 deletions analyzer/node_stats/node_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func NewAnalyzer(
cfg config.ItemBasedAnalyzerConfig,
layers []common.Layer,
consensusClient nodeapi.ConsensusApiLite,
emeraldClient nodeapi.RuntimeApiLite,
sapphireClient nodeapi.RuntimeApiLite,
pontusxClient nodeapi.RuntimeApiLite,
runtimeClients map[common.Runtime]nodeapi.RuntimeApiLite,
target storage.TargetStorage,
logger *log.Logger,
) (analyzer.Analyzer, error) {
Expand All @@ -53,13 +51,9 @@ func NewAnalyzer(
p := &processor{
layers: layers,
consensusSource: consensusClient,
runtimeSources: map[common.Runtime]nodeapi.RuntimeApiLite{
common.RuntimeEmerald: emeraldClient,
common.RuntimeSapphire: sapphireClient,
common.RuntimePontusx: pontusxClient,
},
target: target,
logger: logger.With("analyzer", nodeStatsAnalyzerName),
runtimeSources: runtimeClients,
target: target,
logger: logger.With("analyzer", nodeStatsAnalyzerName),
}

return item.NewAnalyzer[common.Layer](
Expand Down
25 changes: 13 additions & 12 deletions cmd/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,19 +547,20 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
if err1 != nil {
return nil, err1
}
emeraldClient, err1 := sources.Runtime(ctx, common.RuntimeEmerald)
if err1 != nil {
return nil, err1
}
sapphireClient, err1 := sources.Runtime(ctx, common.RuntimeSapphire)
if err1 != nil {
return nil, err1
}
pontusxClient, err1 := sources.Runtime(ctx, common.RuntimePontusx)
if err1 != nil {
return nil, err1
runtimeClients := map[common.Runtime]nodeapi.RuntimeApiLite{}
// We attempt to provide the analyzer with all runtime clients. This may
// fail if the node does not support the runtime, which is valid. If
// the analyzer expects the node to support the runtime but it does not,
// the analyzer will log an error.
for _, runtime := range []common.Runtime{common.RuntimeEmerald, common.RuntimeCipher, common.RuntimeSapphire, common.RuntimePontusx} {
client, err2 := sources.Runtime(ctx, runtime)
if err2 != nil {
logger.Warn("unable to instantiate runtime client for node stats analyzer", "runtime", runtime)
continue
}
runtimeClients[runtime] = client
}
return nodestats.NewAnalyzer(cfg.Analyzers.NodeStats.ItemBasedAnalyzerConfig, cfg.Analyzers.NodeStats.Layers, sourceClient, emeraldClient, sapphireClient, pontusxClient, dbClient, logger)
return nodestats.NewAnalyzer(cfg.Analyzers.NodeStats.ItemBasedAnalyzerConfig, cfg.Analyzers.NodeStats.Layers, sourceClient, runtimeClients, dbClient, logger)
})
}
if cfg.Analyzers.AggregateStats != nil {
Expand Down
4 changes: 4 additions & 0 deletions storage/oasis/nodeapi/history/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func NewHistoryRuntimeApiLite(ctx context.Context, history *config.History, sdkP
apis := map[string]nodeapi.RuntimeApiLite{}
for _, record := range history.Records {
if archiveConfig, ok := nodes[record.ArchiveName]; ok {
// If sdkPT is nil, the subsequent sdkConn.Runtime() call will panic
if sdkPT == nil {
return nil, fmt.Errorf("no paratime specified")
}
sdkConn, err := connections.SDKConnect(ctx, record.ChainContext, archiveConfig.ResolvedRuntimeNode(runtime), fastStartup)
if err != nil {
return nil, err
Expand Down

0 comments on commit 24a551c

Please sign in to comment.