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

chore: Add proof monitoring expiry period #1402

Merged
merged 1 commit into from
Jul 20, 2022
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
12 changes: 12 additions & 0 deletions cmd/orb-server/startcmd/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ const (
"Defaults to 10s if not set. " +
commonEnvVarUsageText + vctProofMonitoringIntervalEnvKey

vctProofMonitoringExpiryPeriodFlagName = "vct-proof-monitoring-expiry-period"
vctProofMonitoringExpiryPeriodEnvKey = "VCT_PROOF_MONITORING_EXPIRY_PERIOD"
vctProofMonitoringExpiryPeriodFlagUsage = "Monitoring service will keep checking for this period of time for proof to be included(default 1h). " + commonEnvVarUsageText + vctProofMonitoringExpiryPeriodEnvKey

vctLogMonitoringIntervalFlagName = "vct-log-monitoring-interval"
vctLogMonitoringIntervalEnvKey = "VCT_LOG_MONITORING_INTERVAL"
vctLogMonitoringIntervalFlagUsage = "The interval in which VCT logs are monitored to ensure that they are consistent. " +
Expand Down Expand Up @@ -697,6 +701,7 @@ type orbParameters struct {
maxWitnessDelay time.Duration
maxClockSkew time.Duration
witnessStoreExpiryPeriod time.Duration
proofMonitoringExpiryPeriod time.Duration
syncTimeout uint64
signWithLocalWitness bool
httpSignaturesEnabled bool
Expand Down Expand Up @@ -1309,6 +1314,11 @@ func getOrbParameters(cmd *cobra.Command) (*orbParameters, error) {
return nil, fmt.Errorf("%s: %w", vctProofMonitoringIntervalFlagName, err)
}

proofMonitoringExpiryPeriod, err := getDuration(cmd, vctProofMonitoringExpiryPeriodFlagName, vctProofMonitoringExpiryPeriodEnvKey, defaultProofMonitoringExpiryPeriod)
if err != nil {
return nil, fmt.Errorf("%s: %w", vctProofMonitoringExpiryPeriodFlagName, err)
}

vctLogMonitoringInterval, err := getDuration(cmd, vctLogMonitoringIntervalFlagName, vctLogMonitoringIntervalEnvKey,
defaultVCTLogMonitoringInterval)
if err != nil {
Expand Down Expand Up @@ -1421,6 +1431,7 @@ func getOrbParameters(cmd *cobra.Command) (*orbParameters, error) {
maxWitnessDelay: maxWitnessDelay,
maxClockSkew: maxClockSkew,
witnessStoreExpiryPeriod: witnessStoreExpiryPeriod,
proofMonitoringExpiryPeriod: proofMonitoringExpiryPeriod,
syncTimeout: syncTimeout,
signWithLocalWitness: signWithLocalWitness,
httpSignaturesEnabled: httpSignaturesEnabled,
Expand Down Expand Up @@ -2098,6 +2109,7 @@ func createFlags(startCmd *cobra.Command) {
startCmd.Flags().StringP(anchorSyncIntervalFlagName, anchorSyncIntervalFlagShorthand, "", anchorSyncIntervalFlagUsage)
startCmd.Flags().StringP(anchorSyncMinActivityAgeFlagName, "", "", anchorSyncMinActivityAgeFlagUsage)
startCmd.Flags().StringP(vctProofMonitoringIntervalFlagName, "", "", vctProofMonitoringIntervalFlagUsage)
startCmd.Flags().StringP(vctProofMonitoringExpiryPeriodFlagName, "", "", vctProofMonitoringExpiryPeriodFlagUsage)
startCmd.Flags().StringP(vctLogMonitoringIntervalFlagName, "", "", vctLogMonitoringIntervalFlagUsage)
startCmd.Flags().StringP(vctLogMonitoringMaxTreeSizeFlagName, "", "", vctLogMonitoringMaxTreeSizeFlagUsage)
startCmd.Flags().StringP(vctLogMonitoringGetEntriesRangeFlagName, "", "", vctLogMonitoringGetEntriesRangeFlagUsage)
Expand Down
15 changes: 14 additions & 1 deletion cmd/orb-server/startcmd/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

"github.com/cenkalti/backoff/v4"
backoff "github.com/cenkalti/backoff/v4"
ariesmemstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mem"
"github.com/hyperledger/aries-framework-go/spi/storage"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -733,6 +733,19 @@ func TestStartCmdWithMissingArg(t *testing.T) {
require.Contains(t, err.Error(), "vct-proof-monitoring-interval: invalid value [xxx]")
})

t.Run("VCT proof monitoring expiry period", func(t *testing.T) {
restoreEnv := setEnv(t, vctProofMonitoringExpiryPeriodEnvKey, "xxx")
defer restoreEnv()

startCmd := GetStartCmd()

startCmd.SetArgs(getTestArgs("localhost:8081", "local", "false", databaseTypeMemOption, ""))

err := startCmd.Execute()
require.Error(t, err)
require.Contains(t, err.Error(), "vct-proof-monitoring-expiry-period: invalid value [xxx]")
})

t.Run("VCT log monitoring interval", func(t *testing.T) {
restoreEnv := setEnv(t, vctLogMonitoringIntervalEnvKey, "xxx")
defer restoreEnv()
Expand Down
2 changes: 2 additions & 0 deletions cmd/orb-server/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const (
defaultMaxWitnessDelay = 10 * time.Minute
defaultMaxClockSkew = 1 * time.Minute
defaultWitnessStoreExpiryDelta = 12 * time.Minute
defaultProofMonitoringExpiryPeriod = 1 * time.Hour
defaultSyncTimeout = 1
defaulthttpSignaturesEnabled = true
defaultDidDiscoveryEnabled = false
Expand Down Expand Up @@ -949,6 +950,7 @@ func startOrbServices(parameters *orbParameters) error {
observer, err := observer.New(apConfig.ServiceIRI, providers,
observer.WithDiscoveryDomain(parameters.discoveryDomain),
observer.WithSubscriberPoolSize(parameters.mqParams.observerPoolSize),
observer.WithProofMonitoringExpiryPeriod(parameters.proofMonitoringExpiryPeriod),
)
if err != nil {
return fmt.Errorf("failed to create observer: %w", err)
Expand Down
16 changes: 8 additions & 8 deletions pkg/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ type monitoringSvc interface {
type outboxProvider func() Outbox

type options struct {
discoveryDomain string
subscriberPoolSize int
monitoringSvcExpiry time.Duration
discoveryDomain string
subscriberPoolSize int
proofMonitoringSvcExpiry time.Duration
}

// Option is an option for observer.
Expand All @@ -133,10 +133,10 @@ func WithSubscriberPoolSize(value int) Option {
}
}

// WithMonitoringServiceExpiry sets expiry period for proof monitoring service.
func WithMonitoringServiceExpiry(value time.Duration) Option {
// WithProofMonitoringExpiryPeriod sets expiry period for proof monitoring service.
func WithProofMonitoringExpiryPeriod(value time.Duration) Option {
return func(opts *options) {
opts.monitoringSvcExpiry = value
opts.proofMonitoringSvcExpiry = value
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ type Observer struct {
// New returns a new observer.
func New(serviceIRI *url.URL, providers *Providers, opts ...Option) (*Observer, error) {
optns := &options{
monitoringSvcExpiry: defaultMonitoringSvcExpiry,
proofMonitoringSvcExpiry: defaultMonitoringSvcExpiry,
}

for _, opt := range opts {
Expand All @@ -180,7 +180,7 @@ func New(serviceIRI *url.URL, providers *Providers, opts ...Option) (*Observer,
serviceIRI: serviceIRI,
Providers: providers,
discoveryDomain: optns.discoveryDomain,
monitoringSvcExpiry: optns.monitoringSvcExpiry,
monitoringSvcExpiry: optns.proofMonitoringSvcExpiry,
}

subscriberPoolSize := optns.subscriberPoolSize
Expand Down
2 changes: 1 addition & 1 deletion pkg/observer/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestStartObserver(t *testing.T) {

o, err := New(serviceIRI, providers,
WithDiscoveryDomain("webcas:shared.domain.com"),
WithMonitoringServiceExpiry(20*time.Second),
WithProofMonitoringExpiryPeriod(20*time.Second),
WithSubscriberPoolSize(3))
require.NotNil(t, o)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions test/bdd/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ services:
- MAX_WITNESS_DELAY=25s
- MAX_CLOCK_SKEW=5s
- WITNESS_STORE_EXPIRY_PERIOD=32s
- VCT_PROOF_MONITORING_EXPIRY_PERIOD=5s

# ORB_AUTH_TOKENS_DEF contains the authorization definition for each of the REST endpoints. Format:
#
Expand Down