Unverified Commit 59cfaba0 authored by Afzal Ansari's avatar Afzal Ansari Committed by GitHub
Browse files

Refactors logging in `pkg/dashboard/ttlcontroller` (#2913)


* adds pkg level log
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

changes the import pkg
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

Aquires the log from pkg
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

Adds suggestion
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

Aquires logger in constructor
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

fixes lint issues
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

* Adds dependency injection framework to add with name ttlc
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

* reformats the methods param
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

* rebases the master
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

* reverts the changes
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>

* minor fixes
Signed-off-by: default avatarafzal442 <afzal442@gmail.com>
Co-authored-by: default avatarSTRRL <str_ruiling@outlook.com>
Co-authored-by: default avatarTi Chi Robot <ti-community-prow-bot@tidb.io>
Showing with 32 additions and 8 deletions
+32 -8
......@@ -91,7 +91,7 @@ func main() {
},
store.NewDBStore,
collector.NewServer,
ttlcontroller.NewController,
ttlcontroller.Bootstrap,
),
store.Module,
apiserver.Module,
......
// Copyright Chaos Mesh Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ttlcontroller
import (
"github.com/go-logr/logr"
"github.com/chaos-mesh/chaos-mesh/pkg/dashboard/core"
)
func Bootstrap(experiment core.ExperimentStore, event core.EventStore, schedule core.ScheduleStore, workflow core.WorkflowStore, ttlc *TTLConfig, logger logr.Logger) *Controller {
return NewController(experiment, event, schedule, workflow, ttlc, logger.WithName("ttlcontroller"))
}
......@@ -19,19 +19,16 @@ import (
"context"
"time"
"github.com/go-logr/logr"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/chaos-mesh/chaos-mesh/pkg/dashboard/core"
)
var (
log = ctrl.Log.WithName("ttlcontroller")
)
// Controller defines the database ttl controller
type Controller struct {
logger logr.Logger
experiment core.ExperimentStore
event core.EventStore
schedule core.ScheduleStore
......@@ -60,6 +57,7 @@ func NewController(
schedule core.ScheduleStore,
workflow core.WorkflowStore,
ttlc *TTLConfig,
logger logr.Logger,
) *Controller {
return &Controller{
experiment: experiment,
......@@ -67,6 +65,7 @@ func NewController(
schedule: schedule,
workflow: workflow,
ttlconfig: ttlc,
logger: logger,
}
}
......@@ -74,14 +73,14 @@ func NewController(
func Register(ctx context.Context, c *Controller) {
defer utilruntime.HandleCrash()
log.Info("Starting database TTL controller")
c.logger.Info("Starting database TTL controller")
go wait.Until(c.runWorker, c.ttlconfig.DatabaseTTLResyncPeriod, ctx.Done())
}
// runWorker is a long-running function that will be called in order to delete the events, archives, schedule, and workflow.
func (c *Controller) runWorker() {
log.Info("Deleting expired data from the database")
c.logger.Info("Deleting expired data from the database")
ctx := context.Background()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment