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

feat: clear_metrics #16550

Closed
wants to merge 3 commits into from
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
21 changes: 21 additions & 0 deletions go/vt/vtgate/scatter_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,29 @@ type shardActionFunc func(rs *srvtopo.ResolvedShard, i int) error
// the results and errors for the caller.
type shardActionTransactionFunc func(rs *srvtopo.ResolvedShard, i int, shardActionInfo *shardActionInfo) (*shardActionInfo, error)

var (
vttabletTimings = stats.NewMultiTimings(
"VttabletCall",
"Scatter connection timings",
[]string{"Operation", "Keyspace", "ShardName", "DbType"})
tabletCallErrorCount = stats.NewCountersWithMultiLabels(
"VttabletCallErrorCount",
"Error count from tablet calls in scatter conns",
[]string{"Operation", "Keyspace", "ShardName", "DbType"})
)

// NewScatterConn creates a new ScatterConn.
func NewScatterConn(statsName string, txConn *TxConn, gw *TabletGateway) *ScatterConn {
// this only works with TabletGateway
if statsName == "VttabletCall" {
return &ScatterConn{
timings: vttabletTimings,
tabletCallErrorCount: tabletCallErrorCount,
txConn: txConn,
gateway: gw,
}
}

tabletCallErrorCountStatsName := ""
if statsName != "" {
tabletCallErrorCountStatsName = statsName + "ErrorCount"
Expand All @@ -91,6 +111,7 @@ func NewScatterConn(statsName string, txConn *TxConn, gw *TabletGateway) *Scatte
txConn: txConn,
gateway: gw,
}

}

func (stc *ScatterConn) startAction(name string, target *querypb.Target) (time.Time, []string) {
Expand Down
26 changes: 26 additions & 0 deletions go/vt/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ var (
[]string{"Operation", "Keyspace", "DbType"})
)

func ClearMetrics() {
vschemaCounters.ResetAll()
errorCounts.ResetAll()
warnings.ResetAll()
vstreamSkewDelayCount.Reset()
vindexUnknownParams.Reset()
timings.Reset()
rowsReturned.ResetAll()
rowsAffected.ResetAll()
queriesProcessed.ResetAll()
queriesRouted.ResetAll()
queriesProcessedByTable.ResetAll()
queriesRoutedByTable.ResetAll()
vttabletTimings.Reset()
tabletCallErrorCount.ResetAll()
}
Comment on lines +219 to +234
Copy link
Contributor

@mattlord mattlord Aug 8, 2024

Choose a reason for hiding this comment

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

This will be a problem because 1) this does not include the full list of vtgate stats today 2) when new ones are added in the future it will not be clear (or expected) to have to find this and add the new stat here for the reset.


// VTGate is the rpc interface to vtgate. Only one instance
// can be created. It implements vtgateservice.VTGateService
// VTGate exposes multiple generations of interfaces.
Expand Down Expand Up @@ -377,6 +394,7 @@ func Init(
})
vtgateInst.registerDebugHealthHandler()
vtgateInst.registerDebugEnvHandler()
vtgateInst.registerClearMetrics()

initAPI(gw.hc)
return vtgateInst
Expand Down Expand Up @@ -441,6 +459,14 @@ func (vtg *VTGate) registerDebugHealthHandler() {
})
}

func (vtg *VTGate) registerClearMetrics() {
servenv.HTTPHandleFunc("/clear/metrics", func(w http.ResponseWriter, r *http.Request) {
ClearMetrics()
log.Infof("vtgate metrics have been cleared.")
w.Write([]byte("vtgate metrics have been cleared."))
})
}

// IsHealthy returns nil if server is healthy.
// Otherwise, it returns an error indicating the reason.
func (vtg *VTGate) IsHealthy() error {
Expand Down
Loading