Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: plugin interface #83

Merged
merged 26 commits into from
Jun 12, 2023
Merged

Conversation

tzaffi
Copy link
Contributor

@tzaffi tzaffi commented May 28, 2023

Re-organize Plugin Interfaces

These changes grew out a personal project to create a binary conduit plugin (or plugins) which will help me calculate taxes. As I go along and spot various opportunites for streamlining, clarifying the requirements, and docs, I'll continue putting up small[1] PR's of this kind.

Except for the last commit (see Odd Finding below), all changes are non-functional. I'm expecting to roll back the last commit, but it's worth further discussion.

Summary of Changes

  • Introducing .markdownlint.yml. This isn't enforced in CI but while using the VS Code extension it helped me identify some bugs in our docs. For example, some improperly formatted list items.
  • Introducing Plugin interface extending PluginMetadata and with methods Config() and Close() in conduit/plugins/plugin.go. These are extended by the Importer, Processor and Exporter interfaces instead of PlugingMetadata resulting in changes in:
    • conduit/plugins/exporters/exporter.go
    • conduit/plugins/importers/importer.go
    • conduit/plugins/processors/processor.go
  • Small edits in the following docs:
    • docs/Configuration.md
    • docs/GettingStarted.md
    • docs/tutorials/WritingBlocksToFile.md
    • docs/tutorials/IndexerMigration.md
  • Add checks that the genesis value returned from newly introduced Importer.GetGenesis() meets expectations in various unit tests.

Odd Finding

Notice that all tests pass after I commented out all usages of Config(). Is this actually used anywhere? If not, we should consider removing it from the plugin interfaces.

Upshot of Odd Finding

After a discussion, we decided to streamline the Plugin interface as follows:

  • Remove Config() from the interfaces
  • Flatten PluginMetadata directly into Plugin interface
  • Add Init() to Plugin interface and...
    • ...split out GetGenesis() from Importer.Init()

[1]: It was still small at the original time that I created this PR description.

@codecov
Copy link

codecov bot commented May 28, 2023

Codecov Report

Merging #83 (5b114a0) into master (442791a) will increase coverage by 1.88%.
The diff coverage is 76.07%.

@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
+ Coverage   67.66%   69.54%   +1.88%     
==========================================
  Files          32       36       +4     
  Lines        1976     2417     +441     
==========================================
+ Hits         1337     1681     +344     
- Misses        570      645      +75     
- Partials       69       91      +22     
Impacted Files Coverage Δ
conduit/data/block_export_data.go 100.00% <ø> (+92.30%) ⬆️
conduit/metrics/metrics.go 100.00% <ø> (ø)
...duit/plugins/exporters/example/example_exporter.go 87.50% <ø> (-1.39%) ⬇️
...duit/plugins/exporters/filewriter/file_exporter.go 81.63% <ø> (-1.06%) ⬇️
conduit/plugins/exporters/noop/noop_exporter.go 73.68% <ø> (-3.59%) ⬇️
conduit/plugins/importers/algod/metrics.go 100.00% <ø> (ø)
...ins/processors/filterprocessor/filter_processor.go 83.82% <ø> (+3.54%) ⬆️
...plugins/processors/filterprocessor/gen/generate.go 34.28% <ø> (ø)
conduit/plugins/processors/noop/noop_processor.go 64.70% <ø> (+6.81%) ⬆️
pkg/cli/internal/list/list.go 20.75% <ø> (ø)
... and 11 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

.markdownlint.yml Outdated Show resolved Hide resolved
@tzaffi tzaffi mentioned this pull request May 29, 2023
.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@tzaffi tzaffi changed the title WIP - enhancement: plugin interface enhancement: plugin interface May 29, 2023
@tzaffi tzaffi marked this pull request as ready for review June 8, 2023 21:14
if err != nil {
return fmt.Errorf("Pipeline.Init(): could not initialize importer (%s): %w", p.cfg.Importer.Name, err)
}
genesis, err := (*p.importer).GetGenesis()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new interface method in use

@@ -55,6 +54,7 @@ type algodImporter struct {
ctx context.Context
cancel context.CancelFunc
mode int
genesis *sdk.Genesis
Copy link
Contributor Author

@tzaffi tzaffi Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache the genesis in the algodImporter struct to avoid having to call the genesis endpoint after Init()

@tzaffi tzaffi requested review from winder and a team June 9, 2023 00:27
conduit/metrics/metrics.go Outdated Show resolved Hide resolved
Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

conduit/metrics/metrics.go Outdated Show resolved Hide resolved
@@ -149,7 +151,8 @@ func TestInitCatchup(t *testing.T) {
targetRound sdk.Round
adminToken string // to trigger fast-catchup
algodServer *httptest.Server
err string
errInit string
errGetGen string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you didn't end up using this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See for example lines 195/196. Sometimes I omitted them when they were "", but if that's confusing I can add these back in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like 195 is also ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit adds in all zero-valued errInit and errGetGen:

b8fef8f

Copy link
Contributor

@winder winder Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that none of these tests define errGetGen to anything besides an empty string, so it could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these observations. My gut was telling me that we need a failure case for full coverage and I half-baked a solution by providing errGetGen. But both of you observed that I didn't actually finish baking the cake. Now it should be all baked: 5b114a0

Copy link
Contributor

@algochoi algochoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleaning

@tzaffi tzaffi merged commit e48bac2 into algorand:master Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants