зеркало из https://github.com/github/vitess-gh.git
WIP fix for table names with dots in them.
- Crashed vttablet in the prometheus client code. - Replace dots with underscores in tablenames on the way in - Switch to prometheus non-panic functions. - Add Makefile option to build non-optimized (debug) binaries. Signed-off-by: Jacques Grove <aquarapid@gmail.com>
This commit is contained in:
Родитель
f56ae63abb
Коммит
7b11b4a517
7
Makefile
7
Makefile
|
@ -49,6 +49,13 @@ endif
|
|||
bash ./build.env
|
||||
go install $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...
|
||||
|
||||
debug:
|
||||
ifndef NOBANNER
|
||||
echo $$(date): Building source tree
|
||||
endif
|
||||
bash ./build.env
|
||||
go install $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" -gcflags -'N -l' ./go/...
|
||||
|
||||
parser:
|
||||
make -C go/vt/sqlparser
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -59,7 +59,7 @@ require (
|
|||
github.com/pkg/errors v0.8.1
|
||||
github.com/prometheus/client_golang v1.1.0
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect
|
||||
github.com/prometheus/common v0.7.0 // indirect
|
||||
github.com/prometheus/common v0.7.0
|
||||
github.com/prometheus/procfs v0.0.5 // indirect
|
||||
github.com/satori/go.uuid v0.0.0-20160713180306-0aa62d5ddceb // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -14,8 +14,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
|||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM=
|
||||
|
@ -230,6 +232,7 @@ github.com/satori/go.uuid v0.0.0-20160713180306-0aa62d5ddceb/go.mod h1:dA0hQrYB0
|
|||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY=
|
||||
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
|
@ -376,6 +379,7 @@ google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8=
|
|||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
|
||||
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175 h1:nn6Zav2sOQHCFJHEspya8KqxhFwKci30UxHy3HXPTyQ=
|
||||
gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"vitess.io/vitess/go/stats"
|
||||
"vitess.io/vitess/go/vt/log"
|
||||
)
|
||||
|
||||
type metricFuncCollector struct {
|
||||
|
@ -40,6 +41,7 @@ func newMetricFuncCollector(v stats.Variable, name string, vt prometheus.ValueTy
|
|||
nil),
|
||||
vt: vt}
|
||||
|
||||
// Will panic if it fails
|
||||
prometheus.MustRegister(collector)
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,12 @@ func (mc *metricFuncCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
|
||||
// Collect implements Collector.
|
||||
func (mc *metricFuncCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- prometheus.MustNewConstMetric(mc.desc, mc.vt, float64(mc.f()))
|
||||
metric, err := prometheus.NewConstMetric(mc.desc, mc.vt, float64(mc.f()))
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", mc.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
|
||||
// countersWithSingleLabelCollector collects stats.CountersWithSingleLabel.
|
||||
|
@ -81,11 +88,12 @@ func (c *countersWithSingleLabelCollector) Describe(ch chan<- *prometheus.Desc)
|
|||
// Collect implements Collector.
|
||||
func (c *countersWithSingleLabelCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
for tag, val := range c.counters.Counts() {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.desc,
|
||||
c.vt,
|
||||
float64(val),
|
||||
tag)
|
||||
metric, err := prometheus.NewConstMetric(c.desc, c.vt, float64(val), tag)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,11 +125,12 @@ func (g *gaugesWithSingleLabelCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
// Collect implements Collector.
|
||||
func (g *gaugesWithSingleLabelCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
for tag, val := range g.gauges.Counts() {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
g.desc,
|
||||
g.vt,
|
||||
float64(val),
|
||||
tag)
|
||||
metric, err := prometheus.NewConstMetric(g.desc, g.vt, float64(val), tag)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", g.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +162,12 @@ func (c *metricWithMultiLabelsCollector) Collect(ch chan<- prometheus.Metric) {
|
|||
for lvs, val := range c.cml.Counts() {
|
||||
labelValues := strings.Split(lvs, ".")
|
||||
value := float64(val)
|
||||
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.CounterValue, value, labelValues...)
|
||||
metric, err := prometheus.NewConstMetric(c.desc, prometheus.CounterValue, value, labelValues...)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +199,12 @@ func (c *gaugesWithMultiLabelsCollector) Collect(ch chan<- prometheus.Metric) {
|
|||
for lvs, val := range c.gml.Counts() {
|
||||
labelValues := strings.Split(lvs, ".")
|
||||
value := float64(val)
|
||||
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, value, labelValues...)
|
||||
metric, err := prometheus.NewConstMetric(c.desc, prometheus.GaugeValue, value, labelValues...)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +238,12 @@ func (c *metricsFuncWithMultiLabelsCollector) Collect(ch chan<- prometheus.Metri
|
|||
for lvs, val := range c.cfml.Counts() {
|
||||
labelValues := strings.Split(lvs, ".")
|
||||
value := float64(val)
|
||||
ch <- prometheus.MustNewConstMetric(c.desc, c.vt, value, labelValues...)
|
||||
metric, err := prometheus.NewConstMetric(c.desc, c.vt, value, labelValues...)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,12 +280,16 @@ func (c *timingsCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
// Collect implements Collector.
|
||||
func (c *timingsCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
for cat, his := range c.t.Histograms() {
|
||||
ch <- prometheus.MustNewConstHistogram(
|
||||
c.desc,
|
||||
metric, err := prometheus.NewConstHistogram(c.desc,
|
||||
uint64(his.Count()),
|
||||
float64(his.Total())/1000000000,
|
||||
makeCumulativeBuckets(c.cutoffs, his.Buckets()),
|
||||
cat)
|
||||
makeCumulativeBuckets(c.cutoffs,
|
||||
his.Buckets()), cat)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,12 +338,17 @@ func (c *multiTimingsCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
func (c *multiTimingsCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
for cat, his := range c.mt.Timings.Histograms() {
|
||||
labelValues := strings.Split(cat, ".")
|
||||
ch <- prometheus.MustNewConstHistogram(
|
||||
metric, err := prometheus.NewConstHistogram(
|
||||
c.desc,
|
||||
uint64(his.Count()),
|
||||
float64(his.Total())/1000000000,
|
||||
makeCumulativeBuckets(c.cutoffs, his.Buckets()),
|
||||
labelValues...)
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,10 +384,13 @@ func (c *histogramCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
|
||||
// Collect implements Collector.
|
||||
func (c *histogramCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- prometheus.MustNewConstHistogram(
|
||||
c.desc,
|
||||
metric, err := prometheus.NewConstHistogram(c.desc,
|
||||
uint64(c.h.Count()),
|
||||
float64(c.h.Total()),
|
||||
makeCumulativeBuckets(c.cutoffs, c.h.Buckets()),
|
||||
)
|
||||
makeCumulativeBuckets(c.cutoffs, c.h.Buckets()))
|
||||
if err != nil {
|
||||
log.Errorf("Error adding metric: %s", c.desc)
|
||||
} else {
|
||||
ch <- metric
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -494,7 +495,8 @@ type QueryStats struct {
|
|||
|
||||
// AddStats adds the given stats for the planName.tableName
|
||||
func (qe *QueryEngine) AddStats(planName, tableName string, queryCount int64, duration, mysqlTime time.Duration, rowCount, errorCount int64) {
|
||||
key := tableName + "." + planName
|
||||
// table names can contain "." characters, replace them!
|
||||
key := strings.Replace(tableName, ".", "_", -1) + "." + planName
|
||||
|
||||
qe.queryStatsMu.RLock()
|
||||
stats, ok := qe.queryStats[key]
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -514,7 +515,7 @@ func (se *Engine) getTableRows() map[string]int64 {
|
|||
defer se.mu.Unlock()
|
||||
tstats := make(map[string]int64)
|
||||
for k, v := range se.tables {
|
||||
tstats[k] = v.TableRows.Get()
|
||||
tstats[strings.Replace(k, ".", "_", -1)] = v.TableRows.Get()
|
||||
}
|
||||
return tstats
|
||||
}
|
||||
|
@ -524,7 +525,7 @@ func (se *Engine) getDataLength() map[string]int64 {
|
|||
defer se.mu.Unlock()
|
||||
tstats := make(map[string]int64)
|
||||
for k, v := range se.tables {
|
||||
tstats[k] = v.DataLength.Get()
|
||||
tstats[strings.Replace(k, ".", "_", -1)] = v.DataLength.Get()
|
||||
}
|
||||
return tstats
|
||||
}
|
||||
|
@ -534,7 +535,7 @@ func (se *Engine) getIndexLength() map[string]int64 {
|
|||
defer se.mu.Unlock()
|
||||
tstats := make(map[string]int64)
|
||||
for k, v := range se.tables {
|
||||
tstats[k] = v.IndexLength.Get()
|
||||
tstats[strings.Replace(k, ".", "_", -1)] = v.IndexLength.Get()
|
||||
}
|
||||
return tstats
|
||||
}
|
||||
|
@ -544,7 +545,7 @@ func (se *Engine) getDataFree() map[string]int64 {
|
|||
defer se.mu.Unlock()
|
||||
tstats := make(map[string]int64)
|
||||
for k, v := range se.tables {
|
||||
tstats[k] = v.DataFree.Get()
|
||||
tstats[strings.Replace(k, ".", "_", -1)] = v.DataFree.Get()
|
||||
}
|
||||
return tstats
|
||||
}
|
||||
|
@ -554,7 +555,7 @@ func (se *Engine) getMaxDataLength() map[string]int64 {
|
|||
defer se.mu.Unlock()
|
||||
tstats := make(map[string]int64)
|
||||
for k, v := range se.tables {
|
||||
tstats[k] = v.MaxDataLength.Get()
|
||||
tstats[strings.Replace(k, ".", "_", -1)] = v.MaxDataLength.Get()
|
||||
}
|
||||
return tstats
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче