Skip to content

Commit

Permalink
*: implement inspection_summary system table which organizes metrics …
Browse files Browse the repository at this point in the history
…by link/module (#14810)
  • Loading branch information
lonng authored Feb 18, 2020
1 parent 1c09740 commit 9fbefc5
Show file tree
Hide file tree
Showing 13 changed files with 861 additions and 73 deletions.
10 changes: 9 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,10 +1317,18 @@ func (b *executorBuilder) buildMemTable(v *plannercore.PhysicalMemTable) Executo
case strings.ToLower(infoschema.TableInspectionResult):
return &MemTableReaderExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
retriever: &inspectionRetriever{
retriever: &inspectionResultRetriever{
extractor: v.Extractor.(*plannercore.InspectionResultTableExtractor),
},
}
case strings.ToLower(infoschema.TableInspectionSummary):
return &MemTableReaderExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
retriever: &inspectionSummaryRetriever{
table: v.Table,
extractor: v.Extractor.(*plannercore.InspectionSummaryTableExtractor),
},
}
case strings.ToLower(infoschema.TableMetricSummary):
return &MemTableReaderExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
Expand Down
3 changes: 3 additions & 0 deletions executor/executor_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import (
var _ = Suite(&testExecSuite{})
var _ = SerialSuites(&testExecSerialSuite{})

// Note: it's a tricky way to export the `inspectionSummaryRules` for unit test but invisible for normal code
var InspectionSummaryRules = inspectionSummaryRules

type testExecSuite struct {
}

Expand Down
4 changes: 2 additions & 2 deletions executor/diagnostics.go → executor/inspection_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ var inspectionRules = []inspectionRule{
&thresholdCheckInspection{inspectionName: "threshold-check"},
}

type inspectionRetriever struct {
type inspectionResultRetriever struct {
dummyCloser
retrieved bool
extractor *plannercore.InspectionResultTableExtractor
}

func (e *inspectionRetriever) retrieve(ctx context.Context, sctx sessionctx.Context) ([][]types.Datum, error) {
func (e *inspectionResultRetriever) retrieve(ctx context.Context, sctx sessionctx.Context) ([][]types.Datum, error) {
if e.retrieved || e.extractor.SkipInspection {
return nil, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ import (
"github.com/pingcap/tidb/util/testkit"
)

var _ = Suite(&diagnosticsSuite{})
var _ = SerialSuites(&inspectionResultSuite{})

type diagnosticsSuite struct {
type inspectionResultSuite struct {
store kv.Storage
dom *domain.Domain
}

func (s *diagnosticsSuite) SetUpSuite(c *C) {
func (s *inspectionResultSuite) SetUpSuite(c *C) {
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
s.store = store
s.dom = dom
}

func (s *diagnosticsSuite) TearDownSuite(c *C) {
func (s *inspectionResultSuite) TearDownSuite(c *C) {
s.dom.Close()
s.store.Close()
}

func (s *diagnosticsSuite) TestInspectionResult(c *C) {
func (s *inspectionResultSuite) TestInspectionResult(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

mockData := map[string]variable.TableSnapshot{}
Expand Down Expand Up @@ -166,13 +166,13 @@ func (s *diagnosticsSuite) TestInspectionResult(c *C) {
}
}

func (s *diagnosticsSuite) parseTime(c *C, se session.Session, str string) types.Time {
func (s *inspectionResultSuite) parseTime(c *C, se session.Session, str string) types.Time {
t, err := types.ParseTime(se.GetSessionVars().StmtCtx, str, mysql.TypeDatetime, types.MaxFsp)
c.Assert(err, IsNil)
return t
}

func (s *diagnosticsSuite) TestThresholdCheckInspection(c *C) {
func (s *inspectionResultSuite) TestThresholdCheckInspection(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
// mock tikv configuration.
configurations := map[string]variable.TableSnapshot{}
Expand Down Expand Up @@ -277,7 +277,7 @@ func (s *diagnosticsSuite) TestThresholdCheckInspection(c *C) {
"grpc_cpu tikv tikv-0 7.21 < 7.20, config: server.grpc-concurrency=8 select instance, sum(value) as cpu from metric_schema.tikv_thread_cpu where name like 'grpc%' and time=now() group by instance"))
}

func (s *diagnosticsSuite) TestCriticalErrorInspection(c *C) {
func (s *inspectionResultSuite) TestCriticalErrorInspection(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

fpName := "github.com/pingcap/tidb/executor/mockMetricsTableData"
Expand Down
Loading

0 comments on commit 9fbefc5

Please sign in to comment.