-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Throttler code: some refactoring and cleanup #16368
Merged
shlomi-noach
merged 21 commits into
vitessio:main
from
planetscale:throttler-cleanup-types-and-names
Jul 17, 2024
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5fb9a6e
rename variable mysqlMetricThresholds to metricThresholds
shlomi-noach c6d7047
rename function mysqlMetricThresholdsSnapshot to metricThresholdsSnap…
shlomi-noach 9eb59b3
rename *Interval variables away from 'mysql'
shlomi-noach 9f2716a
rename *Interval variables away from 'mysql'
shlomi-noach 685441e
rename aggregateMySQLProbes -> aggregateMetricResults. Cleanup tests
shlomi-noach dd11de1
rename MySQLThrottleMetrics -> ThrottleMetrics. Rename mysqlThrottleM…
shlomi-noach c9ac150
renamed files
shlomi-noach dd3868f
rename file
shlomi-noach 2886bf3
eliminatye throttle/mysql package; move everything under throttle/base
shlomi-noach f6e8a55
Remove unused type
shlomi-noach 1ea1b51
remove ctx argument
shlomi-noach 1bddcc0
rename aggregateMetricResults -> aggregateTabletMetricResults
shlomi-noach ec62bbe
shuffle code around, moving aggregateTabletMetricResults into 'base' …
shlomi-noach c82ea9a
remove ctx where unused
shlomi-noach 3423780
terminology: remove 'MySQL' where irrelevant. Add where relevant
shlomi-noach 1f584a1
terminology: remove 'MySQL' where irrelevant
shlomi-noach 85994ed
renamed getMySQLStoreMetric -> getScopedMetric
shlomi-noach 2492d6d
comment wording
shlomi-noach 8c20483
adding missing files
shlomi-noach d913132
Merge branch 'main' into throttler-cleanup-types-and-names
shlomi-noach a8eeea7
update copyright year
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -39,7 +39,7 @@ limitations under the License. | |
SOFTWARE. | ||
*/ | ||
|
||
package mysql | ||
package base | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
|
@@ -39,7 +39,7 @@ limitations under the License. | |
SOFTWARE. | ||
*/ | ||
|
||
package mysql | ||
package base | ||
|
||
import ( | ||
"testing" | ||
|
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
199 changes: 199 additions & 0 deletions
199
go/vt/vttablet/tabletserver/throttle/base/tablet_results_test.go
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,199 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be 2024? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package base | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
alias1 = "zone1-0001" | ||
alias2 = "zone1-0002" | ||
alias3 = "zone1-0003" | ||
alias4 = "zone1-0004" | ||
alias5 = "zone1-0005" | ||
) | ||
|
||
const ( | ||
nonexistentMetricName MetricName = "nonexistent" | ||
) | ||
|
||
func newMetricResultMap(val float64) MetricResultMap { | ||
return MetricResultMap{ | ||
DefaultMetricName: NewSimpleMetricResult(val), | ||
LagMetricName: NewSimpleMetricResult(val), | ||
LoadAvgMetricName: NewSimpleMetricResult(3.14), | ||
} | ||
} | ||
func noSuchMetricMap() MetricResultMap { | ||
result := make(MetricResultMap) | ||
for _, metricName := range KnownMetricNames { | ||
result[metricName] = NoSuchMetric | ||
} | ||
return result | ||
} | ||
|
||
func TestAggregateTabletMetricResultsNoErrors(t *testing.T) { | ||
tabletResultsMap := TabletResultMap{ | ||
alias1: newMetricResultMap(1.2), | ||
alias2: newMetricResultMap(1.7), | ||
alias3: newMetricResultMap(0.3), | ||
alias4: newMetricResultMap(0.6), | ||
alias5: newMetricResultMap(1.1), | ||
} | ||
|
||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 0, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.7) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 1, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.2) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 2, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.1) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 3, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 0.6) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 4, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 0.3) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 5, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 0.3) | ||
} | ||
} | ||
|
||
func TestAggregateTabletMetricResultsNoErrorsIgnoreHostsThreshold(t *testing.T) { | ||
tabletResultsMap := TabletResultMap{ | ||
alias1: newMetricResultMap(1.2), | ||
alias2: newMetricResultMap(1.7), | ||
alias3: newMetricResultMap(0.3), | ||
alias4: newMetricResultMap(0.6), | ||
alias5: newMetricResultMap(1.1), | ||
} | ||
|
||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 0, false, 1.0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.7) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 1, false, 1.0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.2) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 2, false, 1.0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.1) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 3, false, 1.0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 0.6) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 4, false, 1.0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 0.6) | ||
} | ||
{ | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 5, false, 1.0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 0.6) | ||
} | ||
} | ||
|
||
func TestAggregateTabletMetricResultsWithErrors(t *testing.T) { | ||
tabletResultsMap := TabletResultMap{ | ||
alias1: newMetricResultMap(1.2), | ||
alias2: newMetricResultMap(1.7), | ||
alias3: newMetricResultMap(0.3), | ||
alias4: noSuchMetricMap(), | ||
alias5: newMetricResultMap(1.1), | ||
} | ||
|
||
t.Run("nonexistent", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(nonexistentMetricName, tabletResultsMap, 0, false, 0) | ||
_, err := worstMetric.Get() | ||
assert.Error(t, err) | ||
assert.Equal(t, ErrNoSuchMetric, err) | ||
}) | ||
t.Run("no ignore", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 0, false, 0) | ||
_, err := worstMetric.Get() | ||
assert.Error(t, err) | ||
assert.Equal(t, ErrNoSuchMetric, err) | ||
}) | ||
t.Run("ignore 1", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 1, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1.7, value) | ||
}) | ||
t.Run("ignore 2", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 2, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1.2, value) | ||
}) | ||
|
||
tabletResultsMap[alias1][DefaultMetricName] = NoSuchMetric | ||
t.Run("no such metric", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 0, false, 0) | ||
_, err := worstMetric.Get() | ||
assert.Error(t, err) | ||
assert.Equal(t, ErrNoSuchMetric, err) | ||
}) | ||
t.Run("no such metric, ignore 1", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 1, false, 0) | ||
_, err := worstMetric.Get() | ||
assert.Error(t, err) | ||
assert.Equal(t, ErrNoSuchMetric, err) | ||
}) | ||
t.Run("metric found", func(t *testing.T) { | ||
worstMetric := AggregateTabletMetricResults(DefaultMetricName, tabletResultsMap, 2, false, 0) | ||
value, err := worstMetric.Get() | ||
assert.NoError(t, err) | ||
assert.Equal(t, value, 1.7) | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this attribution anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in this specific file. The code in this file is not derived from
freno
, and the note was needlessly copy+pasted from another file.