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

Add option to disable per table metrics collection #5649

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 24 additions & 6 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package schema
import (
"bytes"
"encoding/json"
"flag"
"net/http"
"sync"
"time"
Expand All @@ -40,6 +41,16 @@ import (
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
)

var exposeStatsPerTable = flag.Bool("expose_stats_per_table", true,
"Whether to expose statistics split by table.")

// This is used in some queries for table information, but is not directly
// related to the number of tables that we report metrics for. It might affect
// that though, because in practice we might not hit any codepaths that report
// stats for that table because we don't even load it.
//
// I don't know whether we silently don't see tables if we have more than this
// number.
const maxTableCount = 10000

type notifier func(full map[string]*Table, created, altered, dropped []string)
Expand Down Expand Up @@ -76,11 +87,18 @@ func NewEngine(checker connpool.MySQLChecker, config tabletenv.TabletConfig) *En
}
schemaOnce.Do(func() {
_ = stats.NewGaugeDurationFunc("SchemaReloadTime", "vttablet keeps table schemas in its own memory and periodically refreshes it from MySQL. This config controls the reload time.", se.ticks.Interval)
_ = stats.NewGaugesFuncWithMultiLabels("TableRows", "table rows created in tabletserver", []string{"Table"}, se.getTableRows)
_ = stats.NewGaugesFuncWithMultiLabels("DataLength", "data length in tabletserver", []string{"Table"}, se.getDataLength)
_ = stats.NewGaugesFuncWithMultiLabels("IndexLength", "index length in tabletserver", []string{"Table"}, se.getIndexLength)
_ = stats.NewGaugesFuncWithMultiLabels("DataFree", "data free in tabletserver", []string{"Table"}, se.getDataFree)
_ = stats.NewGaugesFuncWithMultiLabels("MaxDataLength", "max data length in tabletserver", []string{"Table"}, se.getMaxDataLength)

var tableLabels []string
if *exposeStatsPerTable {
tableLabels = []string{"Table"}
} else {
tableLabels = []string{}
}
_ = stats.NewGaugesFuncWithMultiLabels("TableRows", "table rows created in tabletserver", tableLabels, se.getTableRows)
_ = stats.NewGaugesFuncWithMultiLabels("DataLength", "data length in tabletserver", tableLabels, se.getDataLength)
_ = stats.NewGaugesFuncWithMultiLabels("IndexLength", "index length in tabletserver", tableLabels, se.getIndexLength)
_ = stats.NewGaugesFuncWithMultiLabels("DataFree", "data free in tabletserver", tableLabels, se.getDataFree)
_ = stats.NewGaugesFuncWithMultiLabels("MaxDataLength", "max data length in tabletserver", tableLabels, se.getMaxDataLength)

http.Handle("/debug/schema", se)
http.HandleFunc("/schemaz", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -193,7 +211,7 @@ func (se *Engine) Open() error {
return nil
}

// IsOpen() checks if engine is open
// IsOpen checks if engine is open
func (se *Engine) IsOpen() bool {
se.mu.Lock()
defer se.mu.Unlock()
Expand Down
27 changes: 27 additions & 0 deletions go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,33 @@ func TestStatsURL(t *testing.T) {
request, _ := http.NewRequest("GET", "/debug/schema", nil)
response := httptest.NewRecorder()
se.ServeHTTP(response, request)

// Check the status code is what we expect.
if status := response.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
}

func TestPrometheusStatsURL(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
for query, result := range schematest.Queries() {
db.AddQuery(query, result)
}
se := newEngine(10, 1*time.Second, 1*time.Second, true, db)
se.Open()
defer se.Close()

request, _ := http.NewRequest("GET", "/metrics", nil)
response := httptest.NewRecorder()
se.ServeHTTP(response, request)

// Check the status code is what we expect.
if status := response.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
}

type dummyChecker struct {
Expand Down