Skip to content

Commit

Permalink
stats: add metrics for dynamic update (#6278)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored and zhexuany committed Apr 13, 2018
1 parent 533fac1 commit b51b0de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions metrics/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,29 @@ var (
Name: "pseudo_estimation_total",
Help: "Counter of pseudo estimation caused by outdated stats.",
})

DumpFeedbackCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "statistics",
Name: "dump_feedback_total",
Help: "Counter of dumping feedback.",
}, []string{LblType})

UpdateStatsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "statistics",
Name: "update_stats_total",
Help: "Counter of updating stats using feedback.",
}, []string{LblType})
)

func init() {
prometheus.MustRegister(AutoAnalyzeHistogram)
prometheus.MustRegister(AutoAnalyzeCounter)
prometheus.MustRegister(StatsInaccuracyRate)
prometheus.MustRegister(PseudoEstimation)
prometheus.MustRegister(DumpFeedbackCounter)
prometheus.MustRegister(UpdateStatsCounter)
}
16 changes: 14 additions & 2 deletions statistics/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func (h *Handle) dumpFeedbackToKV(fb *QueryFeedback) error {
sql := fmt.Sprintf("insert into mysql.stats_feedback (table_id, hist_id, is_index, feedback) values "+
"(%d, %d, %d, X'%X')", fb.tableID, fb.hist.ID, isIndex, vals)
_, err = h.ctx.(sqlexec.SQLExecutor).Execute(context.TODO(), sql)
if err != nil {
metrics.DumpFeedbackCounter.WithLabelValues(metrics.LblError).Inc()
} else {
metrics.DumpFeedbackCounter.WithLabelValues(metrics.LblOK).Inc()
}
return errors.Trace(err)
}

Expand Down Expand Up @@ -288,9 +293,16 @@ func (h *Handle) HandleUpdateStats(is infoschema.InfoSchema) error {
return errors.Trace(err)
}

func (h *Handle) dumpStatsUpdateToKV(tableID int64, isIndex int, q *QueryFeedback, hist *Histogram, cms *CMSketch) error {
func (h *Handle) dumpStatsUpdateToKV(tableID int64, isIndex int, q *QueryFeedback, hist *Histogram, cms *CMSketch) (err error) {
defer func() {
if err != nil {
metrics.UpdateStatsCounter.WithLabelValues(metrics.LblError).Inc()
} else {
metrics.UpdateStatsCounter.WithLabelValues(metrics.LblOK).Inc()
}
}()
hist = UpdateHistogram(hist, q)
err := SaveStatsToStorage(h.ctx, tableID, -1, isIndex, hist, cms)
err = SaveStatsToStorage(h.ctx, tableID, -1, isIndex, hist, cms)
if err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit b51b0de

Please sign in to comment.