-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOM: onchain report observation tracking (#658)
* wip: parsing tx details framework * WIP: parsing logic * wip: parsing observation counts from transactions * sort data into bucket * txdetails source * bump solana-go * WIP: metrics * share gauge logic + implement report observation metric * report observations exporter * update TODOs
- Loading branch information
Showing
30 changed files
with
956 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package exporter | ||
|
||
import ( | ||
"context" | ||
|
||
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types" | ||
) | ||
|
||
func NewReportObservationsFactory( | ||
log commonMonitoring.Logger, | ||
metrics metrics.ReportObservations, | ||
) commonMonitoring.ExporterFactory { | ||
return &reportObservationsFactory{ | ||
log, | ||
metrics, | ||
} | ||
} | ||
|
||
type reportObservationsFactory struct { | ||
log commonMonitoring.Logger | ||
metrics metrics.ReportObservations | ||
} | ||
|
||
func (p *reportObservationsFactory) NewExporter( | ||
params commonMonitoring.ExporterParams, | ||
) (commonMonitoring.Exporter, error) { | ||
return &reportObservations{ | ||
metrics.FeedInput{ | ||
AccountAddress: params.FeedConfig.GetContractAddress(), | ||
FeedID: params.FeedConfig.GetContractAddress(), | ||
ChainID: params.ChainConfig.GetChainID(), | ||
ContractStatus: params.FeedConfig.GetContractStatus(), | ||
ContractType: params.FeedConfig.GetContractType(), | ||
FeedName: params.FeedConfig.GetName(), | ||
FeedPath: params.FeedConfig.GetPath(), | ||
NetworkID: params.ChainConfig.GetNetworkID(), | ||
NetworkName: params.ChainConfig.GetNetworkName(), | ||
}, | ||
p.log, | ||
p.metrics, | ||
}, nil | ||
} | ||
|
||
type reportObservations struct { | ||
label metrics.FeedInput // static for each feed | ||
log commonMonitoring.Logger | ||
metrics metrics.ReportObservations | ||
} | ||
|
||
func (p *reportObservations) Export(ctx context.Context, data interface{}) { | ||
details, err := types.MakeTxDetails(data) | ||
if err != nil { | ||
return // skip if input could not be parsed | ||
} | ||
|
||
// skip on no updates | ||
if len(details) == 0 { | ||
return | ||
} | ||
|
||
// sanity check: find non-empty detail | ||
// assumption: details ordered from latest -> earliest | ||
var latest types.TxDetails | ||
for _, d := range details { | ||
if !d.Empty() { | ||
latest = d | ||
break | ||
} | ||
} | ||
if latest.Empty() { | ||
p.log.Errorw("exporter could not find non-empty TxDetails", "feed", p.label.ToPromLabels()) | ||
return | ||
} | ||
|
||
p.metrics.SetCount(latest.ObservationCount, p.label) | ||
} | ||
|
||
func (p *reportObservations) Cleanup(_ context.Context) { | ||
p.metrics.Cleanup(p.label) | ||
} |
Oops, something went wrong.