-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PSL-1231] remove storage-challenge & self-healing stale data
- Loading branch information
Showing
7 changed files
with
157 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package metricscleanup | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pastelnetwork/gonode/common/errgroup" | ||
"github.com/pastelnetwork/gonode/common/errors" | ||
"github.com/pastelnetwork/gonode/common/log" | ||
) | ||
|
||
const ( | ||
runTaskInterval = 24 * time.Hour | ||
) | ||
|
||
var ( | ||
metricsCleanupThreshold = time.Now().UTC().AddDate(0, 0, -7).Format("2006-01-02") | ||
) | ||
|
||
// Run cleans up inactive tickets | ||
|
||
// Run stores the latest block hash and height to DB if not stored already | ||
func (s *metricsCleanupService) Run(ctx context.Context) error { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return errors.Errorf("context done: %w", ctx.Err()) | ||
case <-time.After(runTaskInterval): | ||
group, gctx := errgroup.WithContext(ctx) | ||
group.Go(func() error { | ||
err := s.run(gctx) | ||
if err != nil { | ||
log.WithContext(ctx).WithError(err).Error("error executing metrics cleanup service") | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err := group.Wait(); err != nil { | ||
log.WithContext(gctx).WithError(err).Errorf("run task failed") | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
func (s metricsCleanupService) Stats(_ context.Context) (map[string]interface{}, error) { | ||
//cleanup service stats can be implemented here | ||
return nil, nil | ||
} | ||
|
||
func (s *metricsCleanupService) run(ctx context.Context) error { | ||
err := s.historyDB.RemoveStorageChallengeStaleData(ctx, metricsCleanupThreshold) | ||
if err != nil { | ||
log.WithContext(ctx).WithError(err).Error("error removing storage challenge stale data") | ||
} | ||
log.WithContext(ctx).Info("storage challenge stale data has been removed") | ||
|
||
err = s.historyDB.RemoveSelfHealingStaleData(ctx, metricsCleanupThreshold) | ||
if err != nil { | ||
log.WithContext(ctx).WithError(err).Error("error removing self-healing stale data") | ||
} | ||
log.WithContext(ctx).Info("self-healing stale data has been removed") | ||
|
||
return nil | ||
} |
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,20 @@ | ||
package metricscleanup | ||
|
||
import "github.com/pastelnetwork/gonode/hermes/service/node" | ||
|
||
// Config is the config struct for cleaner-service | ||
type Config struct { | ||
snHost string | ||
snPort int | ||
|
||
sn node.SNClientInterface | ||
} | ||
|
||
// NewConfig sets the configurations for cleaner service | ||
func NewConfig(host string, port int, SN node.SNClientInterface) Config { | ||
return Config{ | ||
snHost: host, | ||
snPort: port, | ||
sn: SN, | ||
} | ||
} |
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,17 @@ | ||
package metricscleanup | ||
|
||
import ( | ||
"github.com/pastelnetwork/gonode/common/storage/queries" | ||
"github.com/pastelnetwork/gonode/hermes/service" | ||
) | ||
|
||
type metricsCleanupService struct { | ||
historyDB queries.LocalStoreInterface | ||
} | ||
|
||
// NewMetricsCleanupService returns a new metric cleanup service | ||
func NewMetricsCleanupService(hDB queries.LocalStoreInterface) (service.SvcInterface, error) { | ||
return &metricsCleanupService{ | ||
historyDB: hDB, | ||
}, nil | ||
} |
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