Skip to content

PMM-9403 Add extra label for replicaset metrics #804

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

Merged
merged 2 commits into from
May 22, 2024
Merged
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
15 changes: 7 additions & 8 deletions exporter/v1_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,8 @@ func oplogStatus(ctx context.Context, client *mongo.Client) ([]prometheus.Metric
return []prometheus.Metric{headMetric, tailMetric}, nil
}

func replSetMetrics(m bson.M) []prometheus.Metric {
replSetGetStatus, ok := m["replSetGetStatus"].(bson.M)
func replSetMetrics(d bson.M) []prometheus.Metric {

Choose a reason for hiding this comment

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

🚫 [golangci-lint] reported by reviewdog 🐶
Function 'replSetMetrics' has too many statements (41 > 40) (funlen)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity. Why "d"? Since it is bson.M not bson.D.

Copy link
Member Author

Choose a reason for hiding this comment

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

because it's diagnostic data, needed some other variable, because m was reused below for members.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Thanks

replSetGetStatus, ok := d["replSetGetStatus"].(bson.M)
if !ok {
return nil
}
Expand All @@ -1021,7 +1021,7 @@ func replSetMetrics(m bson.M) []prometheus.Metric {
for _, m := range repl.Members {
if m.StateStr == "PRIMARY" {
primaryOpTime = m.OptimeDate.Time()
gotPrimary = !primaryOpTime.IsZero()
gotPrimary = primaryOpTime.Unix() != 0

break
}
Expand All @@ -1044,20 +1044,19 @@ func replSetMetrics(m bson.M) []prometheus.Metric {
"name": m.Name,
"state": m.StateStr,
"set": repl.Set,
"self": "0",
}
if m.Self {
createMetric("my_name", "The replica state name of the current member.", 1, map[string]string{
"name": m.Name,
"set": repl.Set,
})
labels["self"] = "1"
createMetric("my_name", "The replica state name of the current member.", 1, labels)
}

if !m.ElectionTime.IsZero() {
createMetric("member_election_date",
"The timestamp the node was elected as replica leader",
float64(m.ElectionTime.T), labels)
}
if t := m.OptimeDate.Time(); gotPrimary && !t.IsZero() && m.StateStr != "PRIMARY" {
if t := m.OptimeDate.Time(); gotPrimary && t.Unix() != 0 && m.StateStr != "PRIMARY" {
val := math.Abs(float64(t.Unix() - primaryOpTime.Unix()))
createMetric("member_replication_lag",
"The replication lag that this member has with the primary.",
Expand Down