Skip to content

Commit

Permalink
owner, metrics(ticdc): fix metrics (#10459) (#10513)
Browse files Browse the repository at this point in the history
close #10438, close #10447, close #10449
  • Loading branch information
ti-chi-bot authored Mar 12, 2024
1 parent 0f835ad commit 70447e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cdc/owner/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/pingcap/tiflow/pkg/config"
cdcContext "github.com/pingcap/tiflow/pkg/context"
cerror "github.com/pingcap/tiflow/pkg/errors"
"github.com/pingcap/tiflow/pkg/filter"
pfilter "github.com/pingcap/tiflow/pkg/filter"
"github.com/pingcap/tiflow/pkg/orchestrator"
"github.com/pingcap/tiflow/pkg/pdutil"
Expand Down Expand Up @@ -122,6 +121,9 @@ type changefeed struct {
metricsChangefeedBarrierTsGauge prometheus.Gauge
metricsChangefeedTickDuration prometheus.Observer

metricsChangefeedCreateTimeGuage prometheus.Gauge
metricsChangefeedRestartTimeGauge prometheus.Gauge

newDDLPuller func(ctx context.Context,
replicaConfig *config.ReplicaConfig,
up *upstream.Upstream,
Expand Down Expand Up @@ -536,7 +538,7 @@ LOOP2:
}
c.barriers.Update(finishBarrier, c.state.Info.GetTargetTs())

filter, err := filter.NewFilter(c.state.Info.Config, "")
filter, err := pfilter.NewFilter(c.state.Info.Config, "")
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -636,6 +638,8 @@ LOOP2:
c.initMetrics()

c.initialized = true
c.metricsChangefeedCreateTimeGuage.Set(float64(oracle.GetPhysical(c.state.Info.CreateTime)))
c.metricsChangefeedRestartTimeGauge.Set(float64(oracle.GetPhysical(time.Now())))
log.Info("changefeed initialized",
zap.String("namespace", c.state.ID.Namespace),
zap.String("changefeed", c.state.ID.ID),
Expand Down Expand Up @@ -667,6 +671,11 @@ func (c *changefeed) initMetrics() {
WithLabelValues(c.id.Namespace, c.id.ID)
c.metricsChangefeedTickDuration = changefeedTickDuration.
WithLabelValues(c.id.Namespace, c.id.ID)

c.metricsChangefeedCreateTimeGuage = changefeedStartTimeGauge.
WithLabelValues(c.id.Namespace, c.id.ID, "create")
c.metricsChangefeedRestartTimeGauge = changefeedStartTimeGauge.
WithLabelValues(c.id.Namespace, c.id.ID, "restart")
}

// releaseResources is idempotent.
Expand Down Expand Up @@ -744,6 +753,8 @@ func (c *changefeed) cleanupMetrics() {

if c.isRemoved {
changefeedStatusGauge.DeleteLabelValues(c.id.Namespace, c.id.ID)
changefeedCheckpointTsGauge.DeleteLabelValues(c.id.Namespace, c.id.ID, "create")
changefeedCheckpointTsLagGauge.DeleteLabelValues(c.id.Namespace, c.id.ID, "restart")
}
}

Expand Down
8 changes: 8 additions & 0 deletions cdc/owner/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ var (
Name: "ignored_ddl_event_count",
Help: "The total count of ddl events that are ignored in changefeed.",
}, []string{"namespace", "changefeed"})
changefeedStartTimeGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "ticdc",
Subsystem: "owner",
Name: "changefeed_start_time",
Help: "The start time of changefeeds",
}, []string{"namespace", "changefeed", "type"})
)

const (
Expand Down Expand Up @@ -148,4 +155,5 @@ func InitMetrics(registry *prometheus.Registry) {
registry.MustRegister(changefeedTickDuration)
registry.MustRegister(changefeedCloseDuration)
registry.MustRegister(changefeedIgnoredDDLEventCounter)
registry.MustRegister(changefeedStartTimeGauge)
}

0 comments on commit 70447e5

Please sign in to comment.