Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed some function comments based on best practices from Effective Go #137, thx [@CodeLingoBot](https://github.com/CodeLingoBot).
- [PMM-3473](https://jira.percona.com/browse/PMM-3473): Fixed panic and runtime error.

## [0.7.0]
### Changed
Expand Down
28 changes: 20 additions & 8 deletions collector/mongod/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,18 @@ type ReplStats struct {

// Export exposes the replication stats.
func (replStats *ReplStats) Export(ch chan<- prometheus.Metric) {
replStats.Apply.Export(ch)
replStats.Buffer.Export(ch)
replStats.Network.Export(ch)
replStats.PreloadStats.Export(ch)
if replStats.Apply != nil {
replStats.Apply.Export(ch)
}
if replStats.Buffer != nil {
replStats.Buffer.Export(ch)
}
if replStats.Network != nil {
replStats.Network.Export(ch)
}
if replStats.PreloadStats != nil {
replStats.PreloadStats.Export(ch)
}
// 3.0+ only
if replStats.Executor != nil {
replStats.Executor.Export(ch)
Expand All @@ -425,11 +433,15 @@ type PreloadStats struct {

// Export exposes the preload stats.
func (preloadStats *PreloadStats) Export(ch chan<- prometheus.Metric) {
metricsReplPreloadDocsNumTotal.Set(preloadStats.Docs.Num)
metricsReplPreloadDocsTotalMilliseconds.Set(preloadStats.Docs.TotalMillis)
if preloadStats.Docs != nil {
metricsReplPreloadDocsNumTotal.Set(preloadStats.Docs.Num)
metricsReplPreloadDocsTotalMilliseconds.Set(preloadStats.Docs.TotalMillis)
}

metricsReplPreloadIndexesNumTotal.Set(preloadStats.Indexes.Num)
metricsReplPreloadIndexesTotalMilliseconds.Set(preloadStats.Indexes.TotalMillis)
if preloadStats.Indexes != nil {
metricsReplPreloadIndexesNumTotal.Set(preloadStats.Indexes.Num)
metricsReplPreloadIndexesTotalMilliseconds.Set(preloadStats.Indexes.TotalMillis)
}
}

// StorageStats are the stats associated with the storage.
Expand Down
24 changes: 24 additions & 0 deletions collector/mongod/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mongod

import (
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)

func TestReplStatsExportShouldNotPanic(t *testing.T) {
rs := &ReplStats{}
ch := make(chan prometheus.Metric)
f := func() { rs.Export(ch) }

assert.NotPanics(t, f, "nil pointer in ReplStats")
}

func TestPreloadStatsExportShouldNotPanic(t *testing.T) {
ps := &PreloadStats{}
ch := make(chan prometheus.Metric)
f := func() { ps.Export(ch) }

assert.NotPanics(t, f, "nil pointer in PreloadStats")
}