-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Reset Transformation to reset prometheus counters This transformation resets an aggregated prometheus counter by emitting a zero. This transformation fixes the display issue when an M3Aggregator failover occurs. When the Add transformation is used to generate a cumulative counter for prometheus, the values in the leader and follower are different since they started counting at different times. When the failover happens, the value might decrease. When a cumulative counter decreases, PromQL assumes the counter reset. This leads to strange display issues, since the counter did not actually reset. By explicitly reseting the counter each resolution period and not accumulating a counter, PromQL can correclty graph the rate across failovers. This does have the downside of an extra 0 datapoint per resolution period. The storage cost is more than just the extra 0 since the extra 0 is stored 1 second after the actual datapoint. This degrades the timestamp encoding since the timestamps are no longer at a fixed interval. In practice we see a 3x increase in storage for these aggregated counters.
1 parent
7ed094e
commit 89215d5
Showing
14 changed files
with
382 additions
and
39 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 10 additions & 6 deletions
16
src/metrics/generated/proto/transformationpb/transformation.pb.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -30,4 +30,5 @@ enum TransformationType { | |
PERSECOND = 2; | ||
INCREASE = 3; | ||
ADD = 4; | ||
RESET = 5; | ||
} |
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
Oops, something went wrong.
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,47 @@ | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package transformation | ||
|
||
import "time" | ||
|
||
// transformReset returns the provided datapoint and a zero datapoint one second later. | ||
// | ||
// This transform is useful for force resetting a counter value in Prometheus. When running the M3Aggregator in HA, both | ||
// the follower and leader are computing aggregate counters, but they started counting at different times. If these | ||
// counters are emitted as monotonic cumulative counters, during failover the counter decreases if the new leader | ||
// started counting later. Prometheus assumes any decrease in a counter is due a counter reset, which leads to strange | ||
// display results since the counter did not actually reset. | ||
// | ||
// This transform gets around this issue by explicitly not accumulating results, like Add, and force resets the counter | ||
// with a zero value so PromQL properly graphs the delta as the rate value. | ||
// | ||
// This does have the downside of an extra 0 datapoint per resolution period. The storage cost is more than just the | ||
// extra 0 value since the value is stored 1 second after the actual datapoint. This degrades the timestamp encoding | ||
// since the timestamps are no longer at a fixed interval. In practice we see a 3x increase in storage for these | ||
// aggregated counters. | ||
// | ||
// Currently only a single extra datapoint per aggregation is supported. If multiple transforms in an aggregation emit | ||
// an additional datapoint, only the last one is used. | ||
func transformReset() UnaryMultiOutputTransform { | ||
return UnaryMultiOutputTransformFn(func(dp Datapoint) (Datapoint, Datapoint) { | ||
return dp, Datapoint{Value: 0, TimeNanos: dp.TimeNanos + int64(time.Second)} | ||
}) | ||
} |
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,44 @@ | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package transformation | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReset(t *testing.T) { | ||
reset, err := Reset.UnaryMultiOutputTransform() | ||
require.NoError(t, err) | ||
now := time.Now() | ||
dp := Datapoint{Value: 1000, TimeNanos: now.UnixNano()} | ||
this, other := reset.Evaluate(dp) | ||
require.Equal(t, dp, this) | ||
require.Equal(t, Datapoint{Value: 0, TimeNanos: now.Add(time.Second).UnixNano()}, other) | ||
} | ||
|
||
func TestUnaryMultiParse(t *testing.T) { | ||
parsed, err := ParseType("Reset") | ||
require.NoError(t, err) | ||
require.Equal(t, Reset, parsed) | ||
} |