Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: Add prometheus metrics #1738

Merged
merged 4 commits into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
package ddl

import (
"strconv"
"time"

"github.com/juju/errors"
"github.com/ngaut/log"
"github.com/pingcap/tidb/ast"
Expand Down Expand Up @@ -307,21 +310,25 @@ func (d *ddl) backfillColumn(t table.Table, columnInfo *model.ColumnInfo, reorgI
count := 0

for {
startTS := time.Now()
handles, err := d.getSnapshotRows(t, version, seekHandle)
if err != nil {
return errors.Trace(err)
} else if len(handles) == 0 {
return nil
}

count += len(handles)
seekHandle = handles[len(handles)-1] + 1
sub := time.Since(startTS).Seconds()
err = d.backfillColumnData(t, columnInfo, handles, reorgInfo)
if err != nil {
log.Warnf("[ddl] added column for %v rows failed, take time %v", count, sub)
return errors.Trace(err)
}

count += len(handles)
log.Infof("[ddl] added column for %v rows", count)
batchHandleDataHistogram.WithLabelValues(batchAddCol, strconv.Itoa(len(handles))).Observe(sub)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem no need to use len(handles) as label value.

log.Infof("[ddl] added column for %v rows, take time %v", count, sub)
}
}

Expand Down
18 changes: 13 additions & 5 deletions ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (d *ddl) doDDLJob(ctx context.Context, job *model.Job) error {
err = t.EnQueueDDLJob(job)
return errors.Trace(err)
})

if err != nil {
return errors.Trace(err)
}
Expand All @@ -53,14 +52,23 @@ func (d *ddl) doDDLJob(ctx context.Context, job *model.Job) error {

log.Warnf("[ddl] start DDL job %v", job)

jobID := job.ID

var historyJob *model.Job

jobID := job.ID
// for a job from start to end, the state of it will be none -> delete only -> write only -> reorganization -> public
// for every state changes, we will wait as lease 2 * lease time, so here the ticker check is 10 * lease.
ticker := time.NewTicker(chooseLeaseTime(10*d.lease, 10*time.Second))
defer ticker.Stop()
startTS := time.Now()
jobsGauge.WithLabelValues(JobType(ddlJobFlag).String(), job.Type.String()).Inc()
defer func() {
ticker.Stop()
jobsGauge.WithLabelValues(JobType(ddlJobFlag).String(), job.Type.String()).Desc()
retLabel := handleJobSucc
if err != nil {
retLabel = handleJobFailed
}
handleJobHistogram.WithLabelValues(JobType(ddlJobFlag).String(), job.Type.String(),
retLabel).Observe(time.Since(startTS).Seconds())
}()
for {
select {
case <-d.ddlJobDoneCh:
Expand Down
12 changes: 10 additions & 2 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
package ddl

import (
"strconv"
"time"

"github.com/juju/errors"
"github.com/ngaut/log"
"github.com/pingcap/tidb/ast"
Expand Down Expand Up @@ -350,21 +353,26 @@ func (d *ddl) addTableIndex(t table.Table, indexInfo *model.IndexInfo, reorgInfo
count := 0

for {
startTS := time.Now()
handles, err := d.getSnapshotRows(t, version, seekHandle)
if err != nil {
return errors.Trace(err)
} else if len(handles) == 0 {
return nil
}

count += len(handles)
seekHandle = handles[len(handles)-1] + 1
err = d.backfillTableIndex(t, indexInfo, handles, reorgInfo)
sub := time.Since(startTS).Seconds()
if err != nil {
log.Warnf("[ddl] added index for %v rows failed, take time %v", count, sub)
return errors.Trace(err)
}

count += len(handles)
log.Infof("[ddl] added index for %v rows", count)
batchHandleDataHistogram.WithLabelValues(batchAddIdx, strconv.Itoa(len(handles))).Observe(sub)
log.Infof("[ddl] added index for %v rows, take time %v", count, sub)

}
}

Expand Down
57 changes: 57 additions & 0 deletions ddl/metrcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2016 PingCAP, Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the filename should be "metrics"

//
// 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,
// See the License for the specific language governing permissions and
// limitations under the License.

package ddl

import "github.com/prometheus/client_golang/prometheus"

var (
jobsGauge = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "ddl",
Name: "waiting_jobs",
Help: "Gauge of jobs.",
}, []string{"job_type", "action_type"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type, action


// handle job result state.
handleJobSucc = "handle_job_succ"
handleJobFailed = "handle_job_failed"
handleJobHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "ddl",
Name: "handle_job_duration_seconds",
Help: "Bucketed histogram of processing time (s) of handle jobs",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
}, []string{"job_type", "action_type", "result_state"})

// handle batch data type.
batchAddCol = "batch_add_col"
batchAddIdx = "batch_add_idx"
batchDelData = "batch_del_data"
batchHandleDataHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "ddl",
Name: "batch_add_or_del_data_succ",
Help: "Bucketed histogram of processing time (s) of batch handle data",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
}, []string{"handle_data_type", "batch_rows"})
)

func init() {
prometheus.MustRegister(jobsGauge)
prometheus.MustRegister(handleJobHistogram)
prometheus.MustRegister(batchHandleDataHistogram)
}
8 changes: 6 additions & 2 deletions ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package ddl

import (
"fmt"
"strconv"
"time"

"github.com/juju/errors"
Expand Down Expand Up @@ -173,6 +174,7 @@ func (d *ddl) delKeysWithPrefix(prefix kv.Key, jobType JobType) error {
count := 0

for {
startTS := time.Now()
keys := make([]kv.Key, 0, maxBatchSize)
err := kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
if err1 := d.isReorgRunnable(txn, jobType); err1 != nil {
Expand Down Expand Up @@ -209,12 +211,14 @@ func (d *ddl) delKeysWithPrefix(prefix kv.Key, jobType JobType) error {
count += len(keys)
return nil
})

sub := time.Since(startTS).Seconds()
if err != nil {
log.Warnf("[ddl] deleted %v keys with prefix %q failed, take time %v", count, prefix, sub)
return errors.Trace(err)
}

log.Infof("[ddl] deleted %v keys with prefix %q", count, prefix)
batchHandleDataHistogram.WithLabelValues(batchDelData, strconv.Itoa(len(keys))).Observe(sub)
log.Infof("[ddl] deleted %v keys with prefix %q take time %v", count, prefix, sub)
// delete no keys, return.
if len(keys) == 0 {
return nil
Expand Down