Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2021-09-03 17:33:59 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-09-30 15:05:49 +0300
commit67bbe804fb63129d03522aeea515ed23af67aad8 (patch)
treeb9eedf15c7b245eca263612e3d035c59299145c1
parent007ebf28debb3b201ffc7e5d081bbe5e76a8b9fd (diff)
repoclean: Log warning for missed repositories
For each repository that is not know to praefect but that exists on one of the gitaly nodes in the cluster the warning message will be logged with the info about virtual storage and gitaly node as well as relative path to the missing repository. Based on this info admin could remove the repository if it is a garbage or propagate it to the praefect, so it becomes available for serving. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/3719
-rw-r--r--internal/praefect/repocleaner/action_log.go33
-rw-r--r--internal/praefect/repocleaner/action_log_test.go48
2 files changed, 81 insertions, 0 deletions
diff --git a/internal/praefect/repocleaner/action_log.go b/internal/praefect/repocleaner/action_log.go
new file mode 100644
index 000000000..934d69c49
--- /dev/null
+++ b/internal/praefect/repocleaner/action_log.go
@@ -0,0 +1,33 @@
+package repocleaner
+
+import (
+ "context"
+
+ "github.com/sirupsen/logrus"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore"
+)
+
+// LogWarnAction is an implementation of the Action interface that allows to log a warning message
+// for the repositories that are not known for the praefect.
+type LogWarnAction struct {
+ logger logrus.FieldLogger
+}
+
+// NewLogWarnAction return new instance of the LogWarnAction.
+func NewLogWarnAction(logger logrus.FieldLogger) *LogWarnAction {
+ return &LogWarnAction{
+ logger: logger.WithField("component", "repocleaner.log_warn_action"),
+ }
+}
+
+// Perform logs a warning for each repository that is not known to praefect.
+func (al LogWarnAction) Perform(_ context.Context, notExisting []datastore.RepositoryClusterPath) error {
+ for _, entry := range notExisting {
+ al.logger.WithFields(logrus.Fields{
+ "virtual_storage": entry.VirtualStorage,
+ "storage": entry.Storage,
+ "relative_replica_path": entry.RelativeReplicaPath,
+ }).Warn("repository is not managed by praefect")
+ }
+ return nil
+}
diff --git a/internal/praefect/repocleaner/action_log_test.go b/internal/praefect/repocleaner/action_log_test.go
new file mode 100644
index 000000000..1c7af50b2
--- /dev/null
+++ b/internal/praefect/repocleaner/action_log_test.go
@@ -0,0 +1,48 @@
+package repocleaner
+
+import (
+ "context"
+ "testing"
+
+ "github.com/sirupsen/logrus"
+ "github.com/sirupsen/logrus/hooks/test"
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore"
+)
+
+func TestLogWarnAction_Perform(t *testing.T) {
+ logger, hook := test.NewNullLogger()
+ action := NewLogWarnAction(logger)
+ err := action.Perform(context.TODO(), []datastore.RepositoryClusterPath{
+ {ClusterPath: datastore.ClusterPath{VirtualStorage: "vs1", Storage: "g1"}, RelativeReplicaPath: "p/1"},
+ {ClusterPath: datastore.ClusterPath{VirtualStorage: "vs2", Storage: "g2"}, RelativeReplicaPath: "p/2"},
+ })
+ require.NoError(t, err)
+ require.Len(t, hook.AllEntries(), 2)
+
+ exp := []map[string]interface{}{{
+ "Data": logrus.Fields{
+ "component": "repocleaner.log_warn_action",
+ "virtual_storage": "vs1",
+ "storage": "g1",
+ "relative_replica_path": "p/1",
+ },
+ "Message": "repository is not managed by praefect",
+ }, {
+ "Data": logrus.Fields{
+ "component": "repocleaner.log_warn_action",
+ "virtual_storage": "vs2",
+ "storage": "g2",
+ "relative_replica_path": "p/2",
+ },
+ "Message": "repository is not managed by praefect",
+ }}
+
+ require.ElementsMatch(t, exp, []map[string]interface{}{{
+ "Data": hook.AllEntries()[0].Data,
+ "Message": hook.AllEntries()[0].Message,
+ }, {
+ "Data": hook.AllEntries()[1].Data,
+ "Message": hook.AllEntries()[1].Message,
+ }})
+}