Skip to content

Commit

Permalink
chore(mads): supplement debug log for snapshot reconcile
Browse files Browse the repository at this point in the history
Signed-off-by: Icarus Wu <icaruswu66@qq.com>
  • Loading branch information
Icarus9913 committed Sep 25, 2024
1 parent 27b3498 commit a667d2c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pkg/mads/v1/reconcile/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"

envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
"github.com/go-logr/logr"
)

// Reconciler re-computes configuration for a given node.
type Reconciler interface {
Reconcile(context.Context) error
Reconcile(context.Context, logr.Logger) error
// NeedsReconciliation checks if there is a valid configuration snapshot already present
// for a given node
NeedsReconciliation(node *envoy_core.Node) bool
Expand Down
5 changes: 4 additions & 1 deletion pkg/mads/v1/reconcile/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_cache "github.com/envoyproxy/go-control-plane/pkg/cache/v3"
"github.com/go-logr/logr"

util_xds_v3 "github.com/kumahq/kuma/pkg/util/xds/v3"
)
Expand Down Expand Up @@ -35,7 +36,7 @@ func (r *reconciler) KnownClientIds() map[string]bool {
return maps.Clone(r.knownClientIds)
}

func (r *reconciler) Reconcile(ctx context.Context) error {
func (r *reconciler) Reconcile(ctx context.Context, log logr.Logger) error {
newSnapshotPerClient, err := r.generator.GenerateSnapshot(ctx)
if err != nil {
return err
Expand All @@ -50,8 +51,10 @@ func (r *reconciler) Reconcile(ctx context.Context) error {
oldSnapshot, _ := r.cache.GetSnapshot(clientId)
switch {
case oldSnapshot == nil:
log.V(2).Info("no snapshot found", "clientId", clientId)
snap = newSnapshot
case !util_xds_v3.SingleTypeSnapshotEqual(oldSnapshot, newSnapshot):
log.V(2).Info("detected changes in the snapshots", "oldSnapshot", oldSnapshot, "newSnapshot", newSnapshot)
snap = newSnapshot
default:
snap = oldSnapshot
Expand Down
9 changes: 5 additions & 4 deletions pkg/mads/v1/service/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

type restReconcilerCallbacks struct {
reconciler mads_reconcile.Reconciler
log logr.Logger
}

func (r *restReconcilerCallbacks) OnFetchRequest(ctx context.Context, request util_xds.DiscoveryRequest) error {
Expand All @@ -34,16 +35,16 @@ func (r *restReconcilerCallbacks) OnFetchRequest(ctx context.Context, request ut
}

if r.reconciler.NeedsReconciliation(node) {
return r.reconciler.Reconcile(ctx)
return r.reconciler.Reconcile(ctx, r.log)
}
return nil
}

func (r *restReconcilerCallbacks) OnFetchResponse(request util_xds.DiscoveryRequest, response util_xds.DiscoveryResponse) {
}

func NewReconcilerRestCallbacks(reconciler mads_reconcile.Reconciler) util_xds.RestCallbacks {
return &restReconcilerCallbacks{reconciler: reconciler}
func NewReconcilerRestCallbacks(reconciler mads_reconcile.Reconciler, log logr.Logger) util_xds.RestCallbacks {
return &restReconcilerCallbacks{reconciler: reconciler, log: log}
}

func NewSyncTracker(reconciler mads_reconcile.Reconciler, refresh time.Duration, log logr.Logger) envoy_xds.Callbacks {
Expand All @@ -55,7 +56,7 @@ func NewSyncTracker(reconciler mads_reconcile.Reconciler, refresh time.Duration,
},
OnTick: func(ctx context.Context) error {
log.V(1).Info("on tick")
return reconciler.Reconcile(ctx)
return reconciler.Reconcile(ctx, log)
},
OnError: func(err error) {
log.Error(err, "OnTick() failed")
Expand Down
2 changes: 1 addition & 1 deletion pkg/mads/v1/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewService(config *mads.MonitoringAssignmentServerConfig, rm core_manager.R
// issue: https://github.com/kumahq/kuma/issues/8764
NewSyncTracker(reconciler, config.AssignmentRefreshInterval.Duration, log),
// For on-demand reconciliation
util_xds_v3.AdaptRestCallbacks(NewReconcilerRestCallbacks(reconciler)),
util_xds_v3.AdaptRestCallbacks(NewReconcilerRestCallbacks(reconciler, log)),
}
srv := NewServer(cache, callbacks)

Expand Down
5 changes: 3 additions & 2 deletions pkg/mads/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/emicklei/go-restful/v3"
envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
"github.com/go-logr/logr"
"github.com/golang/protobuf/jsonpb"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -22,11 +21,13 @@ import (
observability_v1 "github.com/kumahq/kuma/api/observability/v1"
mads_config "github.com/kumahq/kuma/pkg/config/mads"
config_types "github.com/kumahq/kuma/pkg/config/types"
"github.com/kumahq/kuma/pkg/core"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
core_manager "github.com/kumahq/kuma/pkg/core/resources/manager"
"github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/resources/store"
rest_error_types "github.com/kumahq/kuma/pkg/core/rest/errors/types"
"github.com/kumahq/kuma/pkg/log"
mads_v1 "github.com/kumahq/kuma/pkg/mads/v1"
"github.com/kumahq/kuma/pkg/mads/v1/service"
"github.com/kumahq/kuma/pkg/plugins/resources/memory"
Expand Down Expand Up @@ -57,7 +58,7 @@ var _ = Describe("MADS http service", func() {
cfg.AssignmentRefreshInterval = config_types.Duration{Duration: refreshInterval}
cfg.DefaultFetchTimeout = config_types.Duration{Duration: defaultFetchTimeout}

svc := service.NewService(cfg, resManager, logr.Discard(), nil)
svc := service.NewService(cfg, resManager, core.NewLogger(log.DebugLevel), nil)

ws := new(restful.WebService)
svc.RegisterRoutes(ws)
Expand Down

0 comments on commit a667d2c

Please sign in to comment.