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

(#1129) - Fix cluster and mirror checks #566

Merged
merged 1 commit into from
Aug 28, 2024
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
15 changes: 6 additions & 9 deletions monitor/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,9 @@ func StreamHealthCheck(server string, nopts []nats.Option, check *Result, opts S
}

func streamCheckMirror(si *api.StreamInfo, check *Result, opts StreamHealthCheckOptions, log api.Logger) {
if (opts.SourcesLagCritical <= 0 && opts.SourcesSeenCritical <= 0) || si.Config.Name == "" || si.Config.Mirror == nil {
return
}

if si.Config.Name == "" {
log.Debugf("CRITICAL: no configuration present")
check.Critical("no configuration present")
// We check sources here because they are mutually exclusive with mirrors. If sources are set, mirrors
// can't be so we can bail out of this check early
if (opts.SourcesLagCritical <= 0 && opts.SourcesSeenCritical <= 0) || si.Config.Name == "" || len(si.Sources) > 0 {
ripienaar marked this conversation as resolved.
Show resolved Hide resolved
return
}

Expand Down Expand Up @@ -355,11 +351,12 @@ func streamCheckMessages(si *api.StreamInfo, check *Result, opts StreamHealthChe

func streamCheckCluster(si *api.StreamInfo, check *Result, opts StreamHealthCheckOptions, log api.Logger) {
nfo := si.Cluster
if nfo == nil && opts.ClusterExpectedPeers <= 0 {

if (nfo == nil || si.Config.Replicas <= 1) && opts.ClusterExpectedPeers <= 0 {
return
}

if nfo == nil {
if nfo == nil || si.Config.Replicas <= 1 {
log.Debugf("Stream is not clustered")
check.Critical("Stream is not clustered")
return
Expand Down
21 changes: 20 additions & 1 deletion monitor/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ func TestStream_checkCluster(t *testing.T) {
Replicas: []*api.PeerInfo{
{Name: "p1"},
},
}}
},
Config: api.StreamConfig{
Replicas: 2,
},
}

streamCheckCluster(si, check, StreamHealthCheckOptions{
ClusterExpectedPeers: 3,
Expand All @@ -443,6 +447,9 @@ func TestStream_checkCluster(t *testing.T) {
{Name: "p3"},
},
},
Config: api.StreamConfig{
Replicas: 3,
},
}

streamCheckCluster(si, check, StreamHealthCheckOptions{
Expand Down Expand Up @@ -476,6 +483,9 @@ func TestStream_checkCluster(t *testing.T) {
{Name: "p3", Lag: 10},
},
},
Config: api.StreamConfig{
Replicas: 3,
},
}

streamCheckCluster(si, check, StreamHealthCheckOptions{
Expand All @@ -495,6 +505,9 @@ func TestStream_checkCluster(t *testing.T) {
{Name: "p3", Lag: 10, Active: time.Hour},
},
},
Config: api.StreamConfig{
Replicas: 3,
},
}

streamCheckCluster(si, check, StreamHealthCheckOptions{
Expand All @@ -515,6 +528,9 @@ func TestStream_checkCluster(t *testing.T) {
{Name: "p3", Lag: 10, Active: time.Hour},
},
},
Config: api.StreamConfig{
Replicas: 3,
},
}

streamCheckCluster(si, check, StreamHealthCheckOptions{
Expand All @@ -534,6 +550,9 @@ func TestStream_checkCluster(t *testing.T) {
{Name: "p3", Lag: 10, Active: time.Second},
},
},
Config: api.StreamConfig{
Replicas: 3,
},
}
streamCheckCluster(si, check, StreamHealthCheckOptions{
ClusterExpectedPeers: 3,
Expand Down
Loading