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

Log polling interval can be configured #277

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/omniwitness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ To enable this, two flags must be passed to `omniwitness`:
1. `--bastion_addr` is the `host:port` of the bastion host to connect to.
1. `--bastion_key_path` is the path to a file containing an ed25519 private key in PKCS8 PEM format.

To run the witness in bastion-only mode, set the `--poll_interval` flag to 0.
This will disable all attempts to poll logs, and witnessing will only occur via bastion connections.

Although the witness key _could_ be reused, it's strongly recommended to use a separate key for this. Such a key can be generated with the following command:

```bash
Expand Down
3 changes: 3 additions & 0 deletions cmd/omniwitness/monolith.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (
bastionKeyPath = flag.String("bastion_key_path", "", "Path to a file containing an ed25519 private key in PKCS8 PEM format")
bastionRateLimit = flag.Float64("bastion_rate_limit", 20, "Maximum number of bastion requests per second to serve")
httpTimeout = flag.Duration("http_timeout", 10*time.Second, "HTTP timeout for outbound requests")

pollInterval = flag.Duration("poll_interval", 1*time.Minute, "Time to wait between polling logs for new checkpoints. Set to 0 to disable polling logs.")
)

func main() {
Expand Down Expand Up @@ -107,6 +109,7 @@ func main() {
BastionAddr: *bastionAddr,
BastionKey: bastionKey,
BastionRateLimit: *bastionRateLimit,
FeedInterval: *pollInterval,
}
var p persistence.LogStatePersistence
if len(*dbFile) > 0 {
Expand Down
25 changes: 11 additions & 14 deletions omniwitness/omniwitness.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type LogStateReadOps = persistence.LogStateReadOps
type LogStateWriteOps = persistence.LogStateWriteOps

const (
// Interval between attempts to feed checkpoints
// TODO(mhutchinson): Make this configurable
defaultFeedInterval = 1 * time.Minute
defaultDistributeInterval = 1 * time.Minute
)

Expand Down Expand Up @@ -142,24 +139,24 @@ func Main(ctx context.Context, operatorConfig OperatorConfig, p LogStatePersiste
return fmt.Errorf("failed to create witness: %v", err)
}

if operatorConfig.FeedInterval == 0 {
operatorConfig.FeedInterval = defaultFeedInterval
}
if operatorConfig.DistributeInterval == 0 {
operatorConfig.DistributeInterval = defaultDistributeInterval
}

bw := witnessAdapter{
w: witness,
}
for c, f := range feeders {
c, f := c, f
// Continually feed this log in its own goroutine, hooked up to the global waitgroup.
g.Go(func() error {
klog.Infof("Feeder %q goroutine started", c.Origin)
defer klog.Infof("Feeder %q goroutine done", c.Origin)
return f(ctx, c, bw, httpClient, operatorConfig.FeedInterval)
})

if operatorConfig.FeedInterval > 0 {
for c, f := range feeders {
c, f := c, f
// Continually feed this log in its own goroutine, hooked up to the global waitgroup.
g.Go(func() error {
klog.Infof("Feeder %q goroutine started", c.Origin)
defer klog.Infof("Feeder %q goroutine done", c.Origin)
return f(ctx, c, bw, httpClient, operatorConfig.FeedInterval)
})
}
}

if operatorConfig.BastionAddr != "" && operatorConfig.BastionKey != nil {
Expand Down
Loading