Skip to content

Commit

Permalink
tidb, domain: schema lease metrics (pingcap#2417)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and shenli committed Jan 9, 2017
1 parent ee9a0fe commit 0066ab6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ func (do *Domain) Reload() error {
}

latestSchemaVersion, err = do.loadInfoSchema(do.infoHandle, schemaVersion, ver.Ver)
loadSchemaDuration.Observe(time.Since(startTime).Seconds())
if err != nil {
loadSchemaCounter.WithLabelValues("failed").Inc()
return errors.Trace(err)
}
loadSchemaCounter.WithLabelValues("succ").Inc()

do.SchemaValidator.Update(ver.Ver, latestSchemaVersion)

Expand Down
42 changes: 42 additions & 0 deletions domain/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2017 PingCAP, Inc.
//
// 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 domain

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

var (
loadSchemaCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "domain",
Name: "load_schema_total",
Help: "Counter of load schema",
}, []string{"type"})

loadSchemaDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "domain",
Name: "load_schema_duration",
Help: "Bucketed histogram of processing time (s) in load schema.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
})
)

func init() {
prometheus.MustRegister(loadSchemaDuration)
prometheus.MustRegister(loadSchemaCounter)
}
8 changes: 8 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ var (
Help: "Bucketed histogram of processing time (s) in running executor.",
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 13),
})
schemaLeaseErrorCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "schema_lease_error_counter",
Help: "Counter of schema lease error",
}, []string{"type"})
)

func init() {
prometheus.MustRegister(sessionExecuteParseDuration)
prometheus.MustRegister(sessionExecuteCompileDuration)
prometheus.MustRegister(sessionExecuteRunDuration)
prometheus.MustRegister(schemaLeaseErrorCounter)
}
2 changes: 2 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ func (s *schemaLeaseChecker) Check(txnTS uint64) error {
case nil:
return nil
case domain.ErrInfoSchemaChanged:
schemaLeaseErrorCounter.WithLabelValues("changed").Inc()
return errors.Trace(err)
default:
schemaLeaseErrorCounter.WithLabelValues("outdated").Inc()
time.Sleep(schemaOutOfDateRetryInterval)
}
}
Expand Down

0 comments on commit 0066ab6

Please sign in to comment.