-
Notifications
You must be signed in to change notification settings - Fork 26
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
Pipelining followups #147
Pipelining followups #147
Changes from all commits
f2bc1a4
18af031
ce344d4
e41924b
b46628f
b7c82a1
b1c2b0b
5c06330
ae1ee48
d7fd948
1e71d1a
497df82
fafc6d7
e08d93a
488f1e8
e9af0bd
873cc83
85714d1
b18d85b
27b2168
fb7ea14
14a64cd
29ed381
78b8447
a4d7376
f96dbc8
d65afb4
f12f4e6
4d0386a
f38ed13
f68c929
35c859c
d635841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package noop | ||
|
||
import ( | ||
"context" | ||
_ "embed" // used to embed config | ||
"fmt" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
sdk "github.com/algorand/go-algorand-sdk/v2/types" | ||
|
||
"github.com/algorand/conduit/conduit/data" | ||
"github.com/algorand/conduit/conduit/plugins" | ||
"github.com/algorand/conduit/conduit/plugins/importers" | ||
) | ||
|
||
// PluginName to use when configuring. | ||
var PluginName = "noop" | ||
|
||
const sleepForGetBlock = 100 * time.Millisecond | ||
|
||
// `noopImporter`s will function without ever erroring. This means they will also process out of order blocks | ||
// which may or may not be desirable for different use cases--it can hide errors in actual importers expecting in order | ||
// block processing. | ||
// The `noopImporter` will maintain `Round` state according to the round of the last block it processed. | ||
// It also sleeps 100 milliseconds between blocks to slow down the pipeline. | ||
type noopImporter struct { | ||
round uint64 | ||
cfg ImporterConfig | ||
} | ||
|
||
//go:embed sample.yaml | ||
var sampleConfig string | ||
|
||
var metadata = plugins.Metadata{ | ||
Name: PluginName, | ||
Description: "noop importer", | ||
Deprecated: false, | ||
SampleConfig: sampleConfig, | ||
} | ||
|
||
func (imp *noopImporter) Metadata() plugins.Metadata { | ||
return metadata | ||
} | ||
|
||
func (imp *noopImporter) Init(_ context.Context, _ data.InitProvider, cfg plugins.PluginConfig, _ *logrus.Logger) error { | ||
if err := cfg.UnmarshalConfig(&imp.cfg); err != nil { | ||
return fmt.Errorf("init failure in unmarshalConfig: %v", err) | ||
} | ||
imp.round = imp.cfg.Round | ||
return nil | ||
} | ||
|
||
func (imp *noopImporter) Close() error { | ||
return nil | ||
} | ||
|
||
func (imp *noopImporter) GetGenesis() (*sdk.Genesis, error) { | ||
return &sdk.Genesis{}, nil | ||
} | ||
|
||
func (imp *noopImporter) GetBlock(rnd uint64) (data.BlockData, error) { | ||
time.Sleep(sleepForGetBlock) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the sleep? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to slow down the pipeline. For example, if you have a no-op for your importer and a file-writer for your exporter this limits the output to 10 blocks per second which is a little easier to manage than without having any sort of brakes on. Another option is to make this configurable, but that didn't strike me as ideal either since I'd like the no-op importer to have no config. LMK. |
||
imp.round = rnd | ||
return data.BlockData{ | ||
BlockHeader: sdk.BlockHeader{ | ||
Round: sdk.Round(rnd), | ||
}, | ||
}, nil | ||
} | ||
|
||
func (imp *noopImporter) Round() uint64 { | ||
return imp.round | ||
} | ||
|
||
func init() { | ||
importers.Register(PluginName, importers.ImporterConstructorFunc(func() importers.Importer { | ||
return &noopImporter{} | ||
})) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package noop | ||
|
||
// ImporterConfig specific to the noop importer | ||
type ImporterConfig struct { | ||
// Optionally specify the round to start on | ||
Round uint64 `yaml:"round"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: noop | ||
# noop has no config | ||
config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the health endpoint bugfix.