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

*: specify time range via TIME_RANGE hint for metrics/inspection tables #14874

Merged
merged 11 commits into from
Feb 21, 2020
Prev Previous commit
Next Next commit
filter metrics_name
Signed-off-by: Lonng <heng@lonng.org>
  • Loading branch information
lonng committed Feb 21, 2020
commit 35a0e455b207cf75d3deac90fa75dbb9f46e0dd3
8 changes: 8 additions & 0 deletions executor/metrics_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@ func (e *MetricSummaryRetriever) retrieve(_ context.Context, sctx sessionctx.Con
}
sort.Strings(tables)

filter := inspectionFilter{set: e.extractor.MetricsNames}
condition := e.timeRange.Condition()
for _, name := range tables {
if !filter.enable(name) {
continue
}
def, found := infoschema.MetricTableMap[name]
if !found {
sctx.GetSessionVars().StmtCtx.AppendWarning(fmt.Errorf("metrics table: %s not found", name))
Expand Down Expand Up @@ -295,8 +299,12 @@ func (e *MetricSummaryByLabelRetriever) retrieve(ctx context.Context, sctx sessi
}
sort.Strings(tables)

filter := inspectionFilter{set: e.extractor.MetricsNames}
condition := e.timeRange.Condition()
for _, name := range tables {
if !filter.enable(name) {
continue
}
def, found := infoschema.MetricTableMap[name]
if !found {
sctx.GetSessionVars().StmtCtx.AppendWarning(fmt.Errorf("metrics table: %s not found", name))
Expand Down
8 changes: 4 additions & 4 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ var tableInspectionResultCols = []columnInfo{
var tableInspectionSummaryCols = []columnInfo{
{"RULE", mysql.TypeVarchar, 64, 0, nil, nil},
{"INSTANCE", mysql.TypeVarchar, 64, 0, nil, nil},
{"METRIC_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"METRICS_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"LABEL", mysql.TypeVarchar, 64, 0, nil, nil},
{"QUANTILE", mysql.TypeDouble, 22, 0, nil, nil},
{"AVG_VALUE", mysql.TypeDouble, 22, 0, nil, nil},
Expand All @@ -1216,7 +1216,7 @@ var tableMetricTablesCols = []columnInfo{
}

var tableMetricSummaryCols = []columnInfo{
{"METRIC_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"METRICS_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"QUANTILE", mysql.TypeDouble, 22, 0, nil, nil},
{"SUM_VALUE", mysql.TypeDouble, 22, 0, nil, nil},
{"AVG_VALUE", mysql.TypeDouble, 22, 0, nil, nil},
Expand All @@ -1227,7 +1227,7 @@ var tableMetricSummaryCols = []columnInfo{

var tableMetricSummaryByLabelCols = []columnInfo{
{"INSTANCE", mysql.TypeVarchar, 64, 0, nil, nil},
{"METRIC_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"METRICS_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"LABEL", mysql.TypeVarchar, 64, 0, nil, nil},
{"QUANTILE", mysql.TypeDouble, 22, 0, nil, nil},
{"SUM_VALUE", mysql.TypeDouble, 22, 0, nil, nil},
Expand Down Expand Up @@ -2386,7 +2386,7 @@ func dataForMetricTables(ctx sessionctx.Context) [][]types.Datum {
for _, name := range tables {
schema := MetricTableMap[name]
record := types.MakeDatums(
name, // METRIC_NAME
name, // METRICS_NAME
schema.PromQL, // PROMQL
strings.Join(schema.Labels, ","), // LABELS
schema.Quantile, // QUANTILE
Expand Down
14 changes: 7 additions & 7 deletions planner/core/memtable_predicate_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ func (e *MetricTableExtractor) getTimeRange(start, end int64) (time.Time, time.T
type MetricSummaryTableExtractor struct {
extractHelper
// SkipRequest means the where clause always false, we don't need to request any component
SkipRequest bool
MetricNames set.StringSet
Quantiles []float64
SkipRequest bool
MetricsNames set.StringSet
Quantiles []float64
}

// Extract implements the MemTablePredicateExtractor Extract interface
Expand All @@ -611,10 +611,10 @@ func (e *MetricSummaryTableExtractor) Extract(
predicates []expression.Expression,
) (remained []expression.Expression) {
remained, quantileSkip, quantiles := e.extractCol(schema, names, predicates, "quantile", false)
remained, metricNameSkip, metricNames := e.extractCol(schema, names, predicates, "metric_name", true)
e.SkipRequest = quantileSkip || metricNameSkip
remained, metricsNameSkip, metricsNames := e.extractCol(schema, names, predicates, "metrics_name", true)
e.SkipRequest = quantileSkip || metricsNameSkip
e.Quantiles = e.parseQuantiles(quantiles)
e.MetricNames = metricNames
e.MetricsNames = metricsNames
return remained
}

Expand Down Expand Up @@ -669,7 +669,7 @@ func (e *InspectionSummaryTableExtractor) Extract(
// Extract the `rule` columns
remained, ruleSkip, rules := e.extractCol(schema, names, predicates, "rule", true)
// Extract the `metric_name` columns
remained, metricNameSkip, metricNames := e.extractCol(schema, names, predicates, "metric_name", true)
remained, metricNameSkip, metricNames := e.extractCol(schema, names, predicates, "metrics_name", true)
// Extract the `quantile` columns
remained, quantileSkip, quantileSet := e.extractCol(schema, names, predicates, "quantile", false)
e.SkipInspection = ruleSkip || quantileSkip || metricNameSkip
Expand Down
2 changes: 1 addition & 1 deletion planner/core/memtable_predicate_extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (s *extractorSuite) TestMetricsSummaryTableExtractor(c *C) {
c.Assert(extractor.Quantiles, DeepEquals, ca.quantiles, Commentf("SQL: %v", ca.sql))
}
if len(ca.names) > 0 {
c.Assert(extractor.MetricNames, DeepEquals, ca.names, Commentf("SQL: %v", ca.sql))
c.Assert(extractor.MetricsNames, DeepEquals, ca.names, Commentf("SQL: %v", ca.sql))
}
c.Assert(extractor.SkipRequest, Equals, ca.skipRequest, Commentf("SQL: %v", ca.sql))
}
Expand Down