Skip to content
Open
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
32 changes: 10 additions & 22 deletions api/middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,24 @@ func TestLogMiddlewareMasksCredentialQuery(t *testing.T) {
LogMiddleware()(c)

restore()
require.Len(t, observed.All(), 1)
query := observed.All()[0].ContextMap()["query"].(string)
require.NotContains(t, query, "secret-value")
require.NotContains(t, query, "bare-key-material")
require.NotContains(t, query, "fragment-secret-value")
if mode == cerrors.RedactLogDisable {
entries := observed.All()
require.Len(t, entries, 1)
query := entries[0].ContextMap()["query"].(string)
switch mode {
case cerrors.RedactLogDisable:
require.Contains(t, query, "key=xxxxx")
require.Contains(t, query, "region=west")
require.Contains(t, query, "keyspace=xxxxx")
require.Contains(t, query, "region=west")
require.Contains(t, query, "#token=xxxxx")
case cerrors.RedactLogMarker:
require.Equal(t, "‹key=xxxxx&keyspace=xxxxx&region=west&token=xxxxx#token=xxxxx›", query)
case cerrors.RedactLogEnable:
require.Equal(t, "?", query)
}
}
}

func TestForwardToServer(t *testing.T) {
core, observed := observer.New(zapcore.InfoLevel)
restore := plog.ReplaceGlobals(zap.New(core), nil)
defer restore()

// Setup mock target server
targetServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Verify received headers
Expand Down Expand Up @@ -99,17 +98,6 @@ func TestForwardToServer(t *testing.T) {
require.Equal(t, http.StatusOK, w.Code)
require.Equal(t, "test-value", w.Header().Get("X-Test-Header"))
require.Equal(t, "test response", w.Body.String())
var loggedURL string
for _, entry := range observed.All() {
if entry.Message == "forwarding request to another server" {
loggedURL = entry.ContextMap()["url"].(string)
break
}
}
require.NotEmpty(t, loggedURL)
require.Contains(t, loggedURL, "region=west")
require.NotContains(t, loggedURL, "forward-secret-value")
require.Contains(t, loggedURL, "token=xxxxx")
}

func TestForwardToServerExceedMaxForwardTimes(t *testing.T) {
Expand Down
8 changes: 6 additions & 2 deletions api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func (o *OpenAPIV1) createChangefeed(c *gin.Context) {
c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonData))
c.Request.ContentLength = int64(len(jsonData))

log.Info("create changefeed api v1", zap.String("changefeedID", changefeedConfig.ID))
log.Info("create changefeed api v1",
zap.String("keyspace", changefeedConfig.Keyspace),
zap.String("changefeedID", changefeedConfig.ID))

o.v2.CreateChangefeed(c)
}
Expand All @@ -136,7 +138,9 @@ func (o *OpenAPIV1) updateChangefeed(c *gin.Context) {
c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonData))
c.Request.ContentLength = int64(len(jsonData))

log.Info("update changefeed api v1", zap.String("changefeedID", changefeedConfig.ID))
log.Info("update changefeed api v1",
zap.String("keyspace", changefeedConfig.Keyspace),
zap.String("changefeedID", changefeedConfig.ID))
o.v2.UpdateChangefeed(c)
}

Expand Down
20 changes: 16 additions & 4 deletions api/v2/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ func (h *OpenAPIV2) CreateChangefeed(c *gin.Context) {
)
if undoErr != nil {
log.Warn("undo ensure changefeed start ts safety failed when creating the changefeed",
zap.String("changefeedID", changefeedID.Name()), zap.Uint64("startTs", cfg.StartTs),
zap.String("keyspace", changefeedID.Keyspace()),
zap.String("changefeed", changefeedID.Name()),
zap.Uint64("startTs", cfg.StartTs),
zap.String("gcServiceID", createGcServiceID),
zap.Error(undoErr))
}
Expand Down Expand Up @@ -341,6 +343,7 @@ func (h *OpenAPIV2) CreateChangefeed(c *gin.Context) {
}

log.Info("create changefeed successfully",
zap.String("keyspace", info.ChangefeedID.Keyspace()),
zap.String("changefeedID", info.ChangefeedID.Name()),
zap.String("state", string(info.State)),
zap.String("changefeedInfo", info.String()),
Expand Down Expand Up @@ -819,7 +822,10 @@ func (h *OpenAPIV2) ResumeChangefeed(c *gin.Context) {
log.Info("resume changefeed config is empty, using defaults")
} else {
if err = json.Unmarshal(body, cfg); err != nil {
log.Error("failed to bind resume changefeed config", zap.Error(err), zap.String("body", string(body)))
log.Error("failed to bind resume changefeed config",
zap.String("contentType", c.ContentType()),
zap.Int("bodyLength", len(body)),
zap.Error(err))
_ = c.Error(errors.WrapError(errors.ErrAPIInvalidParam, err))
return
}
Expand Down Expand Up @@ -919,7 +925,9 @@ func (h *OpenAPIV2) ResumeChangefeed(c *gin.Context) {
)
if undoErr != nil {
log.Warn("undo ensure changefeed start ts safety failed when resuming the changefeed",
zap.String("changefeedID", cfInfo.ChangefeedID.Name()), zap.Uint64("startTs", newCheckpointTs),
zap.String("keyspace", cfInfo.ChangefeedID.Keyspace()),
zap.String("changefeedID", cfInfo.ChangefeedID.Name()),
zap.Uint64("startTs", newCheckpointTs),
zap.String("gcServiceID", resumeGcServiceID),
zap.Error(undoErr))
}
Expand Down Expand Up @@ -972,6 +980,7 @@ func (h *OpenAPIV2) ResumeChangefeed(c *gin.Context) {
}
c.Errors = nil
log.Info("resume changefeed successfully",
zap.String("keyspace", cfInfo.ChangefeedID.Keyspace()),
zap.String("changefeedID", cfInfo.ChangefeedID.Name()),
zap.String("state", string(cfInfo.State)),
zap.String("changefeedInfo", cfInfo.String()),
Expand Down Expand Up @@ -1652,7 +1661,10 @@ func (h *OpenAPIV2) getDispatcherCount(c *gin.Context) {
maintainer, ok := maintainerManager.GetMaintainerForChangefeed(changefeedID)

if !ok {
log.Error("maintainer not found for changefeed in this node", zap.String("GID", changefeedID.Id.String()), zap.String("changefeed", changefeedID.String()))
log.Error("maintainer not found for changefeed in this node",
zap.String("keyspace", changefeedID.Keyspace()),
zap.String("changefeedID", changefeedID.Name()),
zap.String("GID", changefeedID.Id.String()))
_ = c.Error(errors.ErrMaintainerNotFounded)
return
}
Expand Down
13 changes: 9 additions & 4 deletions coordinator/changefeed/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (m *Backoff) checkFailedStatus(status *heartbeatpb.MaintainerStatus) (bool,
m.checkpointTs = status.CheckpointTs
}
log.Error("changefeed maintainer report a fast fail error",
zap.Stringer("changefeed", m.id),
zap.String("keyspace", m.id.Keyspace()),
zap.String("changefeed", m.id.Name()),
zap.Uint64("checkpointTs", m.checkpointTs),
zap.String("node", err.Node),
zap.String("code", err.Code),
Expand Down Expand Up @@ -172,13 +173,15 @@ func (m *Backoff) CheckStatus(status *heartbeatpb.MaintainerStatus) (bool, confi
if m.isRestarting.Load() {
// FIXME: What does ignore the error mean?
log.Info("changefeed is already in restarting progress, ignore the error",
zap.String("keyspace", m.id.Keyspace()),
zap.String("changefeed", m.id.Name()),
zap.Any("err", status.Err[len(status.Err)-1].Message),
)
}

log.Error("changefeed maintainer report an error",
zap.Stringer("changefeed", m.id),
zap.String("keyspace", m.id.Keyspace()),
zap.String("changefeed", m.id.Name()),
zap.Uint64("checkpointTs", m.checkpointTs),
zap.String("node", status.Err[len(status.Err)-1].Node),
zap.String("code", status.Err[len(status.Err)-1].Code),
Expand Down Expand Up @@ -232,15 +235,17 @@ func (m *Backoff) HandleError(errs []*heartbeatpb.RunningError) (bool, *heartbea
log.Error("The changefeed won't be restarted as it has been experiencing failures for "+
"an extended duration",
zap.Duration("maxElapsedTime", m.errBackoff.MaxElapsedTime),
zap.Stringer("changefeed", m.id),
zap.String("keyspace", m.id.Keyspace()),
zap.String("changefeed", m.id.Name()),
zap.Uint64("checkpointTs", m.checkpointTs),
zap.Time("nextRetryTime", m.nextRetryTime.Load()),
)
return true, lastError
}
// if any error is occurred , we should set the changefeed state to warning and stop the changefeed
log.Warn("changefeed meets an error, will be stopped",
zap.Stringer("changefeed", m.id),
zap.String("keyspace", m.id.Keyspace()),
zap.String("changefeed", m.id.Name()),
zap.Uint64("checkpointTs", m.checkpointTs),
zap.Time("nextRetryTime", m.nextRetryTime.Load()),
zap.Any("error", errs))
Expand Down
17 changes: 12 additions & 5 deletions coordinator/changefeed/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ func NewChangefeed(cfID common.ChangeFeedID,
isNew bool,
) *Changefeed {
if info == nil {
log.Panic("changefeed info is nil", zap.Stringer("changefeedID", cfID))
log.Panic("changefeed info is nil",
zap.String("keyspace", cfID.Keyspace()),
zap.String("changefeed", cfID.Name()))
}
if info.Config == nil {
log.Panic("changefeed config is nil", zap.Stringer("changefeedID", cfID))
log.Panic("changefeed config is nil",
zap.String("keyspace", cfID.Keyspace()),
zap.String("changefeed", cfID.Name()))
}
sinkType, _ := config.ParseSinkURI(info.SinkURI)
res := &Changefeed{
Expand All @@ -84,8 +88,8 @@ func NewChangefeed(cfID common.ChangeFeedID,
}

log.Info("changefeed instance created",
zap.String("id", cfID.String()),
zap.Uint64("checkpointTs", checkpointTs),
zap.String("id", cfID.String()),
zap.String("state", string(info.State)),
zap.String("info", info.String()))
return res
Expand All @@ -107,7 +111,9 @@ func (c *Changefeed) SetInfo(info *config.ChangeFeedInfo) {
return
}
if info == nil {
log.Panic("changefeed info is nil", zap.Stringer("changefeedID", c.ID))
log.Panic("changefeed info is nil",
zap.String("keyspace", c.ID.Keyspace()),
zap.String("changefeed", c.ID.Name()))
}
if c.info == nil {
c.info = atomic.NewPointer(info)
Expand Down Expand Up @@ -193,7 +199,8 @@ func (c *Changefeed) UpdateStatus(newStatus *heartbeatpb.MaintainerStatus) (bool
// Record accepted progress before returning without CheckStatus.
c.backoff.checkpointTs = newStatus.CheckpointTs
log.Info("Received changefeed status with bootstrapDone",
zap.Stringer("changefeed", c.ID),
zap.String("keyspace", c.ID.Keyspace()),
zap.String("changefeed", c.ID.Name()),
zap.Bool("bootstrapDone", newStatus.BootstrapDone))
return true, config.StateNormal, nil
}
Expand Down
29 changes: 20 additions & 9 deletions coordinator/changefeed/changefeed_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func (db *ChangefeedDB) AddReplicatingMaintainer(task *Changefeed, nodeID node.I

task.SetNodeID(nodeID)
log.Info("add an replicating maintainer",
zap.String("nodeID", nodeID.String()),
zap.String("changefeed", task.ID.String()))
zap.String("keyspace", task.ID.Keyspace()),
zap.String("changefeed", task.ID.Name()),
zap.String("nodeID", nodeID.String()))

db.changefeeds[task.ID] = task
db.changefeedDisplayNames[task.ID.DisplayName] = task.ID
Expand Down Expand Up @@ -132,7 +133,9 @@ func (db *ChangefeedDB) StopByChangefeedID(cfID common.ChangeFeedID, remove bool
}

if remove {
log.Info("remove changefeed", zap.String("changefeed", cf.ID.String()))
log.Info("remove changefeed",
zap.String("keyspace", cf.ID.Keyspace()),
zap.String("changefeed", cf.ID.Name()))
delete(db.changefeeds, cfID)
delete(db.changefeedDisplayNames, cf.ID.DisplayName)
delete(db.stopped, cfID)
Expand All @@ -147,7 +150,9 @@ func (db *ChangefeedDB) StopByChangefeedID(cfID common.ChangeFeedID, remove bool
)
}
} else {
log.Info("stop changefeed", zap.String("changefeed", cfID.String()))
log.Info("stop changefeed",
zap.String("keyspace", cfID.Keyspace()),
zap.String("changefeed", cfID.Name()))
db.stopped[cfID] = cf
}

Expand Down Expand Up @@ -215,7 +220,8 @@ func (db *ChangefeedDB) BindChangefeedToNode(old, new node.ID, task *Changefeed)
defer db.lock.Unlock()

log.Info("bind changefeed to node",
zap.String("changefeed", task.ID.String()),
zap.String("keyspace", task.ID.Keyspace()),
zap.String("changefeed", task.ID.Name()),
zap.String("oldNode", old.String()),
zap.String("node", new.String()))
db.BindReplicaToNodeWithoutLock(old, new, task)
Expand All @@ -227,7 +233,8 @@ func (db *ChangefeedDB) MarkMaintainerReplicating(task *Changefeed) {
defer db.lock.Unlock()

log.Info("marking changefeed replicating",
zap.String("changefeed", task.ID.String()))
zap.String("keyspace", task.ID.Keyspace()),
zap.String("changefeed", task.ID.Name()))
db.MarkReplicatingWithoutLock(task)
task.StartFinished()
}
Expand Down Expand Up @@ -291,7 +298,8 @@ func (db *ChangefeedDB) MoveToSchedulingQueue(
cf.SetIsNew(overwriteCheckpointTs || (info != nil && util.GetOrZero(info.BootstrapPending)))
db.AddAbsentWithoutLock(cf)
log.Info("move a changefeed to scheduling queue, it will be scheduled later",
zap.Stringer("changefeed", id),
zap.String("keyspace", id.Keyspace()),
zap.String("changefeed", id.Name()),
zap.Uint64("checkpointTs", cf.GetStatus().CheckpointTs),
zap.Bool("overwriteCheckpointTs", overwriteCheckpointTs),
zap.Time("nextScheduleTime", cf.backoff.nextRetryTime.Load()),
Expand All @@ -309,7 +317,8 @@ func (db *ChangefeedDB) MarkMaintainerAbsent(cf *Changefeed) {
defer db.lock.Unlock()

log.Info("marking changefeed absent",
zap.String("changefeed", cf.ID.String()),
zap.String("keyspace", cf.ID.Keyspace()),
zap.String("changefeed", cf.ID.Name()),
zap.String("node", cf.GetNodeID().String()))
db.MarkAbsentWithoutLock(cf)
}
Expand Down Expand Up @@ -382,7 +391,9 @@ func (db *ChangefeedDB) ReplaceStoppedChangefeed(cf *config.ChangeFeedInfo) {

oldCf := db.stopped[cf.ChangefeedID]
if oldCf == nil {
log.Warn("changefeed is not stopped, can not be updated", zap.String("changefeed", cf.ChangefeedID.String()))
log.Warn("changefeed is not stopped, can not be updated",
zap.String("keyspace", cf.ChangefeedID.Keyspace()),
zap.String("changefeed", cf.ChangefeedID.Name()))
return
}
// todo: not create a new changefeed here?
Expand Down
Loading
Loading