-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
80929: authors: add pjtatlow to authors r=rickystewart a=pjtatlow Release note: None 80975: outliers: extract a detector interface r=matthewtodd a=matthewtodd This gives us a place to hang the upcoming work in #79451. Release note: None Co-authored-by: PJ Tatlow <pj@cockroachlabs.com> Co-authored-by: Matthew Todd <todd@cockroachlabs.com>
- Loading branch information
Showing
5 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package outliers | ||
|
||
import "github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
|
||
type detector interface { | ||
enabled() bool | ||
isOutlier(*Outlier_Statement) bool | ||
} | ||
|
||
var _ detector = &latencyThresholdDetector{} | ||
|
||
type latencyThresholdDetector struct { | ||
st *cluster.Settings | ||
} | ||
|
||
func (l latencyThresholdDetector) enabled() bool { | ||
return LatencyThreshold.Get(&l.st.SV) > 0 | ||
} | ||
|
||
func (l latencyThresholdDetector) isOutlier(s *Outlier_Statement) bool { | ||
return l.enabled() && s.LatencyInSeconds >= LatencyThreshold.Get(&l.st.SV).Seconds() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package outliers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLatencyThresholdDetector(t *testing.T) { | ||
t.Run("enabled false by default", func(t *testing.T) { | ||
detector := latencyThresholdDetector{st: cluster.MakeTestingClusterSettings()} | ||
require.False(t, detector.enabled()) | ||
}) | ||
|
||
t.Run("enabled true with nonzero threshold", func(t *testing.T) { | ||
st := cluster.MakeTestingClusterSettings() | ||
LatencyThreshold.Override(context.Background(), &st.SV, 1*time.Second) | ||
detector := latencyThresholdDetector{st: st} | ||
require.True(t, detector.enabled()) | ||
}) | ||
|
||
t.Run("isOutlier false when disabled", func(t *testing.T) { | ||
detector := latencyThresholdDetector{st: cluster.MakeTestingClusterSettings()} | ||
require.False(t, detector.isOutlier(&Outlier_Statement{LatencyInSeconds: 1})) | ||
}) | ||
|
||
t.Run("isOutlier false when fast enough", func(t *testing.T) { | ||
st := cluster.MakeTestingClusterSettings() | ||
LatencyThreshold.Override(context.Background(), &st.SV, 1*time.Second) | ||
detector := latencyThresholdDetector{st: st} | ||
require.False(t, detector.isOutlier(&Outlier_Statement{LatencyInSeconds: 0.5})) | ||
}) | ||
|
||
t.Run("isOutlier true beyond threshold", func(t *testing.T) { | ||
st := cluster.MakeTestingClusterSettings() | ||
LatencyThreshold.Override(context.Background(), &st.SV, 1*time.Second) | ||
detector := latencyThresholdDetector{st: st} | ||
require.True(t, detector.isOutlier(&Outlier_Statement{LatencyInSeconds: 1})) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters