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

resource_manage/metrics: change histogram to vector #6332

Merged
merged 3 commits into from
Apr 26, 2023
Merged
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
12 changes: 6 additions & 6 deletions pkg/mcs/resource_manager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,25 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) {
)
// RU info.
if consumption.RRU != 0 {
rruMetrics.Observe(consumption.RRU)
rruMetrics.Add(consumption.RRU)
}
if consumption.WRU != 0 {
wruMetrics.Observe(consumption.WRU)
wruMetrics.Add(consumption.WRU)
}
// Byte info.
if consumption.ReadBytes != 0 {
readByteMetrics.Observe(consumption.ReadBytes)
readByteMetrics.Add(consumption.ReadBytes)
}
if consumption.WriteBytes != 0 {
writeByteMetrics.Observe(consumption.WriteBytes)
writeByteMetrics.Add(consumption.WriteBytes)
}
// CPU time info.
if consumption.TotalCpuTimeMs > 0 {
if consumption.SqlLayerCpuTimeMs > 0 {
sqlLayerRuMetrics.Add(consumption.SqlLayerCpuTimeMs * m.controllerConfig.RequestUnit.CPUMsCost)
sqlCPUMetrics.Observe(consumption.SqlLayerCpuTimeMs)
sqlCPUMetrics.Add(consumption.SqlLayerCpuTimeMs)
}
kvCPUMetrics.Observe(consumption.TotalCpuTimeMs - consumption.SqlLayerCpuTimeMs)
kvCPUMetrics.Add(consumption.TotalCpuTimeMs - consumption.SqlLayerCpuTimeMs)
Copy link
Contributor

@bufferflies bufferflies Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition of TotalCpuTimeMs less than SqlLayerCpuTimeMs is always true. if not, it maybe panic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, TotalCpuTimeMs includes SqlLayerCpuTimeMs.

}
// RPC count info.
if consumption.KvReadRpcCount != 0 {
Expand Down
69 changes: 31 additions & 38 deletions pkg/mcs/resource_manager/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

package server

import (
"github.com/prometheus/client_golang/prometheus"
)
import "github.com/prometheus/client_golang/prometheus"

const (
namespace = "resource_manager"
Expand All @@ -39,65 +37,60 @@ var (
Help: "Indicate the resource manager server info, and the value is the start timestamp (s).",
}, []string{"version", "hash"})
// RU cost metrics.
readRequestUnitCost = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
// `sum` is added to the name to maintain compatibility with the previous use of histogram.
readRequestUnitCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "read_request_unit",
Help: "Bucketed histogram of the read request unit cost for all resource groups.",
Buckets: prometheus.ExponentialBuckets(1, 10, 5), // 1 ~ 100000
Name: "read_request_unit_sum",
Help: "Counter of the read request unit cost for all resource groups.",
}, []string{resourceGroupNameLabel})
writeRequestUnitCost = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
writeRequestUnitCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "write_request_unit",
Help: "Bucketed histogram of the write request unit cost for all resource groups.",
Buckets: prometheus.ExponentialBuckets(3, 10, 5), // 3 ~ 300000
Name: "write_request_unit_sum",
Help: "Counter of the write request unit cost for all resource groups.",
}, []string{resourceGroupNameLabel})
sqlLayerRequestUnitCost = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
sqlLayerRequestUnitCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "sql_layer_request_unit",
Name: "sql_layer_request_unit_sum",
Help: "The number of the sql layer request unit cost for all resource groups.",
}, []string{resourceGroupNameLabel})

// Resource cost metrics.
readByteCost = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
readByteCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "read_byte",
Help: "Bucketed histogram of the read byte cost for all resource groups.",
Buckets: prometheus.ExponentialBuckets(1, 8, 12),
Name: "read_byte_sum",
Help: "Counter of the read byte cost for all resource groups.",
}, []string{resourceGroupNameLabel})
writeByteCost = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
writeByteCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "write_byte",
Help: "Bucketed histogram of the write byte cost for all resource groups.",
Buckets: prometheus.ExponentialBuckets(1, 8, 12),
Name: "write_byte_sum",
Help: "Counter of the write byte cost for all resource groups.",
}, []string{resourceGroupNameLabel})
kvCPUCost = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
kvCPUCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "kv_cpu_time_ms",
Help: "Bucketed histogram of the KV CPU time cost in milliseconds for all resource groups.",
Buckets: prometheus.ExponentialBuckets(1, 10, 3), // 1 ~ 1000
Name: "kv_cpu_time_ms_sum",
Help: "Counter of the KV CPU time cost in milliseconds for all resource groups.",
}, []string{resourceGroupNameLabel})
sqlCPUCost = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
sqlCPUCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "sql_cpu_time_ms",
Help: "Bucketed histogram of the SQL CPU time cost in milliseconds for all resource groups.",
Buckets: prometheus.ExponentialBuckets(1, 10, 3), // 1 ~ 1000
Name: "sql_cpu_time_ms_sum",
Help: "Counter of the SQL CPU time cost in milliseconds for all resource groups.",
}, []string{resourceGroupNameLabel})
requestCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
requestCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "request_count",
Expand Down