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

vtorc: add detected_problems counter #13967

Merged
merged 15 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
5 changes: 5 additions & 0 deletions go/stats/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ func NewGaugesWithMultiLabels(name, help string, labels []string) *GaugesWithMul
return t
}

// GetLabelName returns a label name using the provided values.
func (mg *GaugesWithMultiLabels) GetLabelName(names ...string) string {
return safeJoinLabels(names, mg.combinedLabels)
}

// Set sets the value of a named counter.
// len(names) must be equal to len(Labels).
func (mg *GaugesWithMultiLabels) Set(names []string, value int64) {
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vtorc/inst/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

type AnalysisCode string
type StructureAnalysisCode string

const (
NoProblem AnalysisCode = "NoProblem"
Expand Down Expand Up @@ -61,6 +60,8 @@ const (
ErrantGTIDDetected AnalysisCode = "ErrantGTIDDetected"
)

type StructureAnalysisCode string

const (
StatementAndMixedLoggingReplicasStructureWarning StructureAnalysisCode = "StatementAndMixedLoggingReplicasStructureWarning"
StatementAndRowLoggingReplicasStructureWarning StructureAnalysisCode = "StatementAndRowLoggingReplicasStructureWarning"
Expand Down
42 changes: 39 additions & 3 deletions go/vt/vtorc/logic/topology_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ var (

countPendingRecoveries = stats.NewGauge("PendingRecoveries", "Count of the number of pending recoveries")

// detectedProblems is used to track the number of detected problems.
//
// When an issue is active it will be set to 1, when it is no longer active
// it will be reset back to 0.
detectedProblems = stats.NewGaugesWithMultiLabels("DetectedProblems", "Count of the different detected problems", []string{
"Analysis",
"TabletAlias",
"Keyspace",
"Shard",
})

// recoveriesCounter counts the number of recoveries that VTOrc has performed
recoveriesCounter = stats.NewCountersWithSingleLabel("RecoveriesCount", "Count of the different recoveries performed", "RecoveryType", actionableRecoveriesNames...)

Expand Down Expand Up @@ -755,17 +766,42 @@ func CheckAndRecover() {
log.Error(err)
return
}

// Regardless of if the problem is solved or not we want to monitor active
// issues, we use a map of labels and set a counter to `1` for each problem
// then we reset any counter that is not present in the current analysis.
active := make(map[string][]string)
for _, e := range replicationAnalysis {
if e.Analysis != inst.NoProblem {
names := [...]string{
string(e.Analysis),
e.AnalyzedInstanceAlias,
e.AnalyzedKeyspace,
e.AnalyzedShard,
}

key := detectedProblems.GetLabelName(names[:]...)
active[key] = names[:]
detectedProblems.Set(names[:], 1)
}
}

// Reset any non-active problems.
for key := range detectedProblems.Counts() {
if names, ok := active[key]; !ok {
detectedProblems.Set(names, 0)
}
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
}

// intentionally iterating entries in random order
for _, j := range rand.Perm(len(replicationAnalysis)) {
analysisEntry := replicationAnalysis[j]

go func() {
err = executeCheckAndRecoverFunction(analysisEntry)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looked like a bug to me so changed the scoping here.

Copy link
Member

Choose a reason for hiding this comment

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

Oh yes! Good catch.

if err != nil {
if err := executeCheckAndRecoverFunction(analysisEntry); err != nil {
log.Error(err)
}
}()

}
}

Expand Down
Loading