Skip to content

Commit

Permalink
sql: instantiate metrics for internal sql stats
Browse files Browse the repository at this point in the history
Previously, we did not instantiate metrics for internal SQL stats.
However, this can cause issues when connExecutor is being created
by InternalExecutor. In order to address this, we also instantiate
metrics for internal stats.

Release note: None

Closes #65523
  • Loading branch information
Azhng committed May 21, 2021
1 parent 040a7af commit eaf1a71
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
42 changes: 19 additions & 23 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,28 +324,6 @@ func NewServer(cfg *ExecutorConfig, pool *mon.BytesMonitor) *Server {
}

func makeMetrics(cfg *ExecutorConfig, internal bool) Metrics {
var statsMetrics StatsMetrics
if !internal {
statsMetrics = StatsMetrics{
SQLStatsMemoryMaxBytesHist: metric.NewHistogram(
getMetricMeta(MetaSQLStatsMemMaxBytes, internal),
cfg.HistogramWindowInterval,
log10int64times1000,
3, /* sigFigs */
),
SQLStatsMemoryCurBytesCount: metric.NewGauge(
getMetricMeta(MetaSQLStatsMemCurBytes, internal)),
ReportedSQLStatsMemoryMaxBytesHist: metric.NewHistogram(
getMetricMeta(MetaReportedSQLStatsMemMaxBytes, internal),
cfg.HistogramWindowInterval,
log10int64times1000,
3, /* sigFigs */
),
ReportedSQLStatsMemoryCurBytesCount: metric.NewGauge(
getMetricMeta(MetaReportedSQLStatsMemCurBytes, internal)),
DiscardedStatsCount: metric.NewCounter(getMetricMeta(MetaDiscardedSQLStats, internal)),
}
}
return Metrics{
EngineMetrics: EngineMetrics{
DistSQLSelectCount: metric.NewCounter(getMetricMeta(MetaDistSQLSelect, internal)),
Expand All @@ -371,7 +349,25 @@ func makeMetrics(cfg *ExecutorConfig, internal bool) Metrics {
},
StartedStatementCounters: makeStartedStatementCounters(internal),
ExecutedStatementCounters: makeExecutedStatementCounters(internal),
StatsMetrics: statsMetrics,
StatsMetrics: StatsMetrics{
SQLStatsMemoryMaxBytesHist: metric.NewHistogram(
getMetricMeta(MetaSQLStatsMemMaxBytes, internal),
cfg.HistogramWindowInterval,
log10int64times1000,
3, /* sigFigs */
),
SQLStatsMemoryCurBytesCount: metric.NewGauge(
getMetricMeta(MetaSQLStatsMemCurBytes, internal)),
ReportedSQLStatsMemoryMaxBytesHist: metric.NewHistogram(
getMetricMeta(MetaReportedSQLStatsMemMaxBytes, internal),
cfg.HistogramWindowInterval,
log10int64times1000,
3, /* sigFigs */
),
ReportedSQLStatsMemoryCurBytesCount: metric.NewGauge(
getMetricMeta(MetaReportedSQLStatsMemCurBytes, internal)),
DiscardedStatsCount: metric.NewCounter(getMetricMeta(MetaDiscardedSQLStats, internal)),
},
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/pgwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func (s *Server) Metrics() (res []interface{}) {
&s.SQLServer.InternalMetrics.StartedStatementCounters,
&s.SQLServer.InternalMetrics.ExecutedStatementCounters,
&s.SQLServer.InternalMetrics.EngineMetrics,
&s.SQLServer.InternalMetrics.StatsMetrics,
}
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/ts/catalog/chart_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,26 @@ var charts = []sectionDescription{
Title: "Number of fingerprint statistics being discarded",
Metrics: []string{"sql.stats.discarded.current"},
},
{
Title: "Memory usage for internal fingerprint storage",
Metrics: []string{"sql.stats.mem.max.internal"},
},
{
Title: "Current memory usage for internal fingerprint storage",
Metrics: []string{"sql.stats.mem.current.internal"},
},
{
Title: "Memory usage for internal reported fingerprint storage",
Metrics: []string{"sql.stats.reported.mem.max.internal"},
},
{
Title: "Current memory usage for internal reported fingerprint storage",
Metrics: []string{"sql.stats.reported.mem.current.internal"},
},
{
Title: "Number of internal fingerprint statistics being discarded",
Metrics: []string{"sql.stats.discarded.current.internal"},
},
},
},
{
Expand Down

0 comments on commit eaf1a71

Please sign in to comment.